public void When_Positions_Have_The_Same_Period_Then_Are_Sumed()
        {
            //Arrange
            var powerService = Substitute.For <IPowerService>();
            var exporter     = Substitute.For <IReportExporter>();
            var dataProvider = new FakeReportDateProvider();
            var sut          = new InterDayReportGenerator(powerService, exporter, dataProvider);

            var firstPowerTrade  = PowerTrade.Create(new DateTime(2016, 11, 05), 24);
            var secondPowerTrade = PowerTrade.Create(new DateTime(2016, 11, 05), 24);

            var trades = new[] { firstPowerTrade, secondPowerTrade };

            for (int k = 0; k < trades.Length; k++)
            {
                for (int i = 0; i < trades[k].Periods.Length; i++)
                {
                    trades[k].Periods[i].Volume = i;
                }
            }
            dataProvider.WithCurrentDateAndTime(new DateTime(2016, 11, 05));
            powerService.GetTradesAsync(new DateTime(2016, 11, 05)).Returns(trades);

            //Act
            Task.Factory.StartNew(async() => await sut.CreateReportAsync(1, ""), CancellationToken.None, TaskCreationOptions.None, BackgroundScheduler.Default);

            //Assert
            exporter.Received().Export(Arg.Any <string>(), Arg.Any <DateTime>(), Arg.Is <InterdayPowerReportPosition[]>(o => o.Length == 24 && o[6].Volume == 12));
        }
Пример #2
0
        public void When_Report_Is_Crashed_Then_Retry()
        {
            //Arrange
            var powerService = Substitute.For <IPowerService>();
            var exporter     = Substitute.For <IReportExporter>();
            var dataProvider = new FakeReportDateProvider();
            var sut          = new InterDayReportGenerator(powerService, exporter, dataProvider);

            dataProvider.WithCurrentDateAndTime(new DateTime(2016, 11, 06, 23, 00, 00));

            powerService.GetTradesAsync(Arg.Any <DateTime>()).Throws(new Exception());

            //Act
            Task.Factory.StartNew(async() => await sut.CreateReportAsync(3, ""), CancellationToken.None, TaskCreationOptions.None, BackgroundScheduler.Default);

            //Assert
            powerService.Received(3).GetTradesAsync(Arg.Any <DateTime>());
        }
Пример #3
0
        public void When_Report_Is_Scheduled_Then_Power_Service_Is_Called()
        {
            //Arrange
            var powerService = Substitute.For <IPowerService>();
            var exporter     = Substitute.For <IReportExporter>();
            var dataProvider = new FakeReportDateProvider();
            var sut          = new InterDayReportGenerator(powerService, exporter, dataProvider);

            var powerTrade = PowerTrade.Create(new DateTime(2016, 11, 06), 24);

            powerService.GetTradesAsync(new DateTime(2016, 11, 07)).Returns(new[] { powerTrade });

            //Act
            Task.Factory.StartNew(async() => await sut.CreateReportAsync(1, ""), CancellationToken.None, TaskCreationOptions.None, BackgroundScheduler.Default);

            //Assert
            powerService.Received(1).GetTradesAsync(Arg.Any <DateTime>());
        }
        public void When_PowerTrade_Has_The_Same_Date_As_Report_Then_Is_Calculated()
        {
            var powerService = Substitute.For <IPowerService>();
            var exporter     = Substitute.For <IReportExporter>();
            var dataProvider = new FakeReportDateProvider();
            var sut          = new InterDayReportGenerator(powerService, exporter, dataProvider);

            var powerTrade = PowerTrade.Create(new DateTime(2016, 11, 07), 24);

            for (int i = 0; i < powerTrade.Periods.Length; i++)
            {
                powerTrade.Periods[i].Volume = i;
            }
            dataProvider.WithCurrentDateAndTime(new DateTime(2016, 11, 07));
            powerService.GetTradesAsync(new DateTime(2016, 11, 07)).Returns(new[] { powerTrade });

            //Act
            Task.Factory.StartNew(async() => await sut.CreateReportAsync(1, ""), CancellationToken.None, TaskCreationOptions.None, BackgroundScheduler.Default);

            //Assert
            exporter.Received().Export(Arg.Any <string>(), Arg.Any <DateTime>(), Arg.Is <InterdayPowerReportPosition[]>(o => o.Length == 24 && o[6].Volume == 6));
        }