public void Generate_Only_Headers_Without_Trades()
        {
            var sut = new PositionReportGenerator();

            var position = CalculatedPositionInfoLocalDate.Create(DateTime.UtcNow, Enumerable.Empty <Trade>());

            var report = sut.Generate(position);

            var truncatedReport = report.Replace(Environment.NewLine, string.Empty);

            truncatedReport.Should().Be("Local Time,Volume", "Strict report check. Headers must match.");
        }
        public async Task <Result <CalculatedPositionInfoLocalDate> > GetPositionAsync(DateTime date)
        {
            var dtoTrades = await this.adapter.GetTradesAsync(date);

            var dates = dtoTrades.Select(t => t.Date).Distinct().ToArray();

            if (dates.Length > 1)
            {
                return(new Result <CalculatedPositionInfoLocalDate>(new DomainServiceException(date, "Power trades must fall on the same date.")));
            }

            var trades = Map(dtoTrades);

            return(CalculatedPositionInfoLocalDate.Create(date, trades));
        }
        public void Generate_Rows()
        {
            var sut = new PositionReportGenerator();

            var position = CalculatedPositionInfoLocalDate.Create(
                date: DateTime.Parse("01/04/2015"),
                trades: new[]
            {
                Trade.Create(19, -42)
            });

            var report = sut.Generate(position);

            var indexHeaderEnd = report.IndexOf(Environment.NewLine, StringComparison.Ordinal);

            var truncatedReport = report
                                  .Substring(indexHeaderEnd)
                                  .Replace(Environment.NewLine, string.Empty);

            truncatedReport.Should().Be("17:00,-42", "Strict report check. Rows must match.");
        }
Exemple #4
0
        public async Task OnSave_ReportGenerated_Then_ReportSaved()
        {
            // TODO: Use something like SharpFilesystem to avoid testing against actual file system.

            var expectedReport = Guid.NewGuid().ToString();

            var saver = new PositionReportSaver(TestContext.CurrentContext.TestDirectory);

            var mockGenerator = new Mock <IPositionReportGenerator>();

            mockGenerator.Setup(gen => gen.Generate(It.IsAny <CalculatedPositionInfo>()))
            .Returns(expectedReport);

            var sut = new PositionReporter(mockGenerator.Object, saver);

            var position = CalculatedPositionInfoLocalDate.Create(this.date, Enumerable.Empty <Trade>());

            await sut.ReportAsync(position);

            var actualReport = File.ReadAllText(this.reportPath);

            actualReport.Should().BeEquivalentTo(expectedReport, "Generated report should match.");
            File.Exists(this.reportPath).Should().BeTrue("Report should be saved.");
        }
Exemple #5
0
        public void No_Positions_Without_Trades()
        {
            var agg = CalculatedPositionInfoLocalDate.Create(DateTime.UtcNow, Enumerable.Empty <Trade>());

            agg.HasPositions.Should().BeFalse("Has no positions when no trades provided.");
        }
        public async Task WhenCalculatingPowerPosition()
        {
            var result = await this.service.GetPositionAsync(DateTime.UtcNow);

            result.IfSucc(pos => this.dataOutput = pos);
        }