-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace RepoM.Api.IO.Methods; | ||
|
||
using System; | ||
using System.Linq; | ||
using ExpressionStringEvaluator.Methods; | ||
using JetBrains.Annotations; | ||
|
||
[UsedImplicitly] | ||
public class IsNullMethod : IMethod | ||
{ | ||
public bool CanHandle(string method) | ||
{ | ||
return "IsNull".Equals(method, StringComparison.CurrentCultureIgnoreCase); | ||
} | ||
|
||
public object? Handle(string method, params object?[] args) | ||
{ | ||
return args == null || args.Any(arg => arg is null); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
tests/RepoM.Api.Tests/IO/Methods/FindFilesMethodTests - Copy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
namespace RepoM.Api.Tests.IO.Methods; | ||
|
||
using RepoM.Api.IO.Methods; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
public class IsNullMethodTests | ||
{ | ||
private readonly IsNullMethod _sut = new(); | ||
|
||
[Theory] | ||
[InlineData("IsNull", true)] | ||
[InlineData("isnull", true)] | ||
[InlineData("IsNullx", false)] | ||
[InlineData("", false)] | ||
[InlineData(null, false)] | ||
public void CanHandle_ShouldReturnExpected(string? method, bool expectedResult) | ||
{ | ||
// arrange | ||
|
||
// act | ||
var result = _sut.CanHandle(method!); | ||
|
||
// assert | ||
_ = result.Should().Be(expectedResult); | ||
} | ||
|
||
[Fact] | ||
public void Handle_ShouldReturnTrue_WhenAnArgumentsIsNull1() | ||
{ | ||
// arrange | ||
|
||
// act | ||
var result = _sut.Handle("IsNull", null!); | ||
|
||
// assert | ||
_ = result.Should().BeOfType<bool>(); | ||
_ = result.Should().Be(true); | ||
} | ||
|
||
[Fact] | ||
public void Handle_ShouldReturnTrue_WhenAnArgumentsIsNull2() | ||
{ | ||
// arrange | ||
|
||
// act | ||
var result = _sut.Handle("IsNull", new object?[] { null!, }); | ||
|
||
// assert | ||
_ = result.Should().BeOfType<bool>(); | ||
_ = result.Should().Be(true); | ||
} | ||
|
||
[Fact] | ||
public void Handle_ShouldReturnTrue_WhenAnArgumentsIsNull3() | ||
{ | ||
// arrange | ||
|
||
// act | ||
var result = _sut.Handle("IsNull", null!, null!); | ||
|
||
// assert | ||
_ = result.Should().BeOfType<bool>(); | ||
_ = result.Should().Be(true); | ||
} | ||
|
||
[Theory] | ||
[InlineData("string")] | ||
[InlineData(12)] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void Handle_ShouldReturnTrue_WhenAnArgumentsIsNull4(object notNullValue) | ||
{ | ||
// arrange | ||
|
||
// act | ||
var result = _sut.Handle("IsNull", null!, notNullValue, null!); | ||
|
||
// assert | ||
_ = result.Should().BeOfType<bool>(); | ||
_ = result.Should().Be(true); | ||
} | ||
|
||
|
||
[Theory] | ||
[InlineData("string")] | ||
[InlineData(12)] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void Handle_ShouldReturnFalse_WhenAllArgumentsAreNotNull1(object notNullValue) | ||
{ | ||
// arrange | ||
|
||
// act | ||
var result = _sut.Handle("IsNull", notNullValue); | ||
|
||
// assert | ||
_ = result.Should().BeOfType<bool>(); | ||
_ = result.Should().Be(false); | ||
} | ||
|
||
[Theory] | ||
[InlineData("string")] | ||
[InlineData(12)] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void Handle_ShouldReturnFalse_WhenAllArgumentsAreNotNull2(object notNullValue) | ||
{ | ||
// arrange | ||
|
||
// act | ||
var result = _sut.Handle("IsNull", "first param", notNullValue); | ||
|
||
// assert | ||
_ = result.Should().BeOfType<bool>(); | ||
_ = result.Should().Be(false); | ||
} | ||
} |