Exemple #1
0
        public async Task Get_Static_Sensor_By_Id_should_return_sensor_by_dto_with_requested_id()
        {
            //Arrange
            var fakeStaticSensor = new StaticSensor {
                Id = 1
            };
            var fakeStaticSensorDbSet = new List <StaticSensor> {
                fakeStaticSensor
            };

            _dataContextMock.Setup(x => x.StaticSensors).ReturnsDbSet(fakeStaticSensorDbSet);
            _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object);
            _mapperMock.Setup(x =>
                              x.Map <StaticSensor, StaticSensorDTO>(It.Is <StaticSensor>(it => it.Id == fakeStaticSensor.Id)))
            .Returns(((StaticSensor v) => new StaticSensorDTO {
                Id = v.Id
            }));

            var queries = new ReadingsQueries(_dataContextFactoryMock.Object, _mapperMock.Object);

            //Act
            var result = await queries.GetStaticSensorByIdAsync(fakeStaticSensor.Id);

            //Arrange
            Assert.Equal(fakeStaticSensor.Id, result.Id);
        }
Exemple #2
0
        public async Task Get_Static_Sensor_By_Id_should_return_null_if_database_is_empty()
        {
            //Arrange
            _dataContextMock.Setup(x => x.StaticSensors).ReturnsDbSet(new List <StaticSensor>());
            _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object);
            _mapperMock.Setup(x => x.Map <StaticSensor, StaticSensorDTO>(It.Is <StaticSensor>(it => it == null)))
            .Returns((() => null));

            var queries = new ReadingsQueries(_dataContextFactoryMock.Object, _mapperMock.Object);

            //Act
            var result = await queries.GetStaticSensorByIdAsync(1);

            //Arrange
            Assert.Null(result);
        }