Example #1
0
        public async Task OnGetAsync_GivenPageModelIsNotNull_ExpectPageModelNotToBeOverridenAndPageResultReturn()
        {
            var mediator    = new Mock <IMediator>();
            var userQueries = new Mock <IUserQueries>();

            userQueries.Setup(x => x.GetDetailsOfUserById(It.IsAny <Guid>()))
            .ReturnsAsync(Maybe.From(new DetailedUserModel(TestVariables.UserId, "email-address", "first-name",
                                                           "last-name", true, TestVariables.Now, null, null, true, new List <Guid>(), null)));
            var roleQueries = new Mock <IRoleQueries>();

            roleQueries.Setup(s => s.GetSimpleRoles())
            .ReturnsAsync(() => Maybe.From(new List <SimpleRoleModel>()));
            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 page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object)
            {
                PageModel = new EditUser.Model()
            };
            var result = await page.OnGetAsync();

            Assert.IsType <PageResult>(result);
            Assert.Null(page.PageModel.EmailAddress);
        }
Example #2
0
        public async Task OnGetAsync_GivenWhenLastAuthenticatedIsNull_ExpectAuthenticationStatusToHaveCorrectMessage()
        {
            var mediator    = new Mock <IMediator>();
            var userQueries = new Mock <IUserQueries>();

            userQueries.Setup(x => x.GetDetailsOfUserById(It.IsAny <Guid>()))
            .ReturnsAsync(Maybe.From(new DetailedUserModel(TestVariables.UserId, "email-address", "first-name",
                                                           "last-name", true, TestVariables.Now, null, null, true, new List <Guid>(), null)));
            var roleQueries = new Mock <IRoleQueries>();

            roleQueries.Setup(s => s.GetSimpleRoles())
            .ReturnsAsync(() => Maybe.From(new List <SimpleRoleModel>()));
            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 page   = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object);
            var result = await page.OnGetAsync();

            Assert.IsType <PageResult>(result);
            Assert.Equal("Never Authenticated", page.AuthenticationStatus);
        }
Example #3
0
        public async Task OnGetAsync_GivenNoUserIsAuthenticated_ExpectNotFoundResult()
        {
            var mediator    = new Mock <IMediator>();
            var userQueries = new Mock <IUserQueries>();
            var roleQueries = new Mock <IRoleQueries>();
            var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>();

            currentAuthenticatedUserProvider.Setup(x => x.CurrentAuthenticatedUser)
            .Returns(Maybe <ISystemUser> .Nothing);

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

            Assert.IsType <NotFoundResult>(result);
        }
Example #4
0
        public async Task OnGetAsync_GivenAttemptToEditSelf_ExpectNotFoundResult()
        {
            var mediator    = new Mock <IMediator>();
            var userQueries = new Mock <IUserQueries>();
            var roleQueries = new Mock <IRoleQueries>();
            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 page = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object)
            {
                Id = TestVariables.AuthenticatedUserId,
            };
            var result = await page.OnGetAsync();

            Assert.IsType <NotFoundResult>(result);
        }
Example #5
0
        public async Task OnGetAsync_GivenUserIsNotInSystem_ExpectNotFoundResultReturn()
        {
            var mediator    = new Mock <IMediator>();
            var userQueries = new Mock <IUserQueries>();

            userQueries.Setup(x => x.GetDetailsOfUserById(It.IsAny <Guid>()))
            .ReturnsAsync(Maybe <DetailedUserModel> .Nothing);
            var roleQueries = new Mock <IRoleQueries>();
            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 page   = new EditUser(userQueries.Object, mediator.Object, roleQueries.Object, currentAuthenticatedUserProvider.Object);
            var result = await page.OnGetAsync();

            Assert.IsType <NotFoundResult>(result);
        }