示例#1
0
        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);
        }
示例#2
0
        public async Task GenericComponentsHaveChanged_Should_Not_ReturnComponentsToInsertOrToDelete(IEnumerable <GenericComponent> genericComponents)
        {
            var genericComponentRepositoryMocked = new Mock <IGenericComponentRepository>();

            genericComponentRepositoryMocked.Setup(x => x.GetGenericComponents()).ReturnsAsync(await GeneratorGenericComponents.GenerateGenericComponentsAsync());

            var genericComponentService = new GenericComponentsImportService(genericComponentRepositoryMocked.Object, _optionsMocked, _loggerMocked, _mapComponentsClientMocked);

            var(componentsToInsert, componentsToDelete) = await genericComponentService.GenericComponentsHaveChanged(genericComponents);

            Assert.Empty(componentsToInsert);
            Assert.Empty(componentsToDelete);
        }
示例#3
0
        public void GetGenericNoiseComponents_Should_Not_ReturnNoiseComponents(MapComponentsDto mapComponentsDto)
        {
            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);

            var result = genericComponentService.GetGenericNoiseComponents(mapComponentsDto);

            Assert.Empty(result);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }