NucuCar/NucuCar.UnitTests/NucuCar.Sensors.Tests/EnvironmentSensor.Tests/Bme680GrpcServiceTest.cs

55 lines
2 KiB
C#
Raw Normal View History

using Microsoft.Extensions.Logging;
using Moq;
2019-12-06 22:54:32 +00:00
using NucuCar.Domain.Sensors;
2019-11-30 16:55:55 +00:00
using NucuCar.Sensors;
using NucuCar.Sensors.EnvironmentSensor;
using NucuCarSensorsProto;
using Xunit;
namespace NucuCar.UnitTests.NucuCar.Sensors.Tests.EnvironmentSensor.Tests
{
public class Bme680GrpcServiceTest
{
private readonly Mock<ILogger<Bme680GrpcService>> _mockLogger;
2019-11-30 16:55:55 +00:00
private readonly Mock<ISensor<Bme680Sensor>> _mockSensor;
private readonly Mock<TestBme680Sensor> _mockTestSensor;
public Bme680GrpcServiceTest()
{
_mockLogger = new Mock<ILogger<Bme680GrpcService>>();
2019-11-30 16:55:55 +00:00
_mockSensor = new Mock<ISensor<Bme680Sensor>>();
_mockTestSensor = new Mock<TestBme680Sensor>();
_mockSensor.Setup(ms => ms.Object).Returns(_mockTestSensor.Object);
2019-11-30 16:55:55 +00:00
}
[Fact]
public void Test_GetSensorState()
{
var service = new Bme680GrpcService(_mockLogger.Object, _mockSensor.Object);
var result = service.GetState(null, null).Result;
2019-11-30 16:55:55 +00:00
// Default sensor state is error
Assert.Equal(SensorStateEnum.Error, result.State);
// Verify that the sensor get state method is called.
_mockSensor.Verify(s => s.Object.GetState(), Times.AtLeastOnce());
_mockSensor.Setup(s => s.Object.GetState()).Returns(SensorStateEnum.Initialized);
result = service.GetState(null, null).Result;
2019-11-30 16:55:55 +00:00
Assert.Equal(SensorStateEnum.Initialized, result.State);
}
2019-11-30 16:55:55 +00:00
[Fact]
public void Test_GetSensorMeasurement()
{
_mockTestSensor.Setup(s => s.GetMeasurement()).Returns(new Bme680MeasurementData());
2019-11-30 16:55:55 +00:00
var service = new Bme680GrpcService(_mockLogger.Object, _mockSensor.Object);
service.GetMeasurement(null, null);
2019-11-30 16:55:55 +00:00
// Verify that the sensor get measurement method is called.
_mockSensor.Verify(s => s.Object.GetMeasurement(), Times.AtLeastOnce());
2019-11-30 16:55:55 +00:00
}
}
}