public async Task SaveGenericNoiseComponents_ShouldDeleteUnusedComponents() { var mapComponentsDto = GeneratorMapComponentsDto.GenerateMapComponentsDtoAsync().Result; mapComponentsDto.Components.RemoveAt(1); var mapComponentsClientMocked = new Mock <IMapComponentsClient>(); mapComponentsClientMocked.Setup(x => x.GetMapComponentsFromBcnConnectaApi()) .ReturnsAsync(mapComponentsDto); var optionsMocked = new Mock <IOptions <AppSettings> >(); optionsMocked.Setup(i => i.Value).Returns(new AppSettings { BcnConnectaApi = new BcnConnectaApi { SensorType = "noise" } }); var genericComponentRepositoryMocked = new Mock <IGenericComponentRepository>(); genericComponentRepositoryMocked.Setup(x => x.GetGenericComponents()) .ReturnsAsync(await GeneratorGenericComponents.GenerateGenericComponentsAsync()); var genericComponentService = new GenericComponentsImportService(genericComponentRepositoryMocked.Object, optionsMocked.Object, _loggerMocked, mapComponentsClientMocked.Object); var(newComponentsInserted, unusedComponentsDeleted) = await genericComponentService.SaveGenericNoiseComponents(); Assert.False(newComponentsInserted); Assert.True(unusedComponentsDeleted); }
public async Task ImportGenericComponents_Should_Not_ReturnGenericComponents() { var mapComponentsClientMocked = new Mock <IMapComponentsClient>(); var optionsMocked = new Mock <IOptions <AppSettings> >(); optionsMocked.Setup(i => i.Value).Returns(new AppSettings { BcnConnectaApi = new BcnConnectaApi { SensorType = "noise" } }); var genericComponentService = new GenericComponentsImportService(_genericComponentRepositoryMocked, optionsMocked.Object, _loggerMocked, mapComponentsClientMocked.Object); mapComponentsClientMocked.Setup(x => x.GetMapComponentsFromBcnConnectaApi()) .ReturnsAsync(await GeneratorMapComponentsDto.GenerateWrongMapComponentsDtoAsync()); var result = await genericComponentService.ImportGenericComponents(); Assert.Empty(result); }
public async Task ImportGenericComponents_ShouldReturnGenericComponents() { var mapComponentsClientMocked = new Mock <IMapComponentsClient>(); var optionsMocked = new Mock <IOptions <AppSettings> >(); optionsMocked.Setup(i => i.Value).Returns(new AppSettings { BcnConnectaApi = new BcnConnectaApi { SensorType = "noise" } }); var genericComponentService = new GenericComponentsImportService(_genericComponentRepositoryMocked, optionsMocked.Object, _loggerMocked, mapComponentsClientMocked.Object); mapComponentsClientMocked.Setup(x => x.GetMapComponentsFromBcnConnectaApi()) .ReturnsAsync(await GeneratorMapComponentsDto.GenerateMapComponentsDtoAsync()); var result = await genericComponentService.ImportGenericComponents(); var expected = GenericComponentConverter.MapToEntity(GeneratorMapComponentsDto.GenerateMapComponentsDtoAsync().Result.Components.Where(i => i.Icon.Equals("noise"))); Assert.Equal(expected.SingleOrDefault().IdComponent, result.SingleOrDefault().IdComponent); }