Пример #1
0
        public async Task AllNonAdminsAsync_ShouldReturn_AllUsersThatAreNotAdmins_ExcludingLogged()
        {
            var db         = GetDatabase();
            var mapper     = GetMapper();
            var userMnager = UserManagerMock.New;

            var firstUser = new User {
                Id = "1", UserName = "******"
            };
            var secondUser = new User {
                Id = "2", UserName = "******"
            };
            var thirdUser = new User {
                Id = "3", UserName = "******"
            };
            var forthUser = new User {
                Id = "4", UserName = "******"
            };
            var fifthUser = new User {
                Id = "5", UserName = "******"
            };
            await db.Users.AddRangeAsync(firstUser, secondUser, thirdUser, forthUser, fifthUser);

            await db.SaveChangesAsync();

            userMnager
            .Setup(u => u.GetUsersInRoleAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <User>()
            {
                firstUser,
                secondUser
            });

            var userService = new UsersService(mapper, db, userMnager.Object);
            //Act
            var result = await userService.AllNonAdminsAsync("3");

            //Assert
            result
            .Should()
            .NotBeNullOrEmpty()
            .And
            .HaveCount(2)
            .And
            .Match(u => u.ElementAt(0).Id == "4" &&
                   u.ElementAt(1).Username == "fifth");
        }