예제 #1
0
        public async Task BanShouldBanUserAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            AutoMapperConfig.RegisterMappings(Assembly.Load("CookingBook.Web.ViewModels"));
            var dbContext = new ApplicationDbContext(options);
            var userRepo  = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            await userRepo.AddAsync(new ApplicationUser
            {
                Name               = "Trayan Keranov",
                Id                 = "trk",
                UserName           = "******",
                NormalizedUserName = "******",
                Email              = "*****@*****.**",
                NormalizedEmail    = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEKDTOW0hiJThqFCz2cTS+wMBN2HthJkHT1jCsqVhgYwc0XikiVo0ESJYcqs8yrZkgg==",
                SecurityStamp      = "5ZMAFTFQEDOZPXC573KIOV5B56KVMHKS",
                ConcurrencyStamp   = "5ed4afbd-318e-456b-8d1b-19a36f2d82f1",
                CreatedOn          = DateTime.Parse("1993-03-21 08:10:00.2228617"),
                EmailConfirmed     = true,
                Roles              = new List <IdentityUserRole <string> >(),
            });

            await userRepo.SaveChangesAsync();

            var      rolesRepo = new EfDeletableEntityRepository <ApplicationRole>(dbContext);
            var      service   = new UsersService(userRepo, rolesRepo);
            DateTime time      = DateTime.MaxValue;

            await service.Ban("trk", time);

            Assert.True(DateTime.Now < dbContext.Users.Find("trk").LockoutEnd);
            Assert.True(dbContext.Users.Find("trk").LockoutEnabled);
        }