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 void WithCookie_ShouldReturnCookieValue()
        {
            var service = this.GetService();
            var mockedRequestCookies = new Mock <IRequestCookieCollection>();
            var key   = Guid.NewGuid().ToString();
            var value = Test.Value2;

            CommonGetMockMethods.SutupMockedRequestCookieCollection(mockedRequestCookies, key, value.ToString());

            var enumResult = service.GetValueOrDefault <Test>(mockedRequestCookies.Object, key);

            Assert.Equal(value, enumResult);
        }
        public async void WithUser_ShoudDeleteUser()
        {
            var dbContext = this.GetDbContext();

            var userManager = CommonGetMockMethods.GetSetupedUserManager(true).Object;
            var service     = this.GetService(dbContext, userManager);

            var dbUser = SeedUsersMethods.SeedUserWithRole(dbContext);

            await service.DeleteAsync(dbUser.Id);

            Assert.Empty(dbContext.Users);
        }
        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 <CarServiceModel> CallGetCarViewModelAsync(
            ApplicationDbContext dbContext,
            string carId,
            bool isUserSignIn,
            string userId)
        {
            var signInManager = CommonGetMockMethods.GetSetupedSignInManager(isUserSignIn).Object;
            var userManager   = CommonGetMockMethods.GetSetupedUserManager(userId);
            var service       = this.GetService(dbContext, signInManager, userManager);
            var user          = new Mock <ClaimsPrincipal>().Object;
            var model         = await service.GetCarTestDriveModelById <CarServiceModel>(carId, user);

            return(model);
        }
        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);
        }
        public async void WithAdmin_ShouldThrowException()
        {
            var dbContext = this.GetDbContext();

            var userManager = CommonGetMockMethods.GetSetupedUserManager(false).Object;
            var service     = this.GetService(dbContext, userManager);

            var dbAdmin = SeedUsersMethods.SeedAdminWithRole(dbContext);

            SeedRolesMethods.SeedUserRole(dbContext);

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

            Assert.Equal(ErrorConstants.IncorrectUser, exception.Message);
        }
Beispiel #11
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);
        }
        private async Task <IEnumerable <CarServiceModel> > CallGetCarsInventoryViewModelAsync(
            ApplicationDbContext dbContext,
            bool isUserSignIn,
            string userId,
            int pageNumber = 1)
        {
            var signInManager = CommonGetMockMethods.GetSetupedSignInManager(isUserSignIn).Object;
            var userManager   = CommonGetMockMethods.GetSetupedUserManager(isUserSignIn ? userId : null);
            var service       = this.GetService(dbContext, signInManager, userManager);
            var user          = new Mock <ClaimsPrincipal>().Object;

            var models = await(await service
                               .GetCarTestDriveModelAsync <CarServiceModel>(dbContext.BaseCars, user, pageNumber))
                         .ToArrayAsync();

            return(models);
        }