I have an interface IVehicle
public interface IVehicle
{
Task<ApiResponse> GetVehicleInfo();
}
This is my implementation of the interface
public class Vehicle : IVehicle
{
private string m_vehicleId;
private VehicleInfoEndPoint m_vEndPoint;
public Vehicle()
{
}
public Vehicle(string vehicleId, string device, HttpClient client,string Uri)
{
m_vEndPoint = new VehicleInfoEndPoint(device, client, Uri);
}
public async Task<ApiResponse> GetVehicleInfo()
{
await m_vEndPoint.GetVehicleInfoPostAsync();
return m_vehicleInfoEndPoint.FullResponse;
}
}
I want to unit test this class. For that I have written the following code.
[Test]
public void Vehicle_GetVehicleInformation_shouldCall_VehicleInfoEndPoint_GetVehicleInfo()
{
var endPointMock = Mock.Of<IVehicleInfoEndPoint>();
var result = new ApiResponse();
var vehicle = new Mock<IVehicle>();
vehicle.Setup(x => x.GetVehicleInfo()).Returns(Task.FromResult(result));
var response = vehicle.Object.GetVehicleInfo().Result;
Mock.Get(endPointMock).Verify(x => x.GetVehicleInfo(), Times.Once);
}
My test is failing with the error that
Expected invocation on the mock once, but was 0 times x=> x.GetVehicleInfo()