Я пишу модульный тест для контроллера с ODataQueryOptions и не могу его смоделировать.
[EnableQuery]
public IQueryable<WeatherForecast> Get(ODataQueryOptions<WeatherForecast> options)
{
logger.LogInformation($"Call to end point [{options.Request.Method}]: Host :'{options.Request.Host}' Endpoint : '{options.Request.Path}'");
logger.LogInformation($"Query string: '{options.Request.QueryString}'");
return weatherForecastService.Get().Entity;
}
Пытаюсь что-то вроде
public class WeatherServiceTests
{
private readonly Mock<IWeatherService> weatherServiceMock;
private readonly Mock<ILogger<WeatherController>> loggerMock;
private readonly Mock<ODataQueryOptions<Weather>> optionsMock;
private readonly WeatherController weatherController;
public WeatherServiceTests()
{
weatherServiceMock = new Mock<IWeatherService>();
loggerMock = new Mock<ILogger<WeatherController>>();
optionsMock = new Mock<ODataQueryOptions<Weather>>();
weatherController = new WeatherController(loggerMock.Object, weatherServiceMock.Object);
}
private ApiResponse<IQueryable<Weather>> GetWeatherMockup()
{
var weather = new List<Weather>
{
new Weather {Content = "Content", Header = "Header", Source = "Source"}
}.AsQueryable();
return new ApiResponse<IQueryable<Weather>>(weather);
}
[Fact]
public void WeatherData_Get()
{
weatherServiceMock.Setup(x => x.Get()).Returns(GetWeatherMockup());
var response = weatherController.Get(optionsMock.Object).ToList();
Assert.NotNull(response);
Assert.True(response.Count == 1);
}
}
Как я могу издеваться над ODataQueryOptions? Я сослался на несколько ответов на один и тот же вопрос, но они бесполезны.