Exemplo n.º 1
0
        public async Task GetUsersAsyncReturnsListOfUsers()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization {
                ConfigureMembers = true
            });
            var users     = fixture.CreateMany <User>();
            var repoMock  = new Mock <IRepository <User> >();
            var uowEfMock = new Mock <IUnitOfWorkEf>();

            repoMock.Setup(x => x.GetAllAsync()).ReturnsAsync(users);
            uowEfMock.Setup(x => x.Repository <User>()).Returns(repoMock.Object);
            fixture.Register(() => repoMock.Object);
            fixture.Register(() => uowEfMock.Object);
            fixture.Inject <IUsersService>(fixture.Freeze <UsersService>());

            var sut = fixture.Create <UsersController>();

            var result = (OkObjectResult)await sut.Get();

            var usersResult = (IList <UserEditionDto>)result.Value;

            users.ToList().Count.Should().Be(usersResult.Count);
        }