Ejemplo n.º 1
0
        public async Task FindUsersAsyncShouldReturnAllExceptAdmin()
        {
            //Arrange
            Mapper.Initialize(config => config.AddProfile <AutoMapperProfile>());

            var adminService = new AdminUserService(Context, UserManager);

            User admin = new User()
            {
                Name          = "Admin",
                SecurityStamp = Guid.NewGuid().ToString()
            };

            await UserManager.AddToRoleAsync(admin, "Administrator");

            var users = new List <User>()
            {
                new User()
                {
                    Name          = "User1",
                    UserName      = "******",
                    SecurityStamp = Guid.NewGuid().ToString()
                },
                new User()
                {
                    Name          = "User2",
                    UserName      = "******",
                    SecurityStamp = Guid.NewGuid().ToString()
                },
                new User()
                {
                    Name          = "User3",
                    UserName      = "******",
                    SecurityStamp = Guid.NewGuid().ToString()
                }
            };

            foreach (var user in users)
            {
                await UserManager.AddToRoleAsync(user, "Author");
            }

            await Context.AddRangeAsync(users);

            await Context.AddAsync(admin);

            await Context.SaveChangesAsync();

            //Act

            var result = await adminService.All();

            //Assert

            result
            .Should()
            .NotContain(u => u.Name == "Admin");

            result
            .Should()
            .Contain(u => u.Name == "User2" ||
                     u.Name == "User1" ||
                     u.Name == "User3");
        }