I'm seeing a possible issue with type coercion using LambdaCompare in a unit test. I have a condition where I'm comparing a long value to an int value. I have a unit test that seems like it should pass, but it doesn't. To test this, I changed the property that is currently an int to a long and reran the test successfully. For design reasons made prior to my involvement with the project, I'm not currently in a position to make that change, as it would impact other parts of the system.
Both the unit test code and the code in the system under test is in VS 2019 with .NET Framework 4.8.
I'm using Neleus.LambdaCompare version 1.0.3, installed via Nuget.
I put together some sample code that should demonstrate what I'm seeing.
public class UseLongId
{
public long ID { get; set;}
public Guid EntityID { get; set; }
}
public class UseIntId
{
public int ID { get; set;}
}
#region ------------- in the system under test
var usesIntId = new UseIntId {ID = 665544}; // arbitrarily set ID = 665544 for demo to be consistent with unit test code
List<Guid> usesLongIds = db
.Query<UseLongId>(x => x.ID == usesIntId.DealerID || x.DealerID == 0)
.Select(x => x.EntityID)
.Distinct()
.ToList();
#endregion
#region ------------- in the unit test
// using NSubstitute in a unit test - use of Arg.Is<>() comes from NSubstitute
int DealerId =665544;
someNSubstituteDatabaseMock
.Received()
.Query(Arg.Is<Expression<Func<UseLongId, bool>>>(x =>
Neleus.LambdaCompare.Lambda.Eq(x, y => y.DealerID == DealerId || y.DealerID == 0)));
#endregion
Here's the error output from the failed test:
NSubstitute.Exceptions.ReceivedCallsException : Expected to receive a call matching:
Query<UseLongId>(x => Eq(x, y => ((y.ID == 665544) OrElse (y.ID == 0))))
Actually received no matching calls.
Received 1 non-matching call (non-matching arguments indicated with '*' characters):
Query<UseLongId>(*x => ((x.ID == Convert(value(SomeArbitraryNamespace.DemoClass+<>c__DisplayClass8_0).usesIntId.ID)) OrElse (x.ID == 0))*)
Stack Trace:
ReceivedCallsExceptionThrower.Throw(ICallSpecification callSpecification, IEnumerable`1 matchingCalls, IEnumerable`1 nonMatchingCalls, Quantity requiredQuantity)
CheckReceivedCallsHandler.Handle(ICall call)
Route.Handle(ICall call)
CallRouter.Route(ICall call)
CastleForwardingInterceptor.Intercept(IInvocation invocation)
AbstractInvocation.Proceed()
ProxyIdInterceptor.Intercept(IInvocation invocation)
AbstractInvocation.Proceed()
ObjectProxy_1.Query[T](Expression`1 predicate)
GetExportParametersTests.It_should_demo_the_issue() line 229
I'm seeing a possible issue with type coercion using
LambdaComparein a unit test. I have a condition where I'm comparing alongvalue to anintvalue. I have a unit test that seems like it should pass, but it doesn't. To test this, I changed the property that is currently anintto alongand reran the test successfully. For design reasons made prior to my involvement with the project, I'm not currently in a position to make that change, as it would impact other parts of the system.Both the unit test code and the code in the system under test is in VS 2019 with .NET Framework 4.8.
I'm using Neleus.LambdaCompare version 1.0.3, installed via Nuget.
I put together some sample code that should demonstrate what I'm seeing.
Here's the error output from the failed test: