public void GetAggregate_UnSuccessful_NoAggregateFound() { // Arrange // Setup the mock datasource instance var mockDataSource = new Mock<IRenUkDataSource>(); mockDataSource.Setup(d => d.Get(It.IsAny<string>())).Returns(() => null); var dataService = new DataService(_mockAggregateRepository.Object, _mockDatasourceRepository.Object, _mockDataTypeRepository.Object, _mockImportServiceResolver.Object, _mockDataSourceResolver.Object); // Act var result = dataService.GetAggregate(_whiteleeWindfarm.Id); // Assert Assert.IsNull(result, "Expected a NULL object to be returned"); }
public void GetAggregate_NonExistantAggregate_Unsuccessful() { // Arrange: var inputDoc = _htmlSingleAggregateDoc; var dataService = new DataService(_repository, _dataSourceRepository, _dataTypeRepository, _importServiceResolver, _dataSourceResolver); // Mock the external call to the internet. using (ShimsContext.Create()) { // Fake the call to the internet HtmlAgilityPack.Fakes.ShimHtmlWeb.AllInstances.LoadString = (htmlWeb, s) => { return inputDoc; }; // Fake the statue code returned from HTTP response HtmlAgilityPack.Fakes.ShimHtmlWeb.AllInstances.StatusCodeGet = (web => { return System.Net.HttpStatusCode.OK; }); // Act var result = dataService.GetAggregate(NonExistentAggregate); // Assert Assert.IsNull(result, "Expected no aggregate to be returned"); } }
public void GetAggregate_Successful_ReturnsAggregate1() { // Arrange var importAggregate = new ImportAggregate { Identifier = "Whitelee Windfarm", Data = new Collection<ImportData> { new ImportData { DataType = DataTypeEnum.Statistics, Data = "External JSON Object" } }, ImportDate = DateTime.Now, SourceId = 2, }; // Setup the mock datasource instance var mockDataSource = new Mock<IRenUkDataSource>(); mockDataSource.Setup(d => d.Get(It.IsAny<string>())).Returns(importAggregate); // Configure the DataSourceResolver _mockDataSourceResolver.Setup(r => r.Resolve(It.IsAny<int>())).Returns(mockDataSource.Object); // Configure the AggregateRepository _mockAggregateRepository.Setup(r => r.Get(2)).Returns(_whiteleeWindfarm); // Configure the DataSourceRepository _mockDatasourceRepository.Setup(d => d.Get(1)).Returns(_dataSource1); _mockDatasourceRepository.Setup(d => d.Get(2)).Returns(_dataSource2); var dataService = new DataService(_mockAggregateRepository.Object, _mockDatasourceRepository.Object, _mockDataTypeRepository.Object, _mockImportServiceResolver.Object, _mockDataSourceResolver.Object); // Act var result = dataService.GetAggregate(_whiteleeWindfarm.Id); // Assert Assert.AreEqual("Whitelee Windfarm", result.Name, "Expected 'Whitelee Windfarm' to be returned as first object."); Assert.AreEqual("{whitelee windfarm}", result.Data.FirstOrDefault(t => t.DataType == DataTypeEnum.FootPrint).Data, "Expected original data '{whitelee windfarm}' to be returned"); Assert.AreEqual("External JSON Object", result.Data.FirstOrDefault(t => t.DataType == DataTypeEnum.Statistics).Data, "Expected the data to have been overridden as external source"); }