29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 6-5. Adding a reference to the MVC project<br />

Creating the Unit Tests<br />

I will add my unit tests to the UnitTest1.cs file in the EssentialTools.Tests project. The paid-for Visual<br />

Studio editions have some nice features for automatically generating test methods for a class that are not available in the Express<br />

edition, but I can still create useful and meaningful tests. To get started, I made the changes shown in Listing 6-27.<br />

Listing 6-27. Adding the Test Methods to the UnitTest1.cs File<br />

using System;<br />

using Microsoft.VisualStudio.TestTools.UnitTesting;<br />

using EssentialTools.Models;<br />

namespace EssentialTools.Tests {<br />

[TestClass]<br />

public class UnitTest1 {<br />

private IDiscountHelper getTestObject() {<br />

return new MinimumDiscountHelper();<br />

}<br />

[TestMethod]<br />

public void Discount_Above_100() {<br />

// arrange<br />

IDiscountHelper target = getTestObject();<br />

decimal total = 200;<br />

// act<br />

var discountedTotal = target.ApplyDiscount(total);<br />

147

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!