예제 #1
0
        public async Task Handler_should_throw_exception_if_dependency_is_null(int paramsSetIndex)
        {
            //Arrage
            var testArgs = new[]
            {
                new[] { _dataContextFactoryMock.Object, (object)null },
                new[] { (object)null, (object)_sensorCacheHelperMock.Object }
            };

            var testArgsCurrentSet = testArgs[paramsSetIndex];

            //Act
            void Act()
            {
                var staticSensorReadingCreatedNotificationHandler = new StaticSensorReadingCreatedNotificationHandler((IDataContextFactory <DataContext>)testArgsCurrentSet[0],
                                                                                                                      (ISensorCacheHelper)testArgsCurrentSet[1]);
            }

            //Assert
            Assert.Throws <ArgumentNullException>(Act);
        }
예제 #2
0
        public async Task Handler_update_cache()
        {
            //Arrange

            var fakeReading = new StaticSensorReading
            {
                Id             = 1,
                StaticSensorId = 1
            };

            var fakeSensor = new StaticSensor
            {
                Id        = 1,
                ApiKey    = ApiKeyHelper.Generate(),
                IsActive  = true,
                IsVisible = true,
                Readings  = new List <StaticSensorReading> {
                    fakeReading
                }
            };
            var fakeSensorDbSet = new List <StaticSensor> {
                fakeSensor
            };

            _dataContextMock.Setup(x => x.Set <StaticSensor>()).ReturnsDbSet(fakeSensorDbSet);
            _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object);

            var cancellationToken = new CancellationToken();
            var notification      = new StaticSensorReadingCreatedNotification(fakeSensor.Id, fakeReading);
            var handler           =
                new StaticSensorReadingCreatedNotificationHandler(_dataContextFactoryMock.Object,
                                                                  _sensorCacheHelperMock.Object);

            //Act
            await handler.Handle(notification, cancellationToken);

            //Assert
            _sensorCacheHelperMock.Verify(
                x => x.UpdateSensorCacheWithReadingAsync(It.Is <StaticSensorReading>(it => it == fakeReading)), Times.Once);
        }
예제 #3
0
        public async Task Handler_should_throw_exception_if_sensor_not_found()
        {
            //Arrange

            var fakeReading = new StaticSensorReading
            {
                Id             = 1,
                StaticSensorId = 1
            };

            var fakeSensor = new StaticSensor
            {
                Id        = 1,
                ApiKey    = ApiKeyHelper.Generate(),
                IsActive  = true,
                IsVisible = true,
                Readings  = new List <StaticSensorReading> {
                    fakeReading
                }
            };
            var fakeSensorDbSet = new List <StaticSensor> ();

            _dataContextMock.Setup(x => x.Set <StaticSensor>()).ReturnsDbSet(fakeSensorDbSet);
            _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object);

            var cancellationToken = new CancellationToken();
            var notification      = new StaticSensorReadingCreatedNotification(fakeSensor.Id, fakeReading);
            var handler           =
                new StaticSensorReadingCreatedNotificationHandler(_dataContextFactoryMock.Object,
                                                                  _sensorCacheHelperMock.Object);

            //Act
            Task Act() => handler.Handle(notification, cancellationToken);

            //Assert
            await Assert.ThrowsAsync <SensorNotFoundException>(Act);
        }