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));
        }
Example #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>());
        }
Example #3
0
        public void When_Report_Is_Scheduled_Before_23_Then_Power_Service_Is_Called_With_The_Same_Date()
        {
            //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, 14, 34, 23));
            var powerTrade = PowerTrade.Create(new DateTime(2016, 11, 06), 24);

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

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

            //Assert
            powerService.Received(1).GetTradesAsync(Arg.Is <DateTime>(o => o == new DateTime(2016, 11, 06)));
        }
        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));
        }