public static IPositionReporter Create(string location)
        {
            if (string.IsNullOrWhiteSpace(location))
            {
                throw new Exception("Invalid empty location for reporter.");
            }

            var generator = new PositionReportGenerator();
            var saver     = new PositionReportSaver(location);

            return(new PositionReporter(generator, saver));
        }
Exemplo n.º 2
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.");
        }