public void GetAggregate_UnSuccessful_NoSuchAggregate_MixedSourceValues() { // Arrange // Configure the AggregateRepository _mockAggregateRepository.Setup(r => r.Get(It.IsAny<int>(), It.IsAny<DataTypeEnum>())).Returns(() => null); var dataService = new DataService(_mockAggregateRepository.Object, _mockDatasourceRepository.Object, _mockDataTypeRepository.Object, _mockImportServiceResolver.Object, _mockDataSourceResolver.Object); // Act var result = dataService.GetAggregateWithDataType(4, DataTypeEnum.Statistics); // Assert Assert.IsNull(result, "Expected NULL reference to be returned, Aggregate does not exist."); }
public void GetAggregateWithDataType_Aikengall_Status_Successful() { // 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.GetAggregateWithDataType(AikengallAggregate,DataTypeEnum.Status); // Assert var resultData = result.Data.ToArray(); var minsegments = (resultData.Count() >= 1); Assert.IsNotNull(result, "Expected aggregate 'Aikengall' to be returned"); Assert.AreEqual("Aikengall", result.Name, "Expected Name to be 'Aikengall'."); Assert.IsTrue(minsegments, "Expected at least one data segment 'Status' to be returned."); Assert.AreEqual(DataTypeEnum.Status, resultData[0].DataType, "Expected the first data segment to be a 'Turbine' segment."); Assert.AreEqual(DataTypeEnum.Turbine, resultData[1].DataType, "Expected the second data segment to be a 'Status' segment."); } }
public void GetAggregate_Successful_ReturnsDataTypeStatistics_MixedSourceValues() { // 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(It.IsAny<int>(), It.IsAny<DataTypeEnum>())).Returns(_blacklawWindfarm); // 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 results = dataService.GetAggregateWithDataType(4, DataTypeEnum.Statistics); // Assert Assert.AreEqual("Blacklaw Windfarm", results.Name, "Expected 'Blacklaw Windfarm' to be returned as first object."); Assert.AreEqual("External JSON Object", results.Data.FirstOrDefault(t => t.DataType == DataTypeEnum.Statistics).Data, "Expected the data to have been overridden as external source"); Assert.AreEqual(DataTypeEnum.Statistics, results.Data.FirstOrDefault().DataType, "Expected original data '{achany estate}' to be returned"); Assert.AreEqual(1, results.Data.Count, "Expected only one data segment"); }