Unit / Integration Testing Code Using HttpCurrentContext
Trying to get Nunit to work in ASP.Net.
The problem is that I am testing a custom control that references a global resource.
When I try to unit test it
/// </summary>
[Test]
public void TestSetAndGetNumber()
{
PhoneNumber phone = new PhoneNumber(PhoneNumber.NumberType.Business, "", true, "");
string expectedString = "1-800-Goat-Phone";
string resultString = "1-800-Goat-Phone";
resultString = phone.Value = resultString;
Assert.AreEqual(expectedString, resultString, "GetNumberMatch method returned unexpected result.");
Assert.Fail("Create or modify test(s).");
}
I get "Can't load App_GlobalResources".
Trying to find out if I can try to simulate the HttpContext you use the Haacked blog post , but no one has confirmed that this is done by -able.
a source to share
This is a typical scenario where you must set up your class correctly so that it can be tested. If you have an external dependency (global resource references) then you should make it abstract so you can mock it.
I suggest you take a look at this book , and it explains how to create your own class for testing. Alternatively, you can download examples from moq . Setting up unit testing is a lot about designing your class in a more fluent way, so that you can test it effectively without interacting with the DB / File System / other resource.
a source to share