コード例 #1
0
        public async Task DevicesController_GetData_Tests()
        {
            //Valid Tests
            serviceMock.Setup(t => t.GetSensorDataAsync(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Sensors>())).ReturnsAsync(new SensorData {
                Sensor = Sensors.Humidity.ToString()
            });
            var result = await controller.GetData("deviceId", DateTime.Now, Sensors.Humidity);

            var actionResult = Assert.IsType <OkObjectResult>(result);
            var sensorData   = Assert.IsType <SensorData>(actionResult.Value);

            Assert.Equal(sensorData.Sensor, Sensors.Humidity.ToString());

            //Invalid Tests
            result = await controller.GetData("deviceId", DateTime.Now.AddDays(1), Sensors.Humidity);

            Assert.IsType <BadRequestObjectResult>(result);
        }