public void GetNetCashBalancePerFundByInvestorTest()
        {
            var factory = new TransactionFactory().WithInvestor(() => "Investor 1")
                          .WithFund(() => "Fund 1")
                          .WithPrice(() => 100)
                          .WithShares(() => 1)
                          .WithTransactionType(() => TransactionType.Sell);
            var transactionsForInvestor1 = factory.Build(3);

            transactionsForInvestor1[0].Fund = "Fund 2";

            var transactionsForInvestor2 = factory
                                           .WithInvestor(() => "Investor 2")
                                           .WithFund(() => "Fund 3")
                                           .WithShares(() => 1)
                                           .WithPrice(() => 100)
                                           .WithTransactionType(() => TransactionType.Sell)
                                           .Build(3);

            var allTransactions = new List <Transaction>();

            allTransactions.AddRange(transactionsForInvestor1);
            allTransactions.AddRange(transactionsForInvestor2);

            var subject = new ProfitReport(allTransactions);
            var profit  = subject.GetNetCashBalancePerFundByInvestor("Investor 1");

            profit.Should().ContainKey("Fund 1").And.ContainKey("Fund 2").And.NotContainKey("Fund 3");
            profit["Fund 1"].Should().Be(200);
            profit["Fund 2"].Should().Be(100);
        }
Example #2
0
        public void GetTransactionsForFundByInvestor()
        {
            var factory      = new TransactionFactory().WithFund(() => "Fund 1").WithInvestor(() => "Investor 1");
            var transactions = factory.Build(3);

            transactions.Add(factory.WithFund(() => "Fund 2").Build());
            transactions.Add(factory.WithInvestor(() => "Investor 2").Build());
            new BreakReport(transactions).GetTransactionsForFundByInvestor("Fund 1", "Investor 1")
            .Should().OnlyContain(t => t.Fund == "Fund 1" && t.Investor == "Investor 1");
        }
        public void GetTotalSoldForDateRangePerInvestorTest()
        {
            var allTransactions      = new List <Transaction>();
            var numberOfTransactions = 10;
            var factory = new TransactionFactory()
                          .WithInvestor(() => "Investor 1")
                          .WithDate(() => DateTime.Now)
                          .WithPrice(() => 100)
                          .WithShares(() => 1)
                          .WithTransactionType(() => TransactionType.Sell);

            allTransactions.AddRange(factory.Build(numberOfTransactions));

            allTransactions.AddRange(factory
                                     .WithInvestor(() => "Investor 2")
                                     .WithDate(() => DateTime.Now)
                                     .WithPrice(() => 100)
                                     .WithShares(() => 1)
                                     .WithTransactionType(() => TransactionType.Sell)
                                     .Build(numberOfTransactions));

            allTransactions.AddRange(factory
                                     .WithInvestor(() => "Investor 3")
                                     .WithDate(() => DateTime.Now.Subtract(new TimeSpan(10, 0, 0)))
                                     .WithTransactionType(() => TransactionType.Sell)
                                     .Build(numberOfTransactions));

            var result = new SalesReport(allTransactions).GetTotalSoldForDateRangePerInvestor(DateTime.Now.Subtract(new TimeSpan(5, 0, 0)));

            result.Select(kvp => kvp.Key).Should().NotContain("Investor 3")
            .And.Contain("Investor 1")
            .And.Contain("Investor 2");

            result["Investor 1"].Should().Be(numberOfTransactions * 100);
            result["Investor 2"].Should().Be(numberOfTransactions * 100);
        }