Esempio n. 1
0
        public async Task EnableAccount_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.EnableAccount(new EnableAccountRequest()));
            var responseModel = Assert.IsType <EnableAccountResponse>(result.Value);

            Assert.False(responseModel.IsSuccess);
        }
Esempio n. 2
0
        public async Task EnableAccount_GivenNoAuthenticatedUser_ExpectResponseWithFailedStatus()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <EnableAccountCommand>(), 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.EnableAccount(new EnableAccountRequest
            {
                UserId = TestVariables.UserId,
            }));
            var responseModel = Assert.IsType <EnableAccountResponse>(result.Value);

            Assert.False(responseModel.IsSuccess);
        }
Esempio n. 3
0
        public async Task EnableAccount_GivenSuccessfulExecution_ExpectSuccessfulResponse()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <EnableAccountCommand>(), 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.EnableAccount(new EnableAccountRequest
            {
                UserId = TestVariables.UserId,
            }));
            var responseModel = Assert.IsType <EnableAccountResponse>(result.Value);

            Assert.True(responseModel.IsSuccess);
        }