public async void ScrapeObjects_ShouldSetCorrectData_UntilScrapingIsFinished(string methodName) { //Arrange var resultFromFundaApi = new FundaResponseModel { Objects = new List <FundaObject>() { new FundaObject() { MakelaarNaam = "TestMakelaar1" }, new FundaObject() { MakelaarNaam = "TestMakelaar1" }, new FundaObject() { MakelaarNaam = "TestMakelaar2" } } }; //This is a long running test, since I mocked the service to throw the "401 max number of requests reached exception" //and therefore my code waits 1 minute before doing the next call _apiCaller.SetupSequence(x => x.GetResponseAsync <FundaResponseModel>(It.IsAny <Uri>())) .ReturnsAsync(resultFromFundaApi) .ReturnsAsync(resultFromFundaApi) .ReturnsAsync(resultFromFundaApi) .ReturnsAsync(new FundaResponseModel() { Objects = new List <FundaObject>() }); //this is to make the scraper think it finished to scrape //Act Type scraperType = _target.GetType(); MethodInfo scraperMethod = scraperType.GetMethod(methodName); await(Task) scraperMethod.Invoke(_target, new object[] { It.IsAny <int>() }); //Assert if (methodName == "ScrapeObjects") { Assert.Equal(2, _target.makelaarsWithPropertiesAmount.Count); Assert.True(_target.GetPropertiesScrapingStatus()); Assert.Empty(_target.makelaarsWithPropertiesWithGardenAmount); Assert.Equal(6, _target.makelaarsWithPropertiesAmount["TestMakelaar1"]); Assert.Equal(3, _target.makelaarsWithPropertiesAmount["TestMakelaar2"]); } else { Assert.Equal(2, _target.makelaarsWithPropertiesWithGardenAmount.Count); Assert.True(_target.GetPropertiesWithGardenScrapingStatus()); Assert.Equal(6, _target.makelaarsWithPropertiesWithGardenAmount["TestMakelaar1"]); Assert.Equal(3, _target.makelaarsWithPropertiesWithGardenAmount["TestMakelaar2"]); } }
public async void ScrapeObjects_ShouldSetCorrectData_UntilException(string methodName) { //Arrange var resultFromFundaApi = new FundaResponseModel { Objects = new List <FundaObject>() { new FundaObject() { MakelaarNaam = "TestMakelaar1" }, new FundaObject() { MakelaarNaam = "TestMakelaar1" }, new FundaObject() { MakelaarNaam = "TestMakelaar2" } } }; _apiCaller.SetupSequence(x => x.GetResponseAsync <FundaResponseModel>(It.IsAny <Uri>())) .ReturnsAsync(resultFromFundaApi) .Throws(new Exception()); //Act Type scraperType = _target.GetType(); MethodInfo scraperMethod = scraperType.GetMethod(methodName); await(Task) scraperMethod.Invoke(_target, new object[] { It.IsAny <int>() }); //Assert if (methodName == "ScrapeObjects") { Assert.Equal(2, _target.makelaarsWithPropertiesAmount.Count); Assert.False(_target.GetPropertiesScrapingStatus()); Assert.Empty(_target.makelaarsWithPropertiesWithGardenAmount); Assert.Equal(2, _target.makelaarsWithPropertiesAmount["TestMakelaar1"]); Assert.Equal(1, _target.makelaarsWithPropertiesAmount["TestMakelaar2"]); } else { Assert.Equal(2, _target.makelaarsWithPropertiesWithGardenAmount.Count); Assert.False(_target.GetPropertiesWithGardenScrapingStatus()); Assert.Equal(2, _target.makelaarsWithPropertiesWithGardenAmount["TestMakelaar1"]); Assert.Equal(1, _target.makelaarsWithPropertiesWithGardenAmount["TestMakelaar2"]); } }