예제 #1
0
        public async Task GetAveragePrice_ValidRequest_CorrectContent()
        {
            // Arrange
            var expected = new AveragePriceViewModel
            {
                Date  = new DateTime(2018, 3, 15, 17, 26, 40),
                Price = 133.71
            };

            var uriBuilder = new UriBuilder(this.fixture.HttpClient.BaseAddress)
            {
                Query = "portfolio=Fannie Mae&owner=Google&instrument=CDS&date=15/03/2018 17:34:50",
                Path  = "api/prices/average"
            };

            // Act
            var response = await this.fixture.HttpClient.GetAsync(uriBuilder.Uri);

            var jsonContent = await response.Content.ReadAsStringAsync();

            var actual = JsonConvert.DeserializeObject <AveragePriceViewModel>(jsonContent, new IsoDateTimeConverter {
                DateTimeFormat = DateFormat.Default
            });

            // Assert
            actual.Should().BeEquivalentTo(expected);
        }
        public async Task GetAveragePrice_WhenExistsPrices_ShouldBeOkObjectResult(
            AveragePriceViewModel resultDto,
            GetAveragePriceDto dto)
        {
            // Arrange
            this.mediatorMock
            .Setup(m => m.Send(It.IsAny <GetAveragePriceQuery>(), default))
            .ReturnsAsync(new DataHandlerResult <AveragePriceViewModel>(resultDto));

            // Act
            var actual = await this.sut.GetAverage(dto);

            // Assert
            actual.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeEquivalentTo(resultDto);
        }
        public async Task Handle_WhenPriceExists_ShouldReturnCorrectAverage(
            Expression <Func <Price, bool> > expression,
            DateTime timeslotDate,
            double average)
        {
            // Arrange
            var expected = new AveragePriceViewModel
            {
                Date  = timeslotDate,
                Price = average
            };

            var request = CreateRequest();

            this.dateTimeConverterMock
            .Setup(d => d.GetTimeSlotStartDate(It.IsAny <DateTime>()))
            .Returns(timeslotDate);

            this.specificationMock
            .Setup(s => s.ToExpression(request))
            .Returns(expression);

            this.priceRepositoryMock
            .Setup(r => r.GetAllAsync(expression,
                                      It.IsAny <Expression <Func <Price, double> > >()))
            .ReturnsAsync(new List <double> {
                average
            });

            // Act
            var actual = await this.sut.Handle(request, default);

            // Assert
            actual.Should().BeAssignableTo <DataHandlerResult <AveragePriceViewModel> >()
            .Which.Data.Should().BeEquivalentTo(expected);
        }