Closed rickersilva closed 5 years ago
You already got an answer on Stack Overflow, which explains this. Calling new AccionARealizarEntity(s1)
twice will give you two distinct objects (even though they might be equal in all their properties), so in the Watch window you're making a call that has no corresponding setup.
Either implement value equality semantics on your AccionARealizarEntity
type by overriding Equals
, GetHashCode
etc. or turn it from a class
to a struct
, if that is appropriate for your object model.
Or cache the value of one call to new AccionARealizarEntity(s1)
somewhere, then use that cached instance in both your setup and the Watch expression.
P.S.: Please don't cross-post.
sorry for the cross posting. I did think twice about it, but decided to post anyway. Thank you for your explanation. problem is solved.
Hope redundancy may help others as well.
Good to hear you got your tests working!
I'm new to unit testing with nUnit and Moq and have run into an issue seting behaviours for a method in a dbprovider. I'm tryin to test a validation method that invokes an Exists method in ICoDbProvider. When false, the method throws an excpetion, and it is working nice. When true, the method should go ahead until the return true; statement at the end of the method. This is the method tested:
The test was originally generated by Intellitest, and it generated a scaffolding for private method testing. The test method looks like this.
This is the case everything in the Model is right and the method should return a valid flag. I have this weird behaviour while debugging. Right after seting Mocks behaviour I called in Watch window the method, and it return false, as shown in the picture
I also have a method that tests the accionARealizar object does not exists, and it returns false as set. But I doubt it is working correctly.
This was originally posted in stackoverflow https://stackoverflow.com/questions/54875460/nunit-moq-behaviour-always-returns-false