Exemple #1
0
        public void TestGetTradesError()
        {
            TestSetupHelpers.SetErrorMode();

            var ps   = new PowerService();
            var date = new DateTime(2017, 12, 13);

            Assert.Throws <PowerServiceException>(() => ps.GetTrades(date));
        }
Exemple #2
0
        public void TestGetTrades()
        {
            TestSetupHelpers.SetTestMode();

            var ps   = new PowerService();
            var date = new DateTime(2017, 12, 13);

            var trades = ps.GetTrades(date);

            Assert.AreEqual(2, trades.Count());
        }
Exemple #3
0
        public void TestCreateFilenameFromRunSettings()
        {
            var expected    = @"c:\temp\PowerPosition_20171213_2350.csv";
            var runSettings = new RunSettings();

            runSettings.Refresh();

            var powerTradesSample = TestSetupHelpers.GetPowerTradesSample();

            var filenameCreator = new FilenameCreator();
            var filename        = filenameCreator.CreateFilename(runSettings, powerTradesSample);

            Assert.AreEqual(expected, filename);
        }
Exemple #4
0
        public void TestAggregatePowerTrades()
        {
            var powerTradesSample = TestSetupHelpers.GetPowerTradesSample();

            var ptAggregator         = new PowerTradeAggregator();
            var aggregatedPowerTrade = ptAggregator.Aggregate(powerTradesSample);

            Assert.IsTrue(aggregatedPowerTrade.Periods.Length == 24);

            for (var i = 0; i < 24; i++)
            {
                var expected = (i + 1) * 6 * 10;
                Assert.AreEqual(expected, aggregatedPowerTrade.Periods[i].Volume, string.Format("Mismatch for period {0}", i));
            }
        }
Exemple #5
0
        public void TestEndToEndError()
        {
            TestSetupHelpers.SetErrorMode();
            var ps          = new PowerService();
            var ppfw        = new PowerPositionFetcherWriter();
            var runSettings = TestSetupHelpers.GetSaveFileRunSettings();
            var date        = new DateTime(2017, 12, 13, 23, 52, 00);

            var now = DateTime.Now;

            ppfw.FetchTradesAndWriteToFile(ps, runSettings, date, new PowerTradeAggregator(), new FilenameCreator(),
                                           new FileWriter(), new Local23PeriodMapper());

            var expected = File.ReadAllLines(runSettings.Path + @"PowerPosition_20171213_" + now.ToString("HHmm") + ".csv");

            Assert.IsTrue(expected.Length <= 0);
        }
Exemple #6
0
        public void TestSaveFile()
        {
            var runSettings = TestSetupHelpers.GetSaveFileRunSettings();

            var aggregatedTrades = TestSetupHelpers.GetPowerTrade1();

            var filenameCreator = new FilenameCreator();
            var filename        = filenameCreator.CreateFilename(runSettings, aggregatedTrades.Date, new DateTime(2017, 12, 13, 23, 50, 55));

            var fileWriter = new FileWriter();

            var periodMapper = new Local23PeriodMapper();

            fileWriter.WritePowerPositionCsvFile(filename, aggregatedTrades, periodMapper);

            var expected = File.ReadAllLines(runSettings.Path + @"PowerPosition_20171213_2350_Expected.csv");
            var actual   = File.ReadAllLines(filename);

            Assert.AreEqual(expected.Length, actual.Length);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }