![]() ![]() (Incidentally, I realize that I could call “SetupAllProperties()”, but I’m not doing that for illustrative purposes).īut, sometimes I’d rather not think of the test double as a double, but just some object that I’m passing in. I create the double and then I manipulate its setup, before passing its object in to my class under test. So, I create a test double for the pencil, and I do some setup on it, and then I pass it into my sharpener, after which I verify that the sharpener mutates it in an expected way. MySharpener.Sharpen(myPencilDouble.Object) Īssert.IsTrue() MyPencilDouble.SetupProperty(pencil => pencil.Length) ![]() MyPencilDouble.SetupProperty(pencil => pencil.IsSharp) Let’s say we have some class PencilSharpener that takes an IPencil and sharpens it, and we want to verify that this is accomplished by setting the Pencil’s length and sharpness properties: public void Sharpen_Sets_IsSharp_To_True() But, in order to explain these two features and the different paradigm they represent, let me reference my normal use of Moq. ![]() Since learning about these features, I’ve been getting a lot of mileage out of them. Today, I’d like to highlight a couple of features of Moq that I didn’t know about until relatively recently (thanks to a recent google+ hangout with Moq author, Daniel Cazzulino). NET Tags: C#, Moq, MS Test, Uncategorized, Unit Testing
0 Comments
Leave a Reply. |