public void LoadSource_Successfully() { var document = _testDoc; // Arrange var mockHelper = new Mock<IRenUkHtmlHelper>(); mockHelper.Setup(l => l.LoadHtmlPage(out document, It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>())) .Returns(HttpStatusCode.OK); mockHelper.Setup(a => a.GetTotalAggregatesAndPages(It.IsAny<HtmlDocument>())).Returns(new[] {"3", "1"}); mockHelper.Setup(n => n.GetAggregateNodes(It.IsAny<HtmlDocument>())).Returns(_aggregateNodes); mockHelper.Setup(m => m.GetAggregateName(_aggregateNodesArray[0])).Returns(_aggregateNamesArray[0]); mockHelper.Setup(m => m.GetAggregateName(_aggregateNodesArray[1])).Returns(_aggregateNamesArray[1]); mockHelper.Setup(m => m.GetAggregateName(_aggregateNodesArray[2])).Returns(_aggregateNamesArray[2]); mockHelper.Setup(u => u.GenerateAggregateUrl(It.IsAny<string>(), _aggregateNamesArray[0], It.IsAny<string>())) .Returns(rubbishBaseUrl + "name/" + _aggregateNamesArray[0] + "/status/all/region/1094/"); mockHelper.Setup(u => u.GenerateAggregateUrl(It.IsAny<string>(), _aggregateNamesArray[1], It.IsAny<string>())) .Returns(rubbishBaseUrl + "name/" + _aggregateNamesArray[1] + "/status/all/region/1094/"); mockHelper.Setup(u => u.GenerateAggregateUrl(It.IsAny<string>(), _aggregateNamesArray[2], It.IsAny<string>())) .Returns(rubbishBaseUrl + "name/" + _aggregateNamesArray[2] + "/status/all/region/1094/"); // Instantiate the datasource class var dataSource = new RenUkDataSource(mockHelper.Object); // Act var result = dataSource.LoadSource(rubbishBaseUrl); // Assert Assert.IsTrue(result, "Expected a successful load of the 3 aggregates, should have returned 'OK'"); }
public void LoadSource_NotFound_Unsuccessful() { var document = _404Doc; // Arrange var mockHelper = new Mock<IRenUkHtmlHelper>(); mockHelper.Setup(l => l.LoadHtmlPage(out document, It.IsAny<string>(), It.IsAny<int>(), It.IsAny<string>())) .Returns(HttpStatusCode.NotFound); // Instantiate the datasource class var dataSource = new RenUkDataSource(mockHelper.Object); // Act var result = dataSource.LoadSource(rubbishBaseUrl); // Assert Assert.IsFalse(result, "Expected a successful load of the 3 aggregates, should have returned 'OK'"); }