Beispiel #1
0
        protected IAdminUsersService GetService(ApplicationDbContext dbContext)
        {
            var userManager = CommonGetMockMethods.GetUserManager().Object;
            var service     = this.GetService(dbContext, userManager);

            return(service);
        }
Beispiel #2
0
        private ITestDriveService GetService(ApplicationDbContext dbContext, string userId)
        {
            var mockedUserManager = CommonGetMockMethods.GetUserManager();

            CommonSetupMockMethods.SetupMockedUserManagerGetUserId(mockedUserManager, userId);
            var service = this.GetService(dbContext, mockedUserManager.Object);

            return(service);
        }
        public async void WithNotBannedUser_ShouldThrowException()
        {
            var dbContext         = this.GetDbContext();
            var mockedUserManager = CommonGetMockMethods.GetUserManager();

            CommonSetupMockMethods.SetupMockedUserManagerIsInRoleAsync(mockedUserManager, true);
            var service = this.GetService(dbContext, mockedUserManager.Object);
            var dbUser  = SeedUsersMethods.SeedUserWithRole(dbContext);

            var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.UnbanUserAsync(dbUser.Id));

            Assert.Equal(ErrorConstants.IncorrectUser, exception.Message);
        }
        public async void WithNotBanned_ShouldBanUser()
        {
            var dbContext         = this.GetDbContext();
            var mockedUserManager = CommonGetMockMethods.GetUserManager();

            CommonSetupMockMethods.SetupMockedUserManagerIsInRoleAsync(mockedUserManager, true);
            var service = this.GetService(dbContext, mockedUserManager.Object);
            var dbUser  = SeedUsersMethods.SeedUserWithRole(dbContext);

            await service.BanUserAsync(dbUser.Id);

            Assert.True(dbUser.LockoutEnd > DateTime.UtcNow);
        }
        private async Task CallScheduleTestDriveAsync(
            ScheduleTestDriveServiceModel model,
            ApplicationDbContext dbContext,
            string userId)
        {
            SeedStatusesMethods.SeedStatus(dbContext, TestDriveStatus.Upcoming);
            var mockedUserManager = CommonGetMockMethods.GetUserManager();

            CommonSetupMockMethods.SetupMockedUserManagerGetUserId(mockedUserManager, userId);
            var service = this.GetService(dbContext, mockedUserManager.Object);
            var user    = new Mock <ClaimsPrincipal>().Object;

            await service.ScheduleTestDriveAsync(model, user);
        }
        public async void WithBannedUser_ShouldUnbanUser()
        {
            var dbContext         = this.GetDbContext();
            var mockedUserManager = CommonGetMockMethods.GetUserManager();

            CommonSetupMockMethods.SetupMockedUserManagerIsInRoleAsync(mockedUserManager, true);
            var service = this.GetService(dbContext, mockedUserManager.Object);
            var dbUser  = SeedUsersMethods.SeedUserWithRole(dbContext);

            this.BanUser(dbContext, dbUser);

            await service.UnbanUserAsync(dbUser.Id);

            Assert.Null(dbUser.LockoutEnd);
        }
Beispiel #7
0
        public async void WithAlreadyExistingEmail_ShouldNotCreateNewUser()
        {
            var dbContext         = this.GetDbContext();
            var mockedUserManager = CommonGetMockMethods.GetUserManager();
            var dbUser            = SeedUsersMethods.SeedUser(dbContext, Guid.NewGuid().ToString());
            var service           = this.GetService(dbContext, mockedUserManager.Object);

            var dbRole       = SeedRolesMethods.SeedAdminRole(dbContext);
            var serviceModel = new UserServiceModel();

            serviceModel.Email = dbUser.Email;

            await service.SeedUserAsync(serviceModel, "", dbRole.Name);

            mockedUserManager.Verify(um => um.CreateAsync(It.IsAny <User>(), It.IsAny <string>()), Times.Never);
        }