public ShareHistoryQueryResponse ConvertFrom(ApiResponse queryResponse)
        {
            if (queryResponse == null)
            {
                return(null);
            }

            var result                    = queryResponse.Chart.Result[0];
            var quoteIndicators           = result.Indicators.Quote[0];
            var shareHistoryQueryResponse = new ShareHistoryQueryResponse
            {
                ShareName = result.Meta.Symbol,
                History   = new ShareHistory()
            };

            // If timestamp is null it means there are no results for the period so we can simply ignore
            if (result.TimeStamp != null)
            {
                var history = shareHistoryQueryResponse.History;
                history.TimeStamp = result.TimeStamp;
                history.Open      = quoteIndicators.Open;
                history.Close     = quoteIndicators.Close;
                history.Low       = quoteIndicators.Low;
                history.High      = quoteIndicators.High;
            }

            return(shareHistoryQueryResponse);
        }
        public async Task GetBasicShareInformation_HistoryHasAllIndicatorsPopulated_AveragePriceIsCalculatedForAllValues()
        {
            // Arrange
            string symbol = "GOOG";
            var    shareHistoryQueryResponse = new ShareHistoryQueryResponse
            {
                ShareName = symbol,
                History   = new ShareHistory
                {
                    TimeStamp = new long[] { 1590586200, 1590672600, 1590759000 },
                    Low       = new decimal?[] { 1, 1, 1 },
                    High      = new decimal?[] { 2, 2, 2 },
                    Open      = new decimal?[] { 3, 3, 3 },
                    Close     = new decimal?[] { 4, 4, 4 }
                }
            };

            _mockShareHistoryQueryService
            .Setup(x => x.Query(symbol, It.IsAny <ShareHistoryQueryRange>()))
            .ReturnsAsync(shareHistoryQueryResponse);

            // Act
            var basicShareInformation = await _basicShareInformationService.GetBasicShareInformationAsync(symbol);

            //Assert
            Assert.Equal(2.5m, basicShareInformation.AverageSharePriceForPeriod);
        }
        public async Task GetBasicShareInformation_HistoryHasIndicatorsWithNullValues_NullValuesAreIgnored()
        {
            // Arrange
            string symbol = "GOOG";
            var    shareHistoryQueryResponse = new ShareHistoryQueryResponse
            {
                ShareName = symbol,
                History   = new ShareHistory
                {
                    TimeStamp = new long[] { 1590586200, 1590672600, 1590759000 },
                    Low       = new decimal?[] { 1, null, 1 },
                    High      = new decimal?[] { null, null, null },
                    Open      = new decimal?[] { null, null, 1 },
                    Close     = new decimal?[] { 3, 3, 3 }
                }
            };

            _mockShareHistoryQueryService
            .Setup(x => x.Query(symbol, It.IsAny <ShareHistoryQueryRange>()))
            .ReturnsAsync(shareHistoryQueryResponse);

            // Act
            var basicShareInformation = await _basicShareInformationService.GetBasicShareInformationAsync(symbol);

            //Assert
            Assert.Equal(2, basicShareInformation.AverageSharePriceForPeriod);
        }
        public async Task GetBasicShareInformation_ResponseHasNoHistory_MinimumSharePriceForPeriodIsZero()
        {
            // Arrange
            string symbol = "GOOG";
            var    shareHistoryQueryResponse = new ShareHistoryQueryResponse
            {
                ShareName = symbol,
                History   = new ShareHistory()
            };

            _mockShareHistoryQueryService
            .Setup(x => x.Query(symbol, It.IsAny <ShareHistoryQueryRange>()))
            .ReturnsAsync(shareHistoryQueryResponse);

            // Act
            var basicShareInformation = await _basicShareInformationService.GetBasicShareInformationAsync(symbol);

            //Assert
            Assert.Equal(0, basicShareInformation.MinimumSharePriceForPeriod);
        }
        public async Task GetBasicShareInformation_HistoryHasLowIndicatorsWithNullValues_MinimumSharePriceForPeriodIsSmallestNotNullLowIndicator()
        {
            // Arrange
            string symbol = "GOOG";
            var    shareHistoryQueryResponse = new ShareHistoryQueryResponse
            {
                ShareName = symbol,
                History   = new ShareHistory
                {
                    Low = new decimal?[] { 1, null, 3 }
                }
            };

            _mockShareHistoryQueryService
            .Setup(x => x.Query(symbol, It.IsAny <ShareHistoryQueryRange>()))
            .ReturnsAsync(shareHistoryQueryResponse);

            // Act
            var basicShareInformation = await _basicShareInformationService.GetBasicShareInformationAsync(symbol);

            //Assert
            Assert.Equal(1, basicShareInformation.MinimumSharePriceForPeriod);
        }
        public async Task GetBasicShareInformation_HistoryHasHighIndicators_MaximumSharePriceForPeriodIsLargestHighIndicator()
        {
            // Arrange
            string symbol = "GOOG";
            var    shareHistoryQueryResponse = new ShareHistoryQueryResponse
            {
                ShareName = symbol,
                History   = new ShareHistory
                {
                    High = new decimal?[] { 1, 2, 3 }
                }
            };

            _mockShareHistoryQueryService
            .Setup(x => x.Query(symbol, It.IsAny <ShareHistoryQueryRange>()))
            .ReturnsAsync(shareHistoryQueryResponse);

            // Act
            var basicShareInformation = await _basicShareInformationService.GetBasicShareInformationAsync(symbol);

            //Assert
            Assert.Equal(3, basicShareInformation.MaximumSharePriceForPeriod);
        }