Beispiel #1
0
        public async Task GetCandleAsync_WhenExceptionIsBeingThrown_ShouldThrowApiException()
        {
            // Arrange
            var importer = new Mock <IImporter>();

            importer
            .Setup(i =>
                   i.ImportAsync(
                       It.IsAny <string>(),
                       It.IsAny <DateTime>(),
                       It.IsAny <DateTime>(),
                       PeriodOption.Daily,
                       CancellationToken.None))
            .ThrowsAsync(new Exception());

            var service = new ExternalFinanceService(importer.Object, _loggerMock.Object);

            // Act
            var exception =
                await Should.ThrowAsync <ApiException>(async() =>
                                                       await service.GetCandleAsync(CompanySymbol, _today));

            // Assert
            this.ShouldSatisfyAllConditions(
                () =>
            {
                exception.Code.ShouldBe(HttpStatusCode.NotFound);
                exception.Errors.ShouldBe(
                    $"Quote data not found [{CompanySymbol}/{_today:yyyy-MM-dd}].");
            });
        }
Beispiel #2
0
        public async Task GetCandleAsync_WhenArgumentExceptionIsBeingThrown_ShouldThrowApiException()
        {
            // Arrange
            const string message = "message";

            var importer = new Mock <IImporter>();

            importer
            .Setup(i =>
                   i.ImportAsync(
                       It.IsAny <string>(),
                       It.IsAny <DateTime>(),
                       It.IsAny <DateTime>(),
                       PeriodOption.Daily,
                       CancellationToken.None))
            .ThrowsAsync(new ArgumentException(message));

            var service = new ExternalFinanceService(importer.Object, _loggerMock.Object);

            // Act
            var exception =
                await Should.ThrowAsync <ApiException>(async() =>
                                                       await service.GetCandleAsync(CompanySymbol, _today));

            // Assert
            this.ShouldSatisfyAllConditions(
                () =>
            {
                exception.Code.ShouldBe(HttpStatusCode.BadRequest);
                exception.Errors.ShouldBe(message);
            });
        }
Beispiel #3
0
        public async Task GetCandleAsync_WhenParametersAreValid_ShouldReturnCandle()
        {
            // Arrange
            var utcNowOffset = DateTimeOffset.UtcNow;

            var importer = new Mock <IImporter>();

            importer
            .Setup(i =>
                   i.ImportAsync(
                       It.IsAny <string>(),
                       It.IsAny <DateTime>(),
                       It.IsAny <DateTime>(),
                       PeriodOption.Daily,
                       CancellationToken.None))
            .ReturnsAsync(GetCandles(utcNowOffset));

            var service = new ExternalFinanceService(importer.Object, _loggerMock.Object);

            // Act
            var result = await service.GetCandleAsync(CompanySymbol, _today);

            // Assert
            this.ShouldSatisfyAllConditions(
                () =>
            {
                result.Close.ShouldBe(1m);
                result.DateTime = utcNowOffset;
            }
                );
        }