Пример #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_ShouldReturnComponentsToDelete(IEnumerable <GenericComponent> genericComponents)
        {
            var genericComponentRepositoryMocked = new Mock <IGenericComponentRepository>();

            genericComponentRepositoryMocked.Setup(x => x.GetGenericComponents())
            .ReturnsAsync(GeneratorGenericComponents.GenerateGenericComponentsAsync().Result.Append(GeneratorGenericComponents.GenerateGenerateComponent()));

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

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

            Assert.Empty(componentsToInsert);
            Assert.NotEmpty(componentsToDelete);
        }