Skip to content

Commit

Permalink
test: Add tests for missed methods/paths in Arg
Browse files Browse the repository at this point in the history
  • Loading branch information
DrBarnabus committed Apr 22, 2024
1 parent 41f39d3 commit 495b58c
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ public void WhenCalledWithArgAnyMatcher_AndWhenMatcherCalledWithNonAssignableTyp
argumentMatcher.Matches(value, typeof(int)).ShouldBeFalse();
}

[Theory]
[AutoData]
public void WhenCalledWithArgAnyMatcher_AndWhenCalledWithMatchingGenericMatcherType_ShouldReturnTrue(string value)
{
var expression = ((LambdaExpression)(() => Arg.Any<Generic.AnyType>())).Body;

var (argumentMatcher, _) = ArgumentMatcherInitializer.Initialize(expression);

argumentMatcher.Matches(value, typeof(string)).ShouldBeTrue();
}

[Theory]
[AutoData]
public void WhenCalledWithArgAnyMatcher_AndWhenCalledWithNonMatchingGenericMatcherType_ShouldReturnFalse(string value)
{
var expression = ((LambdaExpression)(() => Arg.Any<Generic.AnyValueType>())).Body;

var (argumentMatcher, _) = ArgumentMatcherInitializer.Initialize(expression);

argumentMatcher.Matches(value, typeof(int)).ShouldBeFalse();
}

#endregion

#region Arg.AnyNotNull<TValue>
Expand Down Expand Up @@ -120,6 +142,17 @@ public void WhenCalledWithArgAnyNotNullMatcher_AndWhenMatcherCalledWithNull_Shou
argumentMatcher.Matches(null, typeof(object)).ShouldBeFalse();
}

[Theory]
[AutoData]
public void WhenCalledWithArgAnyNotNullMatcher_AndWhenCalledWithMatchingGenericMatcherType_ShouldReturnTrue(string value)
{
var expression = ((LambdaExpression)(() => Arg.AnyNotNull<Generic.AnyReferenceType>())).Body;

var (argumentMatcher, _) = ArgumentMatcherInitializer.Initialize(expression);

argumentMatcher.Matches(value, typeof(string)).ShouldBeTrue();
}

#endregion

#region Arg.Is<TValue>
Expand Down Expand Up @@ -235,6 +268,19 @@ public void WhenCalledWithArgIsMatcherWithExpression_AndWhenMatcherCalledWithNon
argumentMatcher.Matches(value, typeof(string)).ShouldBeFalse();
}

[Theory]
[InlineData(null)]
[InlineData("mimic")]
[InlineData("bar")]
public void WhenCalledWithArgIsMatcherWithTypeExpression_AndWhenMatcherCalledWithMatchingValue_ShouldReturnTrue(string? value)
{
var expression = ((LambdaExpression)(() => Arg.Is<string>((v, t) => t == typeof(string) && (string)v == value))).Body;

var (argumentMatcher, _) = ArgumentMatcherInitializer.Initialize(expression);

argumentMatcher.Matches(value, typeof(string)).ShouldBeTrue();
}

#endregion

#region Arg.In<TValue>
Expand Down

0 comments on commit 495b58c

Please sign in to comment.