public async Task DisableAccount_GivenRequestIsNotValid_ExpectResponseWithFailedStatus() { var mediator = new Mock <IMediator>(); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); currentAuthenticatedUserProvider.Setup(x => x.CurrentAuthenticatedUser) .Returns(Maybe.From(new Mock <ISystemUser>().Object)); var controller = new UserApiController(mediator.Object, currentAuthenticatedUserProvider.Object); controller.ModelState.AddModelError("key", "error-message"); var result = Assert.IsType <JsonResult>(await controller.DisableAccount(new DisableAccountRequest())); var responseModel = Assert.IsType <DisableAccountResponse>(result.Value); Assert.False(responseModel.IsSuccess); }
public async Task DisableAccount_GivenNoAuthenticatedUser_ExpectResponseWithFailedStatus() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <DisableAccountCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(ResultWithError.Fail(new ErrorData(ErrorCodes.AuthenticationFailed))); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); currentAuthenticatedUserProvider.Setup(x => x.CurrentAuthenticatedUser) .Returns(Maybe <ISystemUser> .Nothing); var controller = new UserApiController(mediator.Object, currentAuthenticatedUserProvider.Object); var result = Assert.IsType <JsonResult>(await controller.DisableAccount(new DisableAccountRequest { UserId = TestVariables.UserId, })); var responseModel = Assert.IsType <DisableAccountResponse>(result.Value); Assert.False(responseModel.IsSuccess); }
public async Task DisableAccount_GivenSuccessfulExecution_ExpectSuccessfulResponse() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <DisableAccountCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(ResultWithError.Ok <ErrorData>()); var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>(); var authenticatedUser = new Mock <ISystemUser>(); authenticatedUser.Setup(x => x.UserId).Returns(TestVariables.AuthenticatedUserId); currentAuthenticatedUserProvider.Setup(x => x.CurrentAuthenticatedUser) .Returns(Maybe.From(authenticatedUser.Object)); var controller = new UserApiController(mediator.Object, currentAuthenticatedUserProvider.Object); var result = Assert.IsType <JsonResult>(await controller.DisableAccount(new DisableAccountRequest { UserId = TestVariables.UserId, })); var responseModel = Assert.IsType <DisableAccountResponse>(result.Value); Assert.True(responseModel.IsSuccess); }