Testing invalid model
This commit is contained in:
@@ -145,8 +145,6 @@ public class AuthController_Tests
|
||||
AuthenticatedUser authenticatedUser = null;
|
||||
authServiceMock.Setup(s => s.AuthenticateAsync(It.IsAny<AuthenticateRequestData>())).ReturnsAsync(authenticatedUser);
|
||||
NotFoundResult response = (NotFoundResult)(await controller.AuthenticateAsync(request));
|
||||
Console.WriteLine(JsonConvert.SerializeObject(response));
|
||||
Console.WriteLine(response.GetType());
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(NotFoundResult));
|
||||
|
||||
@@ -160,4 +158,45 @@ public class AuthController_Tests
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AuthenticateAsync_ModelInvalid()
|
||||
{
|
||||
IConfiguration configuration = TestUtils.CreateConfiguration();
|
||||
var authServiceMock = new Mock<IAuthService>();
|
||||
var controller = new AuthController(configuration, authServiceMock.Object);
|
||||
|
||||
var request = new AuthenticateRequest
|
||||
{
|
||||
Data = null
|
||||
};
|
||||
AuthenticatedUser authenticatedUser = null;
|
||||
authServiceMock.Setup(s => s.AuthenticateAsync(It.IsAny<AuthenticateRequestData>())).ReturnsAsync(authenticatedUser);
|
||||
controller.ModelState.AddModelError("Data", "Invalid data");
|
||||
ObjectResult response = (ObjectResult)(await controller.AuthenticateAsync(request));
|
||||
Console.WriteLine(JsonConvert.SerializeObject(response));
|
||||
Console.WriteLine(response.GetType());
|
||||
|
||||
Assert.IsInstanceOfType(response, typeof(ObjectResult));
|
||||
|
||||
if(response != null && response.Value != null)
|
||||
{
|
||||
Assert.IsTrue(response.StatusCode == 400);
|
||||
|
||||
var result = (BaseResponse)response.Value;
|
||||
if(result != null)
|
||||
{
|
||||
Assert.IsTrue(result.Status == 400);
|
||||
Assert.IsTrue(result.Message == "Request is not well formed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Result value is null");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail($"Response is null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user