unit testing - Moq Invocation was not performed on the mock -


Trying to understand the use of

VerifySet etc ... but as long as I do an alternate solution, I Can not get to work.

  Public Interface IProduct {int id {get; Set; } String name {get; Set; }} Public Zero Can_do_something () {var newProduct = new fake & lt; IProduct & gt; (); NewProduct.SetupGet (P => PIID). Returns (1); NewProduct.SetupGet (P => P. name). Returns ("Joe"); // it fails !! That's why I did not bring it a new product. VerifySet (p = & gt; p.Name, Times.AtLeastOnce ()); // If I do this then this new product works. Object .name = "joe"; NewProduct.VerifySet (P => P. names, times.) Once the attit (); }  

Can anyone explain how to use VerifySet and VerifyGet on the property? I am confused.

Before you verify, you need to perform an action specific unit test paradigm with counterfeit goods:

Pre> public zero can_do_something () {// adjust newproduct = new mock & lt; IProduct & gt; (); NewProduct.SetupGet (P => P. Name). Returns ("Joe"); // Act - does not exist! // p.Name (i.e. method call) your action should be here // alert // it fails because p.Name has not taken any new action against it. VerifySet (p = & gt; p.Name, Times at least once ()); }

And this is true because the Act exists:

  Public Zero Can_do_something () {// Adjust newproduct = new mock & lt; IProduct & gt; (); NewProduct.SetupGet (P => P. Name). Returns ("Joe"); // Act Load Product (newProduct.Object); // Present a new presentation. VerifySet (P => P. names, times.) Once the attit (); } Public static zero load product (IP Product Product) {product.Name = "Joe"; } Fake testing follows a different pattern than the non-duplicate test which is known as  Behavior Verification  - I have created that which Make the concept a bit more clear. / P> 

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -