I am using Moq to write unit tests for a project, and when I try to verify So one of the tests is failing that a DateTime property is assigned a value. Context.TaskQueue.AddObject (It.Is & lt; TaskQueueItem & gt; (task_queue = & gt; task_queue.TaskCode == (integer
_mockTaskContext.Verify (reference = & gt; here's my Verify (which fails) is TaskCode.MyTask & amp; Work_queue.ClientID == ExpectedClientID & amp; task_queue.JobNumber == It.IsAny & LT; Integer & gt; () & amp; ; & Amp; task_queue.Requester == String.Empty & amp; task_queue.JobStatus == (int) JobStatus.Submitted & amp; task_queue.TimeQueued == It.Is Any Any & DateTime & gt; ;;) & Amp; amp; amp; & amp; task_queue.TimeStarted == New Date Time (1900, 1, 1) & amp; amp; task_queue.TimeStopped == New DateTime (1900, 1, 1) & amp; amp; ; Task line Task parameter == Expected Tasks Ramam), Times.Once ()); If I comment on hope at task_queue.TimeQueued , then without any other change I have the test Apart from this, I change the requirement on either TimeStarted or TimeStopped New Date Time (1900, 1, 1) to Make it.IsAny & lt; DateTime & gt; () , the test fails I have run outside of the unit test with actual implementation instead of a mall repository under test outside the code test, and the timequated Any ideas why it is being assigned to It.Is Any Anyone does not seem to work correctly date time properties, or I wrongly expect my expectations I'm setting up
UPDATE: I use 'I.IsAny () in other tests without any problem, but this test is still unsuccessful. I think it might be because it is inside because it's inside it. Lambda is an expression, but I do not know how I will work around it.
I'm sure it.IsAny & lt; & Gt; () syntax should be used within the scope of the counterfeit item. In this case when you use setup and simulated logic directly, the reason is that the duplicate object is in recording mode, then < / P> The values you pass in logic are captured
mock.Setup (x => x.Foo (It.IsAny & lt; times> ()); The setup process will process the arguments when the execution line is executed.
However in your example you can it.IsAny & lt; & Gt; We are trying to use the representative to verify the logic that matches the () . When this happens then fake recordings are not being done, but in the process of being used as a result of the object under test (which is very later).
Then someValue == it.IsAny & lt; DateTime & gt; () can not be evaluated as correct because the return value of the IsAny method has to be returned to a matching value. It may be true that I hope that is it. Lieutenant; AT & GT () also does not work.
I recommend that you have to match the exact values or dates in this case
& amp; Amp; IsInRange (DateTime.MinValue, DateTime.MaxValue, task_queue.TimeQueued) Where IsInRange You just have another method to check a value of 2 minutes and The maximum is between the boundary.
Comments
Post a Comment