Skip to content

Commit

Permalink
IsNullMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Sep 8, 2023
1 parent c0cb46c commit c7289f1
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/RepoM.Api/IO/Methods/IsNullMethod.cs
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 tests/RepoM.Api.Tests/IO/Methods/FindFilesMethodTests - Copy.cs
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);
}
}

0 comments on commit c7289f1

Please sign in to comment.