Ejemplo n.º 1
0
        public async void WithCorrectId_ShouldReturnUser()
        {
            var dbContext = this.GetDbContext();
            var dbUser    = SeedUsersMethods.SeedUserWithRole(dbContext);
            var service   = this.GetService(dbContext);

            var model = await service.GetUserByIdAsync(dbUser.Id);

            Assert.NotNull(model);
        }
Ejemplo n.º 2
0
        public async void WithBiggerPageNumber_ShouldEmptyCollection()
        {
            var dbContext = this.GetDbContext();

            SeedUsersMethods.SeedUserWithRole(dbContext);
            var pageNumber = 2;

            var model = await this.CallGetSortedUsersAsync(dbContext, pageNumber);

            Assert.Empty(model);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 protected void SeedUserAndAdmin(ApplicationDbContext dbContext)
 {
     SeedUsersMethods.SeedUserWithRole(dbContext);
     SeedUsersMethods.SeedAdminWithRole(dbContext);
 }