示例#1
0
        public async void WithEmptyUsersCollection_ShouldReturnEmptyCollection()
        {
            var dbContext = this.GetDbContext();

            SeedRolesMethods.SeedUserRole(dbContext);

            var model = await this.CallGetSortedUsersAsync(dbContext);

            Assert.Empty(model);
        }
        public async void WithAlreadyExistingStatus_ShouldDoNothing()
        {
            var dbContext = this.GetDbContext();
            var dbRole    = SeedRolesMethods.SeedUserRole(dbContext);
            var service   = this.GetService(dbContext);

            await service.SeedRolesAsync(dbRole.Name);

            Assert.Single(dbContext.Roles);
            Assert.Equal(dbRole, dbContext.Roles.First());
        }
        public async void WithStatuses_ShouldAddOnlyNotExistingStatuses()
        {
            var dbContext   = this.GetDbContext();
            var dbRole      = SeedRolesMethods.SeedUserRole(dbContext);
            var newRoleName = Guid.NewGuid().ToString();
            var service     = this.GetService(dbContext);

            await service.SeedRolesAsync(dbRole.Name, newRoleName);

            Assert.Equal(2, dbContext.Roles.Count());
            Assert.Equal(dbRole, dbContext.Roles.First());
        }
        public async void WithIncorrectId_ShouldThrowException()
        {
            var dbContext   = this.GetDbContext();
            var service     = this.GetService(dbContext);
            var incorrectId = Guid.NewGuid().ToString();

            SeedRolesMethods.SeedUserRole(dbContext);

            var exception = await Assert.ThrowsAsync <ArgumentException>(async() => await service.UnbanUserAsync(incorrectId));

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

            CommonSetupMockMethods.SetupMockedUserManagerIsInRoleAsync(mockedUserManager, false);
            var service = this.GetService(dbContext, mockedUserManager.Object);
            var dbAdmin = SeedUsersMethods.SeedAdminWithRole(dbContext);

            SeedRolesMethods.SeedUserRole(dbContext);

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

            Assert.Equal(ErrorConstants.IncorrectUser, exception.Message);
        }
示例#6
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 void SeedAllRoles(ApplicationDbContext dbContext)
 {
     this.AdminRole = SeedRolesMethods.SeedAdminRole(dbContext);
     this.UserRole  = SeedRolesMethods.SeedUserRole(dbContext);
 }