Пример #1
0
 public void ShouldBeAbleToCreateAndAddInvestmentToPortfolio()
 {
     var investor = new Investor(new Name("Inverstor1"), new Amount(1000));
     var portfolio = new Portfolio();
     portfolio.AddInvestment(new Investment(investor, null, new Amount(500)));
     Assert.AreEqual(new Amount(500), portfolio.Value);
 }
Пример #2
0
 public void ShouldBeAbleToTellIfInvestorAlreadyInvested()
 {
     var investor = new Investor(new Name("investor"), new Amount(50000));
     var subscription = new Subscription();
     subscription.Add(new Offer(investor, new Amount(500), null));
     Assert.IsTrue(subscription.AlreadyInvested(investor));
 }
Пример #3
0
 public void Should_Be_Able_To_Create_And_Add_Investment_To_Portfolio()
 {
     Investor investor = new Investor(new Name("Inverstor1"), new GringottsDate(DateTime.Now), new Amount(1000));
     Portfolio portfolio = new Portfolio();
     portfolio.AddInvestment(new Investment(investor, null, new Amount(500)));
     Assert.AreEqual(new Amount(500), portfolio.Value);
 }
Пример #4
0
 public void Portfolio_Should_Increase_To_The_Extent_Of_The_Offer()
 {
     Investor investor = new Investor(new Name("Inverstor1"), new GringottsDate(DateTime.Now), new Amount(1000));
     Venture venture = new Venture(new Name("venture1"), new Amount(1000), new Amount(500));
     venture.AddOffer(investor, new Amount(600));
     Assert.AreEqual(new Amount(600), investor.OfferValue);
 }
Пример #5
0
 public void PortfolioShouldIncreaseToTheExtentOfTheOffer()
 {
     var investor = new Investor(new Name("Inverstor1"), new Amount(1000));
     var venture = new Venture(new Name("venture1"), new Amount(1000), new Amount(500));
     venture.AddOffer(investor, new Amount(600));
     Assert.AreEqual(new Amount(600), investor.OfferValue);
 }
Пример #6
0
 public void Should_Allow_Investor_To_Invest_Only_Once()
 {
     Venture venture = new Venture(new Name("Ventura"), new Amount(100), new Amount(1));
     Investor investor = new Investor(new Name("investor"), new GringottsDate(DateTime.Now), new Amount(50000));
     Investor duplicateInvestor = new Investor(new Name("investor"), new GringottsDate(DateTime.Now), new Amount(500));
     venture.AddOffer(investor, new Amount(2));
     Assert.Throws<InvalidOfferException>(() => venture.AddOffer(duplicateInvestor, new Amount(2)));
 }
Пример #7
0
 public void Should_Be_Able_To_Tell_If_Investor_Already_Invested()
 {
     Investor investor = new Investor(new Name("investor"), new GringottsDate(DateTime.Now), new Amount(50000));
     Venture venture = new Venture(new Name("Ventura"), new Amount(100), new Amount(1));
     Subscription subscription = new Subscription();
     subscription.Add(new Offer(investor, new Amount(500), null));
     Assert.IsTrue(subscription.AlreadyInvested(investor));
 }
Пример #8
0
 public void Corpus_Decreases_To_The_Extent_Of_The_Offer()
 {
     Investor investor = new Investor(new Name("Inverstor1"), new GringottsDate(DateTime.Now), new Amount(1000));
     Venture venture = new Venture(new Name("venture1"), new Amount(1000), new Amount(500));
     Offer offer = venture.AddOffer(investor, new Amount(600));
     Assert.NotNull(offer);
     Assert.AreEqual(new Amount(400), investor.Corpus);
 }
Пример #9
0
 public void ShouldAllowInvestorToInvestOnlyOnce()
 {
     var venture = new Venture(new Name("Ventura"), new Amount(100), new Amount(1));
     var investor = new Investor(new Name("investor"),  new Amount(50000));
     var duplicateInvestor = new Investor(new Name("investor"),  new Amount(500));
     venture.AddOffer(investor, new Amount(2));
     Assert.Throws<InvalidOfferException>(() => venture.AddOffer(duplicateInvestor, new Amount(2)));
 }
Пример #10
0
 public void CorpusDecreasesToTheExtentOfTheOffer()
 {
     var investor = new Investor(new Name("Inverstor1"), new Amount(1000));
     var venture = new Venture(new Name("venture1"), new Amount(1000), new Amount(500));
     Offer offer = venture.AddOffer(investor, new Amount(600));
     Assert.NotNull(offer);
     Assert.AreEqual(new Amount(400), investor.Balance);
 }
Пример #11
0
 public void HoldingShouldBeCreatedWhenVentureStarts()
 {
     var venture = new Venture(new Name("Ventura"), new Amount(100), new Amount(1));
     var investor0 = new Investor(new Name("Investor0"),  new Amount(100));
     var investor1 = new Investor(new Name("Investor1"),  new Amount(100));
     venture.AddOffer(investor0, new Amount(50));
     venture.AddOffer(investor1, new Amount(50));
     venture.Start();
     Assert.Greater(venture.Holding.Investments.Count, 0);
 }
Пример #12
0
 public void Holding_Should_Be_Created_When_Venture_Starts()
 {
     Venture venture = new Venture(new Name("Ventura"), new Amount(100), new Amount(1));
     Investor investor0 = new Investor(new Name("Investor0"), new GringottsDate(DateTime.Now), new Amount(100));
     Investor investor1 = new Investor(new Name("Investor1"), new GringottsDate(DateTime.Now), new Amount(100));
     venture.AddOffer(investor0, new Amount(50));
     venture.AddOffer(investor1, new Amount(50));
     venture.Start();
     Assert.Greater(venture.Holding.Investments.Count, 0);
 }
Пример #13
0
        public void Should_Be_Able_To_Give_Returns()
        {
            Amount corpus = new Amount(1000);
            Amount offer = new Amount(250);
            Amount dividend = new Amount(50);
            Investor investor = new Investor(new Name("Dummy"), new GringottsDate(DateTime.Now), corpus);

            Investment investment = new Investment(investor, null, offer);
            investment.GiveReturn(dividend);
            Assert.AreEqual(corpus + dividend, investor.Corpus);
        }
Пример #14
0
 public virtual Offer AddOffer(Investor investor, Amount investedAmount)
 {
     if (Subscription.AlreadyInvested(investor))
         throw new InvalidOfferException("Cannot invest more than once.");
     if (!MinimumInvestment(investedAmount))
         throw new InvalidOfferException("Investment amount less than the required minimum amount.");
     Offer offer = new Offer(investor, investedAmount, null);
     investor.AcceptOffer(offer);
     Subscription.Add(offer);
     return offer;
 }
Пример #15
0
        public void ShouldBeAbleToSaveInvestor()
        {
            string name = "Investor 1";
            DateTime date = DateTime.Today;
            int amount = 100;

            Investor investor = new Investor(new Name(name),  new Amount(amount));

            InvestorRepository investorRepository = new InvestorRepository(session);
            string newId = investorRepository.Save(investor);

            Investor newInvestor = investorRepository.GetInvestorById(newId);
            Assert.AreEqual(new Name(name), newInvestor.Name);
        }
Пример #16
0
        public void ShouldNotBeAbleToSplitANonStartedVenture()
        {
            var outlay = new Amount(40);
            var venture = new Venture(new Name("Ventura"), outlay, new Amount(1));
            var investor0 = new Investor(new Name("Investor0"), new Amount(100));
            venture.AddOffer(investor0, new Amount(50));

            var firstVentureName = new Name("new-venture-1");
            var secondVentureName = new Name("new-venture-2");
            var percentage = new Percentage(0.2f);
            var terms = new TermsOfSplit(percentage, firstVentureName, secondVentureName);

            Assert.Throws<Exception>(()=>venture.Split(terms));
        }
Пример #17
0
        public void Should_Be_Able_To_Save_Investor()
        {
            string name = "Investor 1";
            DateTime date = DateTime.Today;
            int amount = 100;

            Investor investor = new Investor(new Name(name), new GringottsDate(date), new Amount(amount));

            InvestorRepository investorRepository = new InvestorRepository();
            investorRepository.Session = session;
            int newId = investorRepository.Save(investor);

            Investor newInvestor = investorRepository.GetInvestorById(newId);
            Assert.AreEqual(new Name(name), newInvestor.Name);
        }
Пример #18
0
        public void ShouldCloseTheVentureWhenAVentureSplits()
        {
            var outlay = new Amount(40);
            var venture = new Venture(new Name("Ventura"), outlay, new Amount(1));
            var investor0 = new Investor(new Name("Investor0"), new Amount(100));
            venture.AddOffer(investor0, new Amount(50));
            venture.Start();
            var firstVentureName = new Name("new-venture-1");
            var secondVentureName = new Name("new-venture-2");
            var percentage = new Percentage(0.2f);

            var terms = new TermsOfSplit(percentage, firstVentureName, secondVentureName);
            venture.Split(terms);

            Assert.IsTrue(venture.IsClosed());
        }
Пример #19
0
 public void Should_Be_Able_To_Confirm_Subscription()
 {
     Subscription subscription = new Subscription();
     Investor investor0 = new Investor(new Name("Investor0"), new GringottsDate(DateTime.Now), new Amount(100));
     Investor investor1 = new Investor(new Name("Investor1"), new GringottsDate(DateTime.Now), new Amount(100));
     Investor investor2 = new Investor(new Name("Investor2"), new GringottsDate(DateTime.Now), new Amount(100));
     Investor investor3 = new Investor(new Name("Investor3"), new GringottsDate(DateTime.Now), new Amount(100));
     subscription.Add(new Offer(investor0, new Amount(100), null));
     subscription.Add(new Offer(investor1, new Amount(200), null));
     subscription.Add(new Offer(investor2, new Amount(300), null));
     Offer excess = new Offer(investor3, new Amount(400), null);
     subscription.Add(excess);
     Amount outlay = new Amount(600);
     List<Investment> confirmations = subscription.Confirm(outlay);
     Assert.IsFalse(confirmations.Contains(excess.ToInvestment()));
     Assert.AreEqual(outlay, confirmations.Aggregate(new Amount(0), (sum, inv) => sum + inv.Value));
 }
Пример #20
0
        public void ShouldCreateABalanceEventWhenVentureBankruptcyIsNotified()
        {
            var investor = new Investor(new Name("Inverstor1"), new Amount(1100));
            var venture = new Venture(new Name("Hacker's Venture"), new Amount(500), new Amount(500));
            Offer offer = venture.AddOffer(investor, new Amount(500));
            Investment investment = offer.ToInvestment();

            venture.Start();

            investor.NotifyVentureBankruptcy(investment);

            BalanceHistory history = investor.GetBalanceHistory();
            String offerEvent = String.Format(BalanceEvent.VENTURE_BANKRUPT, "Hacker's Venture");

            BalanceEvent expectedBalanceEvent = new BalanceEvent(offerEvent, new Amount(600));

            Assert.Contains(expectedBalanceEvent, history.GetEvents());
        }
        public void Should_Persist()
        {
            Investor investor = new Investor(new Name("Investor 1"), new GringottsDate(DateTime.Today), new Amount(100));
            InvestorRepository investorRepository = new InvestorRepository();
            investorRepository.Session = session;
            investorRepository.Save(investor);

            Venture venture = new Venture(new Name("Ventura"), new Amount(100), new Amount(1));
            VentureRepository ventureRepository = new VentureRepository(session);
            ventureRepository.Save(venture);

            Investment investment = new Investment(investor, venture, new Amount(10));
            InvestmentRepository investmentRepository = new InvestmentRepository(session);
            investmentRepository.Save(investment);

            IList<Investment> investments = investmentRepository.FetchAll();
            Assert.Greater(investments.Count, 0);
        }
        public void VerifyCascadeSaveOfBalanceEventViaInvestor()
        {
            Investor investor = new Investor(new Name("dude"), new Amount(1000));
            BalanceHistory balanceHistory = investor.GetBalanceHistory();

            var venture = new Venture(new Name("Hacker's Venture"), new Amount(500), new Amount(500));
            var offerAmount = new Amount(500);
            venture.AddOffer(investor, offerAmount);
            var testBalanceEvent = new BalanceEvent(string.Format(BalanceEvent.OFFER_ACCEPTED,venture.Name), offerAmount);

            InvestorRepository investorRepository = new InvestorRepository(session);
            investorRepository.Save(investor);
            session.Evict(investor);

            IQuery query = session.CreateQuery("from BalanceEvent");
            IList<BalanceEvent> savedBalanceEvents = query.List<BalanceEvent>();
            Assert.IsTrue(savedBalanceEvents.Contains(testBalanceEvent));
        }
Пример #23
0
 public void ShouldCreateAOfferAcceptedBalanceEventWhenInvestorMakesAnOffer()
 {
     var investor = new Investor(new Name("Inverstor1"), new Amount(1000));
     var venture = new Venture(new Name("ventura!"), new Amount(1000), new Amount(500));
     Offer offer = venture.AddOffer(investor, new Amount(600));
     Assert.AreEqual(new Amount(400), investor.Balance);
     BalanceHistory history = investor.GetBalanceHistory();
     string offerEvent = string.Format(BalanceEvent.OFFER_ACCEPTED, offer.VentureName);
     BalanceEvent balanceEvent = new BalanceEvent(offerEvent, new Amount(400));
     Assert.Contains(balanceEvent, history.GetEvents());
 }
Пример #24
0
 public void ShouldBeAbleToAcceptCreditSurplus()
 {
     var investor = new Investor(new Name("Inverstor1"), new Amount(1000));
     investor.PartialRefundOnOffer(new Amount(50));
     Assert.AreEqual(new Amount(1050), investor.Balance);
 }
Пример #25
0
 public string Save(Investor newInvestor)
 {
     return (string)session.Save(newInvestor);
 }
Пример #26
0
 public void ShouldBeAbleToAcceptInvestment()
 {
     var investor = new Investor(new Name("Inverstor1"), new Amount(1000));
     investor.AddInvestmentToPortfolio(new Investment(investor, null, new Amount(600)));
     Assert.AreEqual(new Amount(600), investor.PortfolioValue);
 }
Пример #27
0
 public void ShouldBeAbleToAcceptOffer()
 {
     var investor = new Investor(new Name("Inverstor1"), new Amount(1000));
     var venture = new Venture(new Name("venture1"), new Amount(1000), new Amount(500));
     investor.AcceptOffer(new Offer(investor, new Amount(600), venture));
 }
Пример #28
0
 public void ShouldCreateAInvestorCreatedBalanceEventWhenInvestorIsCreated()
 {
     Amount amount = new Amount(100);
     var investor = new Investor(new Name("Investor"), amount);
     BalanceHistory history = investor.GetBalanceHistory();
     BalanceEvent balanceEvent = new BalanceEvent(BalanceEvent.INVESTOR_CREATED, amount);
     Assert.Contains(balanceEvent, history.GetEvents());
 }
Пример #29
0
 public bool AlreadyInvested(Investor investor)
 {
     return subscription.Any(investment => investment.HasInvestor(investor));
 }
Пример #30
0
        public void ShouldCreateDividendReceivedEventWhenDividendIsDeclared()
        {
            var initialBalance = new Amount(1000);
            var investor1 = new Investor(new Name("Inverstor 1"), initialBalance);

            var outlay = new Amount(400);
            var venture = new Venture(new Name("Ventura Inc."), outlay, new Amount(1));

            venture.AddOffer(investor1, outlay);

            venture.Start();
            var dividend = new Amount(1000);
            venture.HandOutDividends(dividend);

            BalanceHistory history = investor1.GetBalanceHistory();
            string dividendEvent = string.Format(BalanceEvent.DIVIDEND_RECEIVED, venture.Name);
            BalanceEvent balanceEvent = new BalanceEvent(dividendEvent, initialBalance - outlay + dividend);
            Assert.Contains(balanceEvent, history.GetEvents());
        }