public IActionResult Get([FromQuery] DateTimeRangeRequestDto dateTimeRange) { var query = new RAMMetricsGetQuery(dateTimeRange); var result = _mediator.Send(query); return(Ok(result.Result)); }
public void RAMMetricsGetQueryHandlerTest() { //Arrange var dateTimeRange = new AutoFaker <DateTimeRangeRequestDto>() .RuleFor(x => x.From, f => f.Date.RecentOffset(5)) .RuleFor(x => x.To, f => f.Date.SoonOffset(5)) .Generate(); IReadOnlyCollection <RAMMetric> metricsList = new AutoFaker <RAMMetric>() .RuleFor(x => x.DateTime, x => x.Date.BetweenOffset(dateTimeRange.From, dateTimeRange.To)) .RuleFor(x => x.Something, x => x.Random.Int(0, 209715200)) .Generate(4).ToList(); var expected = metricsList.Adapt <IReadOnlyCollection <RAMMetricResponseDto> >(); _repository.GetMetricsByTimePeriod(Arg.Any <DateTimeOffset>(), Arg.Any <DateTimeOffset>()).Returns(metricsList); var query = new RAMMetricsGetQuery(dateTimeRange); //Act var resultMetricsList = base.Handle(query); //Assert _repository.Received(1).GetMetricsByTimePeriod(dateTimeRange.From, dateTimeRange.To); resultMetricsList.Should().BeEquivalentTo(expected); }
protected override IReadOnlyCollection <RAMMetricResponseDto> Handle(RAMMetricsGetQuery request) { var result = _repository.GetMetricsByTimePeriod(request.DateTimeRange.From, request.DateTimeRange.To); return(result.Adapt <IReadOnlyCollection <RAMMetricResponseDto> >()); }