예제 #1
0
        public async Task GenerateIntradayReportAsync_TransitionToSummerTime(ITradingDataAdapter tradingDataAdapter)
        {
            // arrange
            var reportRepository = new ReportRepository(tradingDataAdapter);
            var csvService       = new CsvService();
            var reportService    = new IntradayReportServiceImpl(reportRepository, csvService);

            // act
            string csv = null;

            using (MemoryStream ms = new MemoryStream())
            {
                await reportService.GenerateIntradayReportAsync(_utcDateOfTransitionToSummerTime, _csvSettings, ms);

                ms.Seek(0, SeekOrigin.Begin);
                csv = new StreamReader(ms, Encoding.UTF8).ReadToEnd();
            }

            // assert:

            csv.Should().NotBeNullOrEmpty();

            var csvRows = csv.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            // Spec.: "CSV should only contain local time, use the GMT time zone periods as the number in the CSV (23 in this case)"
            csvRows.Length.Should().Be(23 + 1);             // data rows + header row

            // Check that report doesn't contain 1am period
            DateTime excludedPeriodDate = new DateTime(2020, 3, 29, 1, 0, 0);

            Assert.IsTrue(!csvRows.Any(r => r.Contains(excludedPeriodDate.ToString(_csvSettings.TimeFormat))));
        }
        public ReportRepository(ITradingDataAdapter tradingDataAdapter)
        {
            if (tradingDataAdapter == null)
            {
                throw new ArgumentNullException(nameof(tradingDataAdapter));
            }

            _tradingDataAdapter = tradingDataAdapter;
        }
예제 #3
0
        public async Task GenerateIntradayReportAsync_TransitionToWinterTime(ITradingDataAdapter tradingDataAdapter,
                                                                             double?volumeValueFor1amUtc, double?volumeValueFor2amUtc)
        {
            // arrange
            var reportRepository = new ReportRepository(tradingDataAdapter);
            var csvService       = new CsvService();
            var reportService    = new IntradayReportServiceImpl(reportRepository, csvService);

            // act
            string csv = null;

            using (MemoryStream ms = new MemoryStream())
            {
                await reportService.GenerateIntradayReportAsync(_utcDateOfTransitionToWinterTime, _csvSettings, ms);

                ms.Seek(0, SeekOrigin.Begin);
                csv = new StreamReader(ms, Encoding.UTF8).ReadToEnd();
            }

            // assert:

            csv.Should().NotBeNullOrEmpty();

            var csvRows = csv.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            // Spec.: "CSV should only contain local time, use the GMT time zone periods as the number in the CSV (25 in this case)"
            csvRows.Length.Should().Be(25 + 1);             // data rows + header row

            // Check that report contains two local 1am periods
            DateTime repeatedPeriodDate    = new DateTime(2020, 3, 29, 1, 0, 0);
            var      rowsForRepeatedPeriod = csvRows
                                             .Where(r => r.Contains(repeatedPeriodDate.ToString(_csvSettings.TimeFormat)))
                                             .ToArray();

            rowsForRepeatedPeriod.Length.Should().Be(2);

            // for mock data we can check additional system behavior
            if (volumeValueFor1amUtc != null && volumeValueFor2amUtc != null)
            {
                // Check that repeated rows contains valid Volume values (for 1am and for 2am UTC period)
                Assert.IsTrue(rowsForRepeatedPeriod.Any(r =>
                                                        r.Contains(volumeValueFor1amUtc.Value.ToString(_csvSettings.NumberFormat))));
                Assert.IsTrue(rowsForRepeatedPeriod.Any(r =>
                                                        r.Contains(volumeValueFor2amUtc.Value.ToString(_csvSettings.NumberFormat))));
            }
        }