Hi
I am new to the world of mocking and I am evaluating your product. I am running into the a problem when creating a mock for a web service proxy. I get a TypeMock.VerifyException stating that the parameter of the method been mocked is incorrect. I get the code working if I use simple parameters, but as soon as I use classes as parameters things start going wrong. Can you please help. See below for a simplified version of the code:
public class AuthenticationServiceGateway
{
public AuthenticateResponse Authenticate(AuthenticateRequest request)
{
// Do actual web service call and return AuthenticateResponse
}
}
public class AuthenticateRequest
{
public string UserId;
public string Password;
public AuthenticateRequest(string userId, string password)
{
this.UserId = userId;
this.Password = password;
}
}
public class AuthenticateResponse
{
public bool Authenticated;
public short DaysBeforePasswordExpires;
public AuthenticateResponse(bool authenticated, short daysBeforePasswordExpires)
{
this.Authenticated = authenticated;
this.DaysBeforePasswordExpires = daysBeforePasswordExpires;
}
}
public class AuthenticationService
{
public bool Authenticate(string userId, string password)
{
AuthenticationServiceGateway gateway = new AuthenticationServiceGateway();
AuthenticationResponse response = gateway.Authenticate(new AuthenticateRequest(userId, password));
if (!response.Authenticated)
{
// Do error handling
}
return true;
}
}
[TestFixture]
public class AuthenticationServiceFixture
{
private const string ValidUserName = "g902263";
private const string ValidPassword = "test14";
[Test]
public void TestAuthenticate()
{
MockManager.Init();
Mock serviceGatewayMock = MockManager.Mock(typeof(AuthenticationServiceGateway));
serviceGatewayMock.ExpectConstructor();
MyAuthenticateRequest request = new MyAuthenticateRequest(ValidUserName, ValidPassword);
MyAuthenticateResponse response = new MyAuthenticateResponse(true, 10);
serviceGatewayMock.ExpectAndReturn("Authenticate", response).Args(request);
AuthenticationService service = new AuthenticationService();
Assert.IsTrue(service.Authenticate(ValidUserName, ValidPassword));
MockManager.Verify();
}
}