c# - TDD: Stub, Mock, or None of the Above -


I am trying to learn TDD by implementing it for a simple project. Some details (and a previous question) are here:

I have a purchase order collection class, which is a private listing of the purchase list (given in the constructor) , And Purchase Orders is a Boolean Property IsValid Purchase is a property of the Collection of Hasrrors which gives a true if any purchase in the list is wrong as the ISIlid. This is the argument that I want to test.

  [TestMethod] Public Zero Purchase_Order_Collection_Has_Errors_Is_True_If_Any_Purchase_Order_Has_Is_Valid_False () {List & lt; Purchase order & gt; Order = new list & lt; Purchase order & gt; (); order. Add (New Purchase Order (- Some values ​​that are meant to produce ESIIDI false) -); order. Add (New Purchase Order (- There are some values ​​which ISIID is true -)); PurchaseOn Store Collection = New Purchase Order Collection (Order); Assert.IsTrue (collection.HasErrors); }  

This is similar to my previous question that is coupled in this exam too, I argue what makes the purchase item wrong or wrong examination, when the exam is actually passed The examination should not be taken into account. The question is different (classes) in the IMO itself are not problem.

Essentially, I want to be able to declare a purchase order, that is, ESIILID is false or correct, without knowing anything else that what the purchase order is.

From my limited TDD knowledge, is it something that you use stabe or Mox is my main question right? Or should I use a different method for this? Or am I totally flawed and am I writing this test and thinking about it wrong?

My initial idea was to use any kind of fake structure and order a purchase that always gives the right or wrong. Although what I have read, I have to declare the ISIDAD virtual. So my second thought was to change it to add to the order for purchase order and to make it a fake purchase order, it was changed to change which always gives the wrong or the truth. Are these two legitimate ideas?

Thank you!

Whether you are on the right track with a stub or duplicate I use a malling framework I like to do

How this will work using a joke, it is that you want to duplicate your purchase order class, so it is time to start implementing the implementation.

Using the example, if you are using C # 3.0 and .NET Framework 3.5:

  [TestMethod] Public Zero Purchase_Order_Collection_Has_Errors_Is_True_If_Any_Purchase_Order_Has_Is_Valid_False () {var mockFirstPurchaseOrder = New fake & lt; IPurchaseOrder & gt; (); Var MockScondancePurchase Order = New Fake & lt; IPurchaseOrder & gt; (); Mockfront purchase order Expect (P = & gt; P.IISIIIDID) Returns (false). Once (); MockScondorPortgage Order Expect (P = & gt; P.IISIIIDID) Returns (true). Tastostone (); & Lt; IPurchaseOrder & gt; Purchase Order = New List & lt; IPurchaseOrder & gt; (); PurchaseOrders.Add (mockFirstPurchaseOrder.Object); PurchaseOrders.Add (mockSecondPurchaseOrder.Object); PurchaseOn Store Collection = New Purchase Order Collection (Order); Assert.IsTrue (collection.HasErrors); }  

Edit:
I used an interface to duplicate the purchase order, but you also do not have it. You can mark IsValid as a virtual and can duplicate the purchase order class. The way my thumb rule is to go is to use virtual first to create just one interface, so I can duplicate an object without any architecture reason I have a code odor.


Comments