Beispiel #1
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);
 }
Beispiel #2
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);
 }
Beispiel #3
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);
 }
Beispiel #4
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));
 }
Beispiel #5
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);
 }
Beispiel #6
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)));
 }
Beispiel #7
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)));
 }
Beispiel #8
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);
 }
Beispiel #9
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);
 }
Beispiel #10
0
 public void ShouldCreateTwoVenturesOnSplit()
 {
     var venture = new Venture(new Name("venture-name"), new Amount(100), new Amount(10));
     var firstVentureName = new Name("new-venture-1");
     var secondVentureName = new Name("new-venture-2");
     var terms = new TermsOfSplit(new Percentage(0.8f), firstVentureName, secondVentureName);
     venture.AddOffer(new Investor(new Name("testName"), new Amount(1000)), new Amount(100));
     venture.Start();
     var ventures = venture.Split(terms);
     Assert.AreEqual(2, ventures.Count());
 }
Beispiel #11
0
 public void ShouldBeAbleToCreateAVenture()
 {
     var nameOfVenture = new Name("Ventura");
     var outlay = new Amount(100);
     var minInvestment = new Amount(1);
     var venture = new Venture(nameOfVenture, outlay, minInvestment);
     Assert.AreEqual(nameOfVenture.GetValue(), venture.Name);
     Assert.AreEqual(outlay, venture.Outlay);
     Assert.AreEqual(minInvestment, venture.MinInvestment);
     Assert.True(venture.IsProposed());
 }
Beispiel #12
0
 public void ShouldCreateVenturesWithPassedNames()
 {
     var venture = new Venture(new Name("venture-name"), new Amount(100), new Amount(10));
     var firstVentureName = new Name("new-venture-1");
     var secondVentureName = new Name("new-venture-2");
     var terms = new TermsOfSplit(new Percentage(0.8f), firstVentureName, secondVentureName);
     venture.AddOffer(new Investor(new Name("testName"), new Amount(1000)), new Amount(100));
     venture.Start();
     var ventures = venture.Split(terms);
     Assert.AreEqual(firstVentureName.GetValue(), ventures.First().Name);
     Assert.AreEqual(secondVentureName.GetValue(), ventures.Last().Name);
 }
        public void Should_Be_Able_To_Save_And_Load_A_Venture()
        {
            Name nameOfVenture = new Name("Ventura");
            Amount outlay = new Amount(100);
            Amount minInvestment = new Amount(1);
            Venture venture = new Venture(nameOfVenture, outlay, minInvestment);
            VentureRepository ventureRepository = new VentureRepository(session);

            ventureRepository.Save(venture);
            IList<Venture> ventures = ventureRepository.FetchAll();

            Assert.AreEqual(venture, ventures.First());
        }
Beispiel #14
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));
        }
        public void ShouldBeAbleToSaveAndLoadAVenture()
        {
            Name nameOfVenture = new Name("Ventura");
            Amount outlay = new Amount(100);
            Amount minInvestment = new Amount(1);
            Venture venture = new Venture(nameOfVenture, outlay, minInvestment);
            VentureRepository ventureRepository = new VentureRepository(session);

            ventureRepository.Save(venture);
            session.Flush();
            session.Evict(venture);

            IList<Venture> ventures = ventureRepository.FetchAll();

            Assert.Contains(venture, ventures as ICollection);
        }
Beispiel #16
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());
        }
        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));
        }
Beispiel #18
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);
        }
Beispiel #20
0
 public void Save(Venture venture)
 {
     session.Save(venture);
 }
Beispiel #21
0
        public virtual IEnumerable<Venture> Split(TermsOfSplit termsOfSplit)
        {
            if(!IsStarted()){
                throw new Exception("Cannot split a venture that is not started.");
            }
            // Splitting of OutLay
            var aVentures = new List<Venture>();
            var aFirstVenture = new Venture(termsOfSplit.FirstVentureName,termsOfSplit.Ratio.Apply(Outlay));
            var aSecondVenture = new Venture(termsOfSplit.SecondVentureName, termsOfSplit.Ratio.ApplyRemaining(Outlay));

            // Splitting of Holding's Investments
            var holdings = Holding.Split(termsOfSplit.Ratio);
            aFirstVenture.holding = holdings[0];
            aSecondVenture.holding = holdings[1];

            AddEventToVentureHistory(VentureEvent.SPLIT);
            CloseTheVenture();

            aFirstVenture.AddEventToVentureHistory(VentureEvent.SPLIT);
            aSecondVenture.AddEventToVentureHistory(VentureEvent.SPLIT);
            aFirstVenture.ChangeStateToStarted();
            aSecondVenture.ChangeStateToStarted();

            aVentures.Add(aFirstVenture);
            aVentures.Add(aSecondVenture);
            return aVentures;
        }
Beispiel #22
0
 public virtual bool Equals(Venture other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Id, Id) && Equals(other.Name, Name);
 }
Beispiel #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());
 }
Beispiel #24
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));
 }
Beispiel #25
0
        public void ShouldUpdateThePortfolioOfTheInvestorWhenVentureCloses()
        {
            var outlay = new Amount(50);
            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);
            var ventures = venture.Split(terms);

               Assert.IsFalse(investor0.HasInvestmentIn(venture));
               Assert.IsTrue(investor0.HasInvestmentIn(ventures.First()));
               Assert.IsTrue(investor0.HasInvestmentIn(ventures.Last()));
        }
Beispiel #26
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());
        }
Beispiel #27
0
        public void ShouldCreateAOfferRejectedEventWhenVentureRejectsAnOffer()
        {
            var initialBalance = new Amount(1000);
            var investor1 = new Investor(new Name("Inverstor 1"), initialBalance);
            var investor2 = new Investor(new Name("Inverstor 2"), initialBalance);

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

            venture.AddOffer(investor1, outlay);
            var offerAmount2 = new Amount(600);
            venture.AddOffer(investor2, offerAmount2);

            venture.Start();

            BalanceHistory history = investor2.GetBalanceHistory();
            string offerEvent = string.Format(BalanceEvent.OFFER_REJECTED, venture.Name);
            BalanceEvent balanceEvent = new BalanceEvent(offerEvent, initialBalance);
            Assert.Contains(balanceEvent, history.GetEvents());
        }
Beispiel #28
0
        public void ShouldSplitHoldingInvestmentsAccordingToRatio()
        {
            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);
            var ventures = venture.Split(terms);
            Assert.AreEqual(venture.HoldingValue.Denomination, ventures.Sum(n => n.HoldingValue.Denomination));
        }
Beispiel #29
0
 public bool HasInvestmentIn(Venture venture)
 {
     IEnumerable<Investment> commonInvestments = investments.Intersect(venture.Holding.Investments);
     if (commonInvestments.Count() > 0) return true;
     return false;
 }
Beispiel #30
0
        public void ShouldCreateAOfferPartiallyAcceptedEventWhenOffersAreConfirmed()
        {
            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));

            var excess = new Amount(100);
            venture.AddOffer(investor1, outlay + excess);
            Assert.AreEqual(initialBalance - (outlay + excess), investor1.Balance);

            venture.Start();

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