Пример #1
0
        public async Task OnPostAsync_GivenInvalidModelState_ExpectRedirectToPageResult()
        {
            var mediator    = new Mock <IMediator>();
            var userQueries = new Mock <IUserQueries>();
            var roleQueries = new Mock <IRoleQueries>();
            var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>();

            var page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object);

            page.ModelState.AddModelError("Error", "Error");

            var result = await page.OnPostAsync();

            Assert.IsType <RedirectToPageResult>(result);
        }
Пример #2
0
        OnPostAsync_GivenValidModelStateAndCommandDoesNotExecute_ExpectRedirectToPageResultAndPrgStateSetToFailed()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <UpdateUserCoreDetailsCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(ResultWithError.Fail(new ErrorData(ErrorCodes.SavingChanges)));
            var userQueries = new Mock <IUserQueries>();
            var roleQueries = new Mock <IRoleQueries>();
            var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>();

            var page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object)
            {
                PageModel = new EditUser.Model()
            };

            var result = await page.OnPostAsync();

            Assert.IsType <RedirectToPageResult>(result);
            Assert.Equal(PrgState.Failed, page.PrgState);
        }
Пример #3
0
        OnPostAsync_GivenValidModelStateAndCommandDoesExecute_ExpectRedirectToPageResultToViewUserPage()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.Send(It.IsAny <UpdateUserCoreDetailsCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(ResultWithError.Ok <ErrorData>());
            var userQueries = new Mock <IUserQueries>();
            var roleQueries = new Mock <IRoleQueries>();
            var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>();

            var page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object)
            {
                PageModel = new EditUser.Model()
            };

            var result = await page.OnPostAsync();

            var pageResult = Assert.IsType <RedirectToPageResult>(result);

            Assert.Equal(PageLocations.UserView, pageResult.PageName);
        }