コード例 #1
0
        public virtual async Task <IEnumerable <ApartComplex> > AggregateData()
        {
            var citiesData = await _cityHandler.GetCityData();

            var apartComplexes = await _apartComplexHandler.GetApartComplexes(citiesData);

            await _apartmentHandler.SetApartments(apartComplexes);

            return(apartComplexes);
        }
コード例 #2
0
        public async Task GetCityData()
        {
            // Arrange
            var city1Node = HtmlNode.CreateNode(_htmlCity1Literal);
            var city2Node = HtmlNode.CreateNode(_htmlCity2Literal);

            var expectedResult = new List <CityData>
            {
                new CityData()
                {
                    Name = "Київ", Url = "https://lun.ua/?q=kyiv"
                },
                new CityData()
                {
                    Name = "Київська обл.", Url = "https://lun.ua/?q=kyiv_region"
                }
            };

            var cityHRefs = new List <string>
            {
                "/?q=kyiv", "/?q=kyiv_region"
            };

            var htmlWebMock    = new Mock <HtmlWeb>();
            var htmlParserMock = new Mock <HtmlParser>(htmlWebMock.Object);

            htmlParserMock
            .Setup(htmlParser => htmlParser.ParseText(city1Node))
            .Returns(expectedResult[0].Name);
            htmlParserMock
            .Setup(htmlParser => htmlParser.ParseText(city2Node))
            .Returns(expectedResult[1].Name);
            htmlParserMock
            .Setup(htmlParser => htmlParser.ParseHref(city1Node))
            .Returns(cityHRefs[0]);
            htmlParserMock
            .Setup(htmlParser => htmlParser.ParseHref(city2Node))
            .Returns(cityHRefs[1]);

            var pageHandlerMock = new Mock <PageHandler>(htmlParserMock.Object);

            pageHandlerMock
            .Setup(pageHandler => pageHandler.LoadCityHtml())
            .ReturnsAsync(new HtmlNodeCollection(null)
            {
                city1Node, city2Node
            });
            pageHandlerMock
            .Setup(pageHandler => pageHandler.CreateLunUaUrl(cityHRefs[0]))
            .Returns(expectedResult[0].Url);
            pageHandlerMock
            .Setup(pageHandler => pageHandler.CreateLunUaUrl(cityHRefs[1]))
            .Returns(expectedResult[1].Url);

            var cityHandler = new CityHandler(pageHandlerMock.Object, htmlParserMock.Object);

            // Act
            var actualResult = await cityHandler.GetCityData();

            // Assert
            Assert.Equal(expectedResult.ToList(), actualResult.ToList());
        }