Esempio n. 1
0
        public async void WithEmptyUsersCollection_ShouldReturnEmptyCollection()
        {
            var dbContext = this.GetDbContext();

            SeedRolesMethods.SeedUserRole(dbContext);

            var model = await this.CallGetSortedUsersAsync(dbContext);

            Assert.Empty(model);
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
 private void SeedAllRoles(ApplicationDbContext dbContext)
 {
     this.AdminRole = SeedRolesMethods.SeedAdminRole(dbContext);
     this.UserRole  = SeedRolesMethods.SeedUserRole(dbContext);
 }