Exemple #1
0
        public async Task Should_GetAllAsync_ReturnsAListOfHouses()
        {
            //Arrange
            const int residentialId = 1;

            var entities = new List <HouseEf>
            {
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
                new HouseEf {
                    ResidentialId = residentialId
                },
            };

            var models = new List <House>
            {
                new House(),
                new House(),
                new House(),
                new House(),
                new House()
            };

            var parameter = new Parameter
            {
                ItemsPerPage = 5
            };

            var mock = entities.AsQueryable().BuildMockDbSet();

            _houseRepositoryMock.Setup(x => x.AsNoTracking()).Returns(mock.Object);

            _mapperMock.Setup(x => x.Map <IEnumerable <House> >(It.IsAny <IEnumerable <HouseEf> >()))
            .Returns(models);

            _manager = new HouseManager(_mapperMock.Object, _houseRepositoryMock.Object);


            //Act

            var result = await _manager.GetAllAsync(residentialId, parameter);

            //Assert

            _houseRepositoryMock.Verify(x => x.AsNoTracking(), Times.Once);
            _mapperMock.Verify(x => x.Map <IEnumerable <House> >(It.IsAny <IEnumerable <HouseEf> >()), Times.Once);

            Assert.NotNull(result);
            Assert.Equal(10, result.TotalOfItems);
            Assert.Equal(5, result.Items.Count());
        }