/// <summary> /// Adds the item to system data collections. /// </summary> /// <param name="type">The type.</param> /// <param name="ariName">Name of the ari.</param> /// <param name="ariType">Type of the ari.</param> /// <param name="ariValue">The ari value.</param> /// <param name="temperatureF">The farenhait temperature.</param> /// <param name="temperatureC">The celsius temperature.</param> private void AddItemToSystemDataCollections(string type, string ariName, string ariType, string ariValue, double temperatureF = 0, double temperatureC = 0) { if (ariType.ToLower().Contains("temperature") || ariType.ToLower().Contains("fan")) { var minValue = "0"; var maxValue = "0"; if (ariType.ToLower().Contains("temperature")) { if (ariName.ToLower().Contains("temperature #")) { Console.WriteLine(ariName); } var temperatureRepository = new TemperatureRepository(); temperatureRepository.Add(ariName, temperatureF, temperatureC); var maxAverageTemperature = temperatureRepository.GetMaxTemperature(ariName); var minAverageTemperature = temperatureRepository.GetMinTemperature(ariName); maxValue = $"{maxAverageTemperature.ValueC} ({maxAverageTemperature.ValueF} F)"; minValue = $"{minAverageTemperature.ValueC} ({minAverageTemperature.ValueF} F)"; } _systemDataCollections[type].Add(new SystemDataItem { Name = ariName, Type = ariType, Value = ariValue, MinValue = minValue, MaxValue = maxValue }); } }
/// <summary> /// Constroi instancia do serviço /// </summary> /// <param name="configuration"></param> /// <param name="serviceSettings"></param> /// <param name="temperatureFacade"></param> public MonitoringService(IConfiguration configuration, GeneralSettings serviceSettings, BaseFacade <Temperature> temperatureFacade) { _temperatureRepository = new TemperatureRepository(configuration); _cityRepository = new CityRepository(configuration); _temperatureApiFacade = temperatureFacade; _serviceSettings = serviceSettings; }
public void RemoverTemperaturaSemCidade() { var repo = new TemperatureRepository(config); repo.Remove((TestContext.Properties["TemperaturaSemCidade"] as Temperature)); // Assert - Expects exception }
public void CadastrarTemperaturaDataInvalida() { var repo = new TemperatureRepository(config); repo.Add((TestContext.Properties["TemperaturaComDataInvalida"] as Temperature)); // Assert - Expects exception }
/// <summary> /// Carrega no objeto atual e retorna todas as temperaturas registradas para uma cidade. /// </summary> /// <param name="city">Cidade</param> /// <param name="config">Configurações da aplicação</param> /// <returns></returns> public static IEnumerable <Temperature> TemperaturesExt(this City city, IConfiguration config) { var temperatureRepository = new TemperatureRepository(config); var allTemperatures = temperatureRepository.GetAll(city.Id); city.Temperatures = allTemperatures; return(city.Temperatures); }
/// <summary> /// Carrega no objeto atual e retorna todas as temperaturas registradas nas íltimas XX horas /// </summary> /// <param name="city">Cidade</param> /// <param name="config">Configurações da aplicação</param> /// <param name="latestHours">Numero de horas</param> /// <returns></returns> public static IEnumerable <Temperature> LatestTemperaturesExt(this City city, IConfiguration config, int latestHours) { var temperatureRepository = new TemperatureRepository(config); var lastestTemperature = temperatureRepository.GetByDate(new Temperature { CityId = city.Id }, DateTime.Now.AddHours(0 - latestHours)); city.Temperatures = lastestTemperature; return(city.Temperatures); }
public static Temperature LastTemperatureExt(this City city, IConfiguration config) { var temperatureRepository = new TemperatureRepository(config); var lastTemperature = temperatureRepository.GetLast(city.Id); city.Temperatures = new List <Temperature> { lastTemperature }; return(lastTemperature); }
/// <summary> /// Construtor /// </summary> /// <param name="configuration">Configurações gerais da aplicação, passado por injeção de dependencia registrada no startup.cs</param> /// <param name="byCepSettings">Configurações da api utilizada para buscar cidades por CEP (Opção registrada no startup.cs)</param> /// <param name="autocompleteSettings">Configurações da api utilizada para buscar cidades para autocomplete (Opção registrada no startup.cs)</param> /// <param name="generalSettings">Configurações de funcionamento da aplicação (Opção registrada no startup.cs)</param> public CitiesController(IConfiguration configuration, IOptionsSnapshot <CityByCepApiSettings> byCepSettings, IOptionsSnapshot <CityAutocompleteApiSettings> autocompleteSettings, IOptionsSnapshot <GeneralSettings> generalSettings) { _configuration = configuration; _generalSettings = generalSettings.Value; _cityRepository = new CityRepository(_configuration); _temperatureRepository = new TemperatureRepository(_configuration); _bycepFacade = FacadeFactory <City> .Create(byCepSettings.Value); _autocompleteFacade = FacadeFactory <City> .Create(autocompleteSettings.Value); }
public async Task <List <ListViewDataRow> > GetDesiredDataFromApiForListView(bool isTemperature, bool isHumidity, int amount, string date, string sensorName) { if (isTemperature && isHumidity) { isHumidity = false; } if (isTemperature) { var rowList = CreateNewListForTemperature(); var repo = new TemperatureRepository(); var temperatures = await repo.GetTemperatures(amount, date, sensorName); foreach (var item in temperatures) { rowList.Add(new ListViewDataRow() { RoomName = item.TemperatureSensor.Room.Name.ToString(), SensorName = item.TemperatureSensor.Name.ToString(), Value = item.Value.ToString(), Date = item.Date.ToShortDateString() }); } return(rowList); } else if (isHumidity) { var rowList = CreateNewListForHumidity(); var repo = new HumidityRepository(); var humidity = await repo.GetHumidity(amount, date, sensorName); foreach (var item in humidity) { rowList.Add(new ListViewDataRow() { RoomName = item.HumiditySensor.Room.Name.ToString(), SensorName = item.HumiditySensor.Name.ToString(), Value = item.Value.ToString(), Date = item.Date.ToShortDateString() }); } return(rowList); } else { return(null); } }
public async Task <List <PlotData> > GetTemperatureFromApiForPlot(string dateTime, string sensorName) { var temperatureList = new List <PlotData>(); var repo = new TemperatureRepository(); var temperatures = await repo.GetTemperatures(100, dateTime, sensorName); foreach (var item in temperatures) { temperatureList.Add(new PlotData() { Value = item.Value, Date = item.Date }); } return(temperatureList); }
public UnitOfWork(ApplicationDbContext db) { _db = db; Room = new RoomRepository(_db); Device = new DeviceRepository(_db); HttpDevice = new HttpDeviceRepository(_db); MqttDevice = new MqttDeviceRepository(_db); ZigbeeDevice = new ZigbeeDeviceRepository(_db); PublishMessage = new MqttPublishingMessageRepository(_db); SubscribeMessage = new MqttSubscriptionMessageRepository(_db); BatteryReading = new BatteryRepository(_db); ContactReading = new ContactRepository(_db); HumidityReading = new HumidityRepository(_db); MotionReading = new MotionRepository(_db); TemperatureReading = new TemperatureRepository(_db); }
public UnitOfWork(GrowingPlantsContext context) { UserRepository = new UserRepository(context); TreeRepository = new TreeRepository(context); MeasurementUnitRepository = new MeasurementUnitRepository(context); LightRepository = new LightRepository(context); HumidityRepository = new HumidityRepository(context); TemperatureRepository = new TemperatureRepository(context); FavoriteTreeRepository = new FavoriteTreeRepository(context); CountryRepository = new CountryRepository(context); PlantingProcessRepository = new PlantingProcessRepository(context); PlantingEnvironmentRepository = new PlantingEnvironmentRepository(context); ProcessStepRepository = new ProcessStepRepository(context); PlantingActionRepository = new PlantingActionRepository(context); RecurrenceRepository = new RecurrenceRepository(context); NotificationRepository = new NotificationRepository(context); PlantingSpotRepository = new PlantingSpotRepository(context); PlantTypeRepository = new PlantTypeRepository(context); GalleryRepository = new GalleryRepository(context); PictureRepository = new PictureRepository(context); }
public async Task SaveTemperaturesToAExistingFile() { //Arrange var options = new OptionsWrapper <TemperatureSettings>(new TemperatureSettings { BasePath = basePath }); var expectedFilePath = basePath + "/02-01-20_temps.csv"; var expectedLine1 = "02/01/20 00:05:00,15.8,51.2,7.05,few clouds"; var mockFileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { expectedFilePath, new MockFileData(expectedLine1 + "\n") }, // { @"c:\demo\jQuery.js", new MockFileData("some js") }, // { @"c:\demo\image.gif", new MockFileData(new byte[] { 0x12, 0x34, 0x56, 0xd2 }) } }); var repository = new TemperatureRepository(options, mockFileSystem, NullLogger <TemperatureRepository> .Instance); var temperatureToSave = new Temperature { dateTime = new DateTime(2020, 01, 02, 0, 10, 0), Humidity = 45.6, InsideTemp = 21.2, OutsideTemp = 14.3, WeatherDescription = "Sunny but cold" }; //Act await repository.SaveTemperature(temperatureToSave); //Assert Assert.IsTrue(mockFileSystem.FileExists(expectedFilePath)); var temperatureFile = mockFileSystem.File.ReadLines(expectedFilePath); var temperatureLine1 = temperatureFile.Skip(0).Take(1).Single(); Assert.AreEqual(expectedLine1, temperatureLine1); var temperatureLine2 = temperatureFile.Skip(1).Take(1).Single(); var expectedLine2 = $"{temperatureToSave.dateTime:dd/MM/yy HH:mm:ss},{temperatureToSave.InsideTemp},{temperatureToSave.Humidity},{temperatureToSave.OutsideTemp},{temperatureToSave.WeatherDescription}"; Assert.AreEqual(expectedLine2, temperatureLine2); }
public async Task Given_TemperatureRepository_When_GettingAllTemperatureRecords_Then_AllRecordsShouldBeReturnedAsync() { await RunOnDatabaseAsync(async sut => { //Arrange var repo = new TemperatureRepository(sut); var record = new TemperatureRecord { Id = Guid.NewGuid(), UserId = Guid.NewGuid(), Value = 10, Time = new DateTime(2017, 11, 20, 11, 21, 1) }; //Act await repo.AddAsync(record); await repo.SaveChangesAsync(); //Assert var results = await repo.GetAllAsync(); results.Count.Should().Be(1); }); }
public async Task Given_TemperatureRepository_When_AddingATemperatureRecord_Then_TheRecordShouldBeMemorizedAsync() { await RunOnDatabaseAsync(async sut => { //Arrange var repo = new TemperatureRepository(sut); var record = new TemperatureRecord { Id = Guid.NewGuid(), UserId = Guid.NewGuid(), Value = 10, Time = new DateTime(2017, 11, 20, 11, 21, 1) }; //Act await repo.AddAsync(record); await repo.SaveChangesAsync(); //Assert var results = await repo.GetAllAsync(); results[0].ShouldBeEquivalentTo(record); }); }
public async Task Given_TemperatureRepository_When_GettingTemperatureRecordsOfAUser_Then_AllRecordsOfThatUserShouldBeReturnedAsync() { await RunOnDatabaseAsync(async sut => { //Arrange var repo = new TemperatureRepository(sut); var userId = Guid.NewGuid(); var records = new List <TemperatureRecord> { new TemperatureRecord { Id = Guid.NewGuid(), UserId = userId, Value = 1, Time = new DateTime(2017, 11, 20, 11, 21, 1) }, new TemperatureRecord { Id = Guid.NewGuid(), UserId = Guid.NewGuid(), Value = 2, Time = new DateTime(2017, 11, 20, 11, 21, 1) } }; //Act foreach (var record in records) { await repo.AddAsync(record); } await repo.SaveChangesAsync(); //Assert var results = await repo.GetByUserIdAsync(userId); results.Count.Should().Be(1); }); }
public async Task SaveTemperaturesToANewFile() { //Arrange var options = new OptionsWrapper <TemperatureSettings>(new TemperatureSettings { BasePath = basePath }); var expectedFilePath = basePath + "/01-01-20_temps.csv"; var mockFileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { // { @"expectedFilePath", new MockFileData("Testing is meh.") }, // { @"c:\demo\jQuery.js", new MockFileData("some js") }, // { @"c:\demo\image.gif", new MockFileData(new byte[] { 0x12, 0x34, 0x56, 0xd2 }) } }); mockFileSystem.Directory.CreateDirectory(basePath); var repository = new TemperatureRepository(options, mockFileSystem, NullLogger <TemperatureRepository> .Instance); var temperatureToSave = new Temperature { dateTime = new DateTime(2020, 01, 01, 0, 0, 0), Humidity = 45.6, InsideTemp = 21.2, OutsideTemp = 14.3, WeatherDescription = "Sunny but cold" }; //Act await repository.SaveTemperature(temperatureToSave); //Assert Assert.IsTrue(mockFileSystem.FileExists(expectedFilePath)); var temperatureFile = mockFileSystem.File.ReadLines(expectedFilePath); var temperatureLine = temperatureFile.First(); var expectedLine = $"{temperatureToSave.dateTime:dd/MM/yy HH:mm:ss},{temperatureToSave.InsideTemp},{temperatureToSave.Humidity},{temperatureToSave.OutsideTemp},{temperatureToSave.WeatherDescription}"; Assert.AreEqual(expectedLine, temperatureLine); }
public TemperatureController(IConfiguration config) { _model = new TemperatureRepository(config); }
public TemperatureService(TemperatureRepository repository) : base(repository) { }
public async Task <IEnumerable <TemperatureAvgYearly> > GetTemperatureAvgYearly(string sensorName) { var repo = new TemperatureRepository(); return(await repo.GetTemperatureAvgYearly(sensorName)); }
public void ObterHistoricoTemperaturasCidadesInexistente() { var repo = new TemperatureRepository(config); repo.GetByDate((TestContext.Properties["TemperaturaSemCidade"] as Temperature), DateTime.Now); }
public TemperatureController() { _temperatureRepository = new TemperatureRepository(); }