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);
        }
        public void GetUniqueSalesRepsTest()
        {
            var factory      = new TransactionFactory().WithSalesRep(() => "Rep 1");
            var transactions = factory.Build(3);

            transactions[0].SalesRepresentative = "Rep 2";
            new AssetReport(transactions).GetUniqueSalesReps()
            .Should().OnlyHaveUniqueItems().And.OnlyContain(rep => rep == "Rep 1" || rep == "Rep 2");
        }
示例#3
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 GetFundsForInvestorTest()
        {
            var factory = new TransactionFactory().WithInvestor(() => "Investor 1")
                          .WithFund(() => "Fund 1");
            var transactions = factory.Build(3);

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

            new ProfitReport(transactions).GetFundsForInvestor("Investor 1")
            .Should().Contain("Fund 1").And.Contain("Fund 2");
        }
        public void GetInvestorsForRepsTest()
        {
            var factory = new TransactionFactory().WithSalesRep(() => "Rep 1")
                          .WithInvestor(() => "Investor 1");
            var transactions = factory.Build(3);

            transactions[0].Investor = "Investor 2";
            new AssetReport(transactions).GetInvestorsForReps()
            .Should().ContainKey("Rep 1").WhichValue
            .Should().OnlyHaveUniqueItems().And.OnlyContain(value => value == "Investor 1" || value == "Investor 2");
        }
示例#6
0
        public void GetShareBalanceForFundByInvestorTest()
        {
            var factory = new TransactionFactory()
                          .WithFund(() => "Fund 1")
                          .WithInvestor(() => "Investor 1")
                          .WithShares(() => 100)
                          .WithTransactionType(() => TransactionType.Buy);
            var transactions = factory.Build(3);

            transactions.Add(factory.WithTransactionType(() => TransactionType.Sell).Build());
            new BreakReport(transactions).GetShareBalanceForFundByInvestor("Fund 1", "Investor 1")
            .Should().Be(200);
        }
        public void GetNetAmountHeldForInvestorTest()
        {
            var factory = new TransactionFactory().WithInvestor(() => "Investor 1")
                          .WithFund(() => "Fund 1")
                          .WithPrice(() => 100)
                          .WithShares(() => 1)
                          .WithTransactionType(() => TransactionType.Sell);
            var transactions = factory.Build(3);

            transactions.AddRange(factory.WithTransactionType(() => TransactionType.Buy).Build(1));
            transactions.AddRange(factory.WithFund(() => "Fund 2").Build(1));
            new AssetReport(transactions).GetNetAmountHeldForInvestor("Investor 1").Should().Be(100);
        }
        public void FilterTransactionsByDateTest()
        {
            var factory = new TransactionFactory().WithDate(() => DateTime.Now);
            var transactionsFromToday       = factory.Build(3);
            var transactionsFromFiveDaysAgo = factory.WithDate(() => Faker.Date.Recent(5)).Build(3);
            var allTransactions             = new List <Transaction>();

            allTransactions.AddRange(transactionsFromToday);
            allTransactions.AddRange(transactionsFromFiveDaysAgo);

            var twoDaysAgo = DateTime.Now.Subtract(new TimeSpan(2, 0, 0, 0));
            var result     = new SalesReport(allTransactions).FilterTransactionsByDate(twoDaysAgo)
                             .Select(t => t.Date).Should().OnlyContain(d => d >= twoDaysAgo);
        }
        public void GetCashBalanceForFundByInvestorTest()
        {
            var factory = new TransactionFactory().WithInvestor(() => "Investor 1")
                          .WithFund(() => "Fund 1")
                          .WithPrice(() => 100)
                          .WithShares(() => 1)
                          .WithTransactionType(() => TransactionType.Sell);
            var transactions = factory.Build(3);

            transactions[0].TransactionType = TransactionType.Buy;

            new ProfitReport(transactions).GetCashBalanceForFundByInvestor("Fund 1", "Investor 1")
            .Should().Be(100);
        }
示例#10
0
        public void GetFundsWithNegativeShareBalanceForInvestorTest()
        {
            var factory = new TransactionFactory()
                          .WithFund(() => "Fund 1")
                          .WithInvestor(() => "Investor 1")
                          .WithShares(() => 100)
                          .WithTransactionType(() => TransactionType.Sell);
            var transactions = factory.Build(3);

            transactions.AddRange(
                factory.WithFund(() => "Fund 2").WithTransactionType(() => TransactionType.Buy).Build(3));
            new BreakReport(transactions).GetFundsWithNegativeShareBalanceForInvestor("Investor 1")
            .Should().NotContainKey("Fund 2")
            .And.ContainKey("Fund 1")
            .WhichValue.Should().Be(-300);
        }
        public void GetSellAmountsPerInvestorTest()
        {
            var factory = new TransactionFactory();
            var numberOfTransactions     = Faker.Random.Int(1, 100);
            var allTransactions          = factory.Build(numberOfTransactions);
            var transactionsForInvestor1 = factory
                                           .WithPrice(() => 100)
                                           .WithShares(() => 1)
                                           .WithTransactionType(() => TransactionType.Sell)
                                           .WithInvestor(() => "Investor 1")
                                           .WithTransactionType(() => TransactionType.Sell)
                                           .Build(numberOfTransactions);

            allTransactions.AddRange(transactionsForInvestor1);
            var result = new SalesReport().GetSellAmountForInvestor("Investor 1", allTransactions);

            result.Should().Be(numberOfTransactions * 100);
        }
        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);
        }