Exemplo n.º 1
0
        public async Task AddAdminThrowExceptionIfEmailExistTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            var usersRepository = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var userManager     = this.GetUserManagerMock();
            var rolesRepository = new EfDeletableEntityRepository <ApplicationRole>(dbContext);
            var service         = new UsersService(usersRepository, userManager.Object, rolesRepository, null, null, null, null);

            await SeedDataAsync(dbContext);

            string userName = "******";
            string email    = "*****@*****.**";
            string password = "******";

            await Assert.ThrowsAsync <ArgumentException>(() => service.AddAdmin(userName, email, password));
        }
Exemplo n.º 2
0
        public async Task AddAdminCorrectlyTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            var    usersRepository = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var    userManager     = this.GetUserManagerMock();
            var    rolesRepository = new EfDeletableEntityRepository <ApplicationRole>(dbContext);
            var    service         = new UsersService(usersRepository, userManager.Object, rolesRepository, null, null, null, null);
            string userName        = "******";
            string email           = "*****@*****.**";
            string password        = "******";

            var result = service.AddAdmin(userName, email, password);

            var user = usersRepository.All().Where(u => u.UserName == "*****@*****.**").FirstOrDefault();

            var isInRole = await userManager.Object.IsInRoleAsync(user, GlobalConstants.AdministratorRoleName);

            Assert.True(isInRole);
        }