Exemplo n.º 1
0
        public async Task Get_Sensor_By_Id_should_return_requested_sensor_dto()
        {
            //Arrange
            var fakeStaticSensor = new StaticSensor {
                Id = 1
            };
            var fakeStaticSensorDbSet = new List <Sensor> {
                fakeStaticSensor
            };
            var fakeStaticSensorDto = new StaticSensorDTO {
                Id = fakeStaticSensor.Id
            };

            _dataContextMock.Setup(x => x.Sensors).ReturnsDbSet(fakeStaticSensorDbSet);
            _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object);
            _mapperMock.Setup(x => x.Map <Sensor, SensorDTO>(fakeStaticSensor))
            .Returns(fakeStaticSensorDto);

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

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

            //Arrange
            Assert.Equal(fakeStaticSensorDto, result);
        }
Exemplo n.º 2
0
        public async Task Get_Sensor_By_Id_should_return_null_if_database_is_empty()
        {
            //Arrange
            _dataContextMock.Setup(x => x.Sensors).ReturnsDbSet(new List <Sensor>());
            _dataContextFactoryMock.Setup(x => x.Create()).Returns(_dataContextMock.Object);
            _mapperMock.Setup(x => x.Map <Sensor, SensorDTO>(It.Is <Sensor>(it => it == null)))
            .Returns((() => null));

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

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

            //Arrange
            Assert.Null(result);
        }