Trying to get Nunit working in ASP.Net.
The problem is, I’m testing a custom control – which 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 will get “cannot load App_GlobalResources”.
Trying to figure out if maybe I should attempt to simulate HttpContext Using You’ve been Haacked blog post but nobody has verified this is do-able.
This is a typical scenario that you should set up your class in a right way to be testable. If you have external dependency (references to a Global Resource), then you should make it an abstract, so you can mock it.
I suggest you take a look at this book, and it explains how to design your class be more testable. Alternative, you can download examples from moq. Set up unit testing is a lot about designing your class in more loose coupled way, so you can effectively test it without interaction with DB/File system/other resource.