I want to write unit tests for a web service. I create my test project, reference my web project (not service reference, assembly reference), then write some code to test the we
If you are using mocking, you can wrap this logic in another class:
interface IAuthenticator
{
bool IsAuthenticated();
}
and implement the real one:
class Authenticator : IAuthenticator
{
bool IsAuthenticated()
{
return HttpContext.Current.User.Identity.IsAuthenticated;
}
}
but in the test, create a mock and return true or false:
Mock mock = new Mock();
mock.Expect(x => x.IsAuthenticated()).Returns(true);