using Microsoft.Extensions.Logging; using Moq; using NucuCar.Domain.Sensors; using NucuCar.Sensors; using NucuCar.Sensors.Environment; using NucuCarSensorsProto; using Xunit; namespace NucuCar.UnitTests.NucuCar.Sensors.Tests.EnvironmentSensor.Tests { public class Bme680GrpcServiceTest { private readonly Mock> _mockLogger; private readonly Mock> _mockSensor; private readonly Mock _mockTestSensor; public Bme680GrpcServiceTest() { _mockLogger = new Mock>(); _mockSensor = new Mock>(); _mockTestSensor = new Mock(); _mockSensor.Setup(ms => ms.Object).Returns(_mockTestSensor.Object); } [Fact] public void Test_GetSensorState() { var service = new Bme680GrpcService(_mockLogger.Object, _mockSensor.Object); var result = service.GetState(null, null).Result; // 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; Assert.Equal(SensorStateEnum.Initialized, result.State); } [Fact] public void Test_GetSensorMeasurement() { _mockTestSensor.Setup(s => s.GetMeasurement()).Returns(new NucuCarSensorResponse()); var service = new Bme680GrpcService(_mockLogger.Object, _mockSensor.Object); service.GetMeasurement(null, null); // Verify that the sensor get measurement method is called. _mockSensor.Verify(s => s.Object.GetMeasurement(), Times.AtLeastOnce()); } } }