public async Task Handler_should_update_cache_for_static_sensor() { var fakeStaticSensorReading = new StaticSensorReading { Id = 1, StaticSensorId = 1 }; var fakeStaticSensor = new StaticSensor { Id = 1, Readings = new List <StaticSensorReading> { fakeStaticSensorReading } }; var fakeStaticSensorDbSet = new List <StaticSensor> { fakeStaticSensor }; _dataContextMock.Setup(x => x.StaticSensors).ReturnsDbSet(fakeStaticSensorDbSet); _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object); var cancellationToken = new CancellationToken(); var notification = new StaticSensorVisibilityStateChangedNotification(fakeStaticSensor.Id); var handler = new StaticSensorVisibilityStateChangedNotificationHandler(_sensorCacheHelperMock.Object, _dataContextFactoryMock.Object); //Act await handler.Handle(notification, cancellationToken); //Assert _sensorCacheHelperMock.Verify( x => x.UpdateStaticSensorCacheAsync(It.Is <StaticSensor>(it => it == fakeStaticSensor && it.Readings.SequenceEqual(fakeStaticSensor.Readings))), Times.Once); }
public async Task Handler_should_throw_not_found_exception_if_sensor_doesnt_exist() { _dataContextMock.Setup(x => x.StaticSensors).ReturnsDbSet(new List <StaticSensor>()); _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object); var cancellationToken = new CancellationToken(); var notification = new StaticSensorVisibilityStateChangedNotification(1); var handler = new StaticSensorVisibilityStateChangedNotificationHandler(_sensorCacheHelperMock.Object, _dataContextFactoryMock.Object); //Act Task Act() => handler.Handle(notification, cancellationToken); //Assert await Assert.ThrowsAsync <SensorNotFoundException>(Act); }