07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

20<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

<strong>Test</strong> case Result Automated test<br />

Verify that the<br />

class that implements<br />

the IItem<br />

interface notifies<br />

the instrumentation<br />

when it<br />

calculates a total<br />

price.<br />

Passed The following test case verifies that the Item Categories<br />

Calcuated/sec performance counter is incremented when<br />

the CalculateTotal method calculates the total price for the<br />

SoftwareItem object. The GetCounterValue method returns<br />

the current counter value of the countername parameter.<br />

[<strong>Test</strong>Method]<br />

public void VerifyItemCalculatedPerfCounter()<br />

{<br />

string counterName = "Item Categories Calculated/<br />

sec";<br />

int initialCount = GetCounterValue(counterName, "Total");<br />

ItemProviderFactory factory = new ItemProviderFactory();<br />

SoftwareItem item = (SoftwareItem)factory.<br />

Create("IE7");<br />

item.CalculateTotal();<br />

int loggedCount = GetCounterValue(counterName, "Total");<br />

Assert.IsTrue((loggedCount - initialCount) == 1);<br />

}<br />

In the following example, the quantity is set to zero for the CommonItem<br />

named MicrosoftXP. The CommonItem class throws<br />

an exception if the quantity is less than or equal to zero. This<br />

test case verifies that when an exception is thrown, an error is<br />

logged to the event log through the instrumentation provider.<br />

[<strong>Test</strong>Method]<br />

public void VerifyErrorLoggedToEventLog()<br />

{<br />

using (EventLog log = new EventLog("Application"))<br />

{<br />

int initialCount = log.Entries.Count;<br />

ItemProviderFactory factory = new ItemProviderFactory();<br />

IItem item = factory.Create("MicrosoftXP");<br />

item.CalculateTotal();<br />

int finalCount = log.Entries.Count;<br />

Assert.IsTrue(finalCount - initialCount == 1);<br />

Assert.IsTrue(log.Entries[finalCount - 1].Message.<br />

Contains("The quantity value should be greater than<br />

zero"));<br />

Assert.IsTrue(log.Entries[finalCount - 1].Source.<br />

Equals("<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong>"));<br />

}<br />

}

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

Saved successfully!

Ooh no, something went wrong!