public async Task All_ShouldReturnCorrectDataWithValidInputAndParticularSearchTerm()
        {
            const string SearchTerm = "Test";

            //Arrange
            var controller = new AdminUsersController(this.userService.Object, this.fixture.UserManagerMockInstance.Object);

            this.userService.Setup(u => u.AllAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(this.GetUsers());

            this.userService.Setup(u => u.TotalUsers(It.IsAny <string>()))
            .Returns(TotalUsers);

            //Act
            var result = await controller.All(SearchTerm, MinPageSize);

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model.As <AllUsers>();

            model.Users.Should().HaveCount(TotalUsers);
            model.Pagination.SearchTerm.Should().Be(SearchTerm);
            model.Pagination.CurrentPage.Should().Be(MinPageSize);
            model.Pagination.NextPage.Should().Be(MaxPageSize);
            model.Pagination.PreviousPage.Should().Be(MinPageSize);
            model.Pagination.TotalElements.Should().Be(TotalUsers);
        }
        public async Task ChangeRoles_AddUserToRoleWhenNotInThisRoleShouldReirectToAllUsers()
        {
            //Arrange
            var controller = new AdminUsersController(null, this.fixture.UserManagerMockInstance.Object);

            this.fixture.UserManagerMockInstance.Setup(u => u.FindByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(this.GetUser());

            this.fixture.UserManagerMockInstance.Setup(u => u.IsInRoleAsync(It.IsAny <User>(), It.IsAny <string>()))
            .ReturnsAsync(false);

            this.fixture.UserManagerMockInstance.Setup(u => u.AddToRoleAsync(It.IsAny <User>(), It.IsAny <string>()))
            .ReturnsAsync(new IdentityResult());

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = await controller.ChangeRolesAsync(UserId, Role.Administrator, false);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.AdminAllUsers);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.UserAddedToRole, UserUsername, Role.Administrator.ToString()));
        }
        public async Task All_PageGreaterThanTotalPagesShouldRedirectToAllUsers()
        {
            const int InvalidPageSize = 10;

            //Arrange
            var controller = new AdminUsersController(this.userService.Object, this.fixture.UserManagerMockInstance.Object);

            this.userService.Setup(u => u.AllAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(this.GetUsers());

            this.userService.Setup(u => u.TotalUsers(It.IsAny <string>()))
            .Returns(TotalUsers);

            //Act
            var result = await controller.All(string.Empty, InvalidPageSize);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.AdminAllUsers);
            model.RouteValues.Keys.Should().Contain(RouteValueKeyPage);
            model.RouteValues.Values.Should().Contain(MaxPageSize);
            model.RouteValues.Keys.Should().Contain(RouteValueKeySearchTerm);
            model.RouteValues.Values.Should().Contain(string.Empty);
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            ServiceLocatorInitializer.Init();

            controller = new AdminUsersController(
                CreateMockUserRepository(),
                MockRepository.GenerateMock<IMembershipService>(),
                MockRepository.GenerateMock<IRepository<Team>>(),
                MockRepository.GenerateMock<IRepository<Game>>());
        }
        public void ControllerShouldBeForAuthenticatedUsersOnly()
        {
            //Arrange
            var controller = new AdminUsersController(null, null);

            //Act
            var attributes = controller.GetType().GetCustomAttributes(true);

            //Assert
            attributes.Any(a => a.GetType() == typeof(AuthorizeAttribute));
        }
Exemplo n.º 6
0
        public AdminUsersControllerUnitTests()
        {
            _mockRepo = new Mock <IUnitOfWork <MadpayDbContext> >();

            _mockMapper = new Mock <IMapper>();
            //_mockUtilities = new Mock<IUtilities>();
            _mockLogger      = new Mock <ILogger <AdminUsersController> >();
            _mockUserManager = new Mock <FakeUserManager>();
            _dbMad           = new Mock <MadpayDbContext>();
            _controller      = new AdminUsersController(_mockRepo.Object, _dbMad.Object, _mockMapper.Object, _mockLogger.Object, _mockUserManager.Object);
        }
        public void ControllerShouldBeInAdminsArea()
        {
            //Arrange
            var controller = new AdminUsersController(null, null);

            //Act
            var attributes    = controller.GetType().GetCustomAttributes(true);
            var areaAttribute = attributes.FirstOrDefault(a => a.GetType() == typeof(AreaAttribute));

            //Assert
            areaAttribute.As <AreaAttribute>().RouteValue.Should().Be(WebConstants.Area.Admin);
        }
        public void ControllerShouldBeForAdminsOnly()
        {
            //Arrange
            var controller = new AdminUsersController(null, null);

            //Act
            var attributes         = controller.GetType().GetCustomAttributes(true);
            var authorizeAttribute = attributes.FirstOrDefault(a => a.GetType() == typeof(AuthorizeAttribute));

            //Assert
            authorizeAttribute.As <AuthorizeAttribute>().Roles.Should().Be(Role.Administrator.ToString());
        }
        public async Task All_WithPageLessOrEqualToZeroShouldRedirectToAllUsers(int page)
        {
            //Arrange
            var controller = new AdminUsersController(null, null);

            //Act
            var result = await controller.All(string.Empty, page);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.AdminAllUsers);
            model.RouteValues.Keys.Should().Contain(RouteValueKeyPage);
            model.RouteValues.Values.Should().Contain(MinPageSize);
            model.RouteValues.Keys.Should().Contain(RouteValueKeySearchTerm);
            model.RouteValues.Values.Should().Contain(string.Empty);
        }
Exemplo n.º 10
0
        public ShellController(IAuthenticationService authService,
                               HomeController homeController,
                               AdminUsersController adminUsersController,
                               AppBusinessUnitController businessUnitController,
                               AppCostsPerMonthController costsPerMonthController,
                               AppCostsPerBusinessUnitController costsPerUnitController,
                               AppEmployeeController employeeController,
                               AppVehicleController vehicleController)
        {
            _authService = authService;

            _controllers.Add("home", homeController);
            _controllers.Add("costsPerMonth", costsPerMonthController);
            _controllers.Add("costsPerUnit", costsPerUnitController);
            _controllers.Add("businessUnits", businessUnitController);
            _controllers.Add("vehicles", vehicleController);
            _controllers.Add("employees", employeeController);
            _controllers.Add("admin/users", adminUsersController);
        }
        public async Task All_ValidPageAndNoTownsShouldReturnCountZero()
        {
            //Arrange
            var controller = new AdminUsersController(this.userService.Object, this.fixture.UserManagerMockInstance.Object);

            this.userService.Setup(u => u.AllAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(new List <AdminUserListingServiceModel>());

            //Act
            var result = await controller.All(string.Empty, MinPageSize);

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model.As <AllUsers>();

            model.Users.Should().HaveCount(0);
            model.Pagination.SearchTerm.Should().Be(string.Empty);
            model.Pagination.CurrentPage.Should().Be(MinPageSize);
            model.Pagination.NextPage.Should().Be(0);
            model.Pagination.PreviousPage.Should().Be(MinPageSize);
            model.Pagination.TotalElements.Should().Be(0);
        }
        public async Task ChangeRoles_WithNonExistingUserShouldRedirectToAllUsers()
        {
            //Arrange
            User user       = null;
            var  controller = new AdminUsersController(null, this.fixture.UserManagerMockInstance.Object);

            this.fixture.UserManagerMockInstance.Setup(u => u.FindByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(user);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = await controller.ChangeRolesAsync(UserId, Role.Administrator, false);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.AdminAllUsers);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.NonExistingEntity, nameof(WebConstants.Entity.User), UserId));
        }