public LabFarmController(LabFarmService labfarmService, PlantService plantService, SensorService sensorService, SensorDataService sensorDataService, PictureService pictureService) { _labfarmService = labfarmService; _plantService = plantService; _sensorService = sensorService; _sensorDataService = sensorDataService; _pictureService = pictureService; }
public async Task NotCallGetSensorData_WhenTimeSpanIsLessThanPollingInterval() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "NotCallGetSensorData_WhenTimeSpanIsLessThanPollingInterval") .Options; Sensor validSensor = new Sensor { SensorId = "validId" }; DateTime value = DateTime.Now; validSensor.LastTimeStamp = value; validSensor.MinPollingIntervalInSeconds = 1000000; IEnumerable <Sensor> expectedList = new List <Sensor> { validSensor }; SensorData dbSensorData = new SensorData { Sensor = validSensor }; UserSensor dbUserSensor = new UserSensor { Sensor = validSensor }; using (DataContext actContext = new DataContext(contextOptions)) { Mock <IApiClient> apiClientMock = new Mock <IApiClient>(); Mock <INotificationService> notificationServiceMock = new Mock <INotificationService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCacheWrapper> memoryCacheMock = new Mock <IMemoryCacheWrapper>(); await actContext.SensorData.AddAsync(dbSensorData); await actContext.Sensors.AddAsync(validSensor); await actContext.UserSensors.AddAsync(dbUserSensor); await actContext.SaveChangesAsync(); memoryCacheMock.Setup(mock => mock.GetOrSetCache()) .Returns(Task.FromResult(expectedList)); SensorDataService SUT = new SensorDataService( apiClientMock.Object, actContext, notificationServiceMock.Object, memoryCacheMock.Object); await SUT.GetSensorsDataAsync(); apiClientMock.Verify(mock => mock.GetSensorData(It.IsAny <string>()), Times.Never); } }
public async Task InsertAsyncTest() { var sensorDataRepository = A.Fake <ISensorDataRepository>(); var service = new SensorDataService(sensorDataRepository); var aggregatedSensorData = new AggregatedSensorData { SensorBoxId = "test", SensorType = SensorType.Temperature, AggregationType = AggregationType.Mean, CreatedAt = DateTimeOffset.UtcNow, Value = 1 }; await service.InsertAsync(aggregatedSensorData); A.CallTo(() => sensorDataRepository.InsertAsync(aggregatedSensorData)).MustHaveHappened(); }
public MainWindow() { InitializeComponent(); _service = new SensorDataService(); _logger = LogManager.GetCurrentClassLogger(); AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += CurrentDomain_UnhandledException; CreateIcon(); _service.Start(); try { EnsureAppIsInStartup(); } catch (Exception e) { _logger.Fatal(e); } }
public async Task CallGetOrSetCache_WhenInvoked() { Mock <IApiClient> apiClientMock = new Mock <IApiClient>(); Mock <DataContext> dataContextMock = new Mock <DataContext>(); Mock <INotificationService> notificationServiceMock = new Mock <INotificationService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCacheWrapper> memoryCacheMock = new Mock <IMemoryCacheWrapper>(); IEnumerable <Sensor> expectedList = new List <Sensor>(); memoryCacheMock.Setup(mock => mock.GetOrSetCache()) .Returns(Task.FromResult(expectedList)); SensorDataService SUT = new SensorDataService( apiClientMock.Object, dataContextMock.Object, notificationServiceMock.Object, memoryCacheMock.Object); await SUT.GetSensorsDataAsync(); memoryCacheMock.Verify(mock => mock.GetOrSetCache(), Times.Once); }
private void SendSensorData() { ISensorDataService sensorDataService = new SensorDataService(employee.Username, employee.Password); sensorDataService.Add(DataSensor); }
public async Task NotUpdateSensorValues_WhenTimeSpanIsLessThanPollingInterval_AndNewDataIsNot200Ok() { // Arrange var contextOptions = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "NotUpdateSensorValues_WhenTimeSpanIsLessThanPollingInterval_AndNewDataIsNot200Ok") .Options; Sensor validSensor = new Sensor { SensorId = "validId", LastValue = "1", UserSensors = new List <UserSensor>() }; DateTime value = new DateTime(2017, 1, 18); validSensor.LastTimeStamp = value; validSensor.MinPollingIntervalInSeconds = 0; IEnumerable <Sensor> expectedList = new List <Sensor> { validSensor }; SensorData dbSensorData = new SensorData { Sensor = validSensor, Value = "1" }; UserSensor dbUserSensor = new UserSensor { Sensor = validSensor }; validSensor.UserSensors.Add(dbUserSensor); List <UserSensor> affectedSensors = new List <UserSensor>(); affectedSensors.AddRange(validSensor.UserSensors); SensorData apiSensorData = null; using (DataContext actContext = new DataContext(contextOptions)) { Mock <IApiClient> apiClientMock = new Mock <IApiClient>(); Mock <INotificationService> notificationServiceMock = new Mock <INotificationService>(); Mock <ISensorService> sensorServiceMock = new Mock <ISensorService>(); Mock <IMemoryCacheWrapper> memoryCacheMock = new Mock <IMemoryCacheWrapper>(); await actContext.SensorData.AddAsync(dbSensorData); await actContext.Sensors.AddAsync(validSensor); await actContext.UserSensors.AddAsync(dbUserSensor); await actContext.SaveChangesAsync(); memoryCacheMock.Setup(mock => mock.GetOrSetCache()) .Returns(Task.FromResult(expectedList)); apiClientMock.Setup(mock => mock.GetSensorData(It.IsAny <string>())) .Returns(Task.FromResult(apiSensorData)); notificationServiceMock.Setup(mock => mock.CheckAlarmNotificationsAsync(affectedSensors)) .Returns(Task.CompletedTask); SensorDataService SUT = new SensorDataService( apiClientMock.Object, actContext, notificationServiceMock.Object, memoryCacheMock.Object); await SUT.GetSensorsDataAsync(); } // Assert using (DataContext assertContext = new DataContext(contextOptions)) { var nonUpdatedSensorData = await assertContext.SensorData.FirstAsync(); var nonUpdatedSensor = await assertContext.Sensors.FirstAsync(); Assert.IsTrue(nonUpdatedSensorData.Value == "1"); Assert.IsTrue(nonUpdatedSensor.LastValue == "1"); } }
public SensorDataController(SensorDataService service) { _service = service; }