Ejemplo n.º 1
0
        public async Task GetAllCountriesWithCities_ShouldBeDoneSuccessfully()
        {
            // Arrange
            var countries = new List <Country>()
            {
                new Country()
                {
                    Cities = new List <City>()
                    {
                        new City()
                        {
                            Id = 1
                        },
                        new City()
                        {
                            Id = 2
                        },
                    }
                }
            };

            var countriesToReturn = new List <CountryToReturnDto>()
            {
                new CountryToReturnDto()
                {
                    Cities = new List <CityToReturnDto>()
                    {
                        new CityToReturnDto()
                        {
                            Id = 1
                        },
                        new CityToReturnDto()
                        {
                            Id = 2
                        },
                    }
                }
            };

            _unitOfWorkMock.Setup(x => x.Countries.GetAllCountriesWithCities())
            .ReturnsAsync(countries);

            _mapperMock.Setup(x => x.Map <ICollection <CountryToReturnDto> >(countries))
            .Returns(countriesToReturn);

            // Act
            var result = await _sut.GetAllCountriesWithCities();

            // Assert
            Assert.Equal(countries.FirstOrDefault().Cities.FirstOrDefault().Id, result.FirstOrDefault().Cities.FirstOrDefault().Id);
        }