public AddOffer ( |
||
investor | ||
investedAmount | ||
return |
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))); }
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))); }
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); }
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); }
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); }
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); }
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); }
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); }
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()); }
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 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 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)); }
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 ShouldAcceptInvestment() { var venture = new Venture(new Name("Venture"), new Amount(1000000), new Amount(23538)); var investor = new Investor(new Name("investor"), new Amount(50000)); Assert.DoesNotThrow(() => venture.AddOffer(investor, new Amount(30000))); }
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()); }
public void ShouldNotTakeMoreInvestmentThanOutlay() { 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(); // TODO: make aggregation in venture Assert.AreEqual(outlay, venture.Holding.Investments.Aggregate(new Amount(0), (sum, inv) => sum + inv.Value)); }
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()); }
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()); }
public void ShouldReturnOverInvestmentToInvestorWhenStart() { var outlay = new Amount(40); var venture = new Venture(new Name("Ventura"), outlay, new Amount(1)); var initialCorpus = new Amount(100); var investor = new Investor(new Name("Investor0"), initialCorpus); venture.AddOffer(investor, new Amount(50)); venture.Start(); Assert.AreEqual(initialCorpus - outlay, investor.Balance); }
public void VentureNotInStartedStateWillNotGoBankrupt() { var outlay = new Amount(40); var venture = new Venture(new Name("Ventura"), outlay, new Amount(1)); var initialCorpus = new Amount(100); var investor = new Investor(new Name("Investor0"), initialCorpus); venture.AddOffer(investor, new Amount(50)); Assert.Throws<InvalidOperationException>(venture.GoBankrupt); }
public void ShouldUpdateInvestorPortfolioWhenVentureGoesBankrupt() { var outlay = new Amount(50); var venture = new Venture(new Name("Ventura"), outlay, new Amount(1)); var initialCorpus = new Amount(100); var investor = new Investor(new Name("Investor0"), initialCorpus); var investmentAmount = new Amount(50); venture.AddOffer(investor, investmentAmount); venture.Start(); var previousAmount = investor.PortfolioValue; venture.GoBankrupt(); var currentAmount = investor.PortfolioValue; Assert.AreEqual(previousAmount-investmentAmount, currentAmount); }
public void ShouldUpdateInvestorBalancesWhileStartingAVenture() { var outlay = new Amount(600); var venture = new Venture(new Name("Ventura"), outlay, new Amount(1)); var initialBalance = new Amount(1000); var investor1 = new Investor(new Name("Investor1"), initialBalance); var investor2 = new Investor(new Name("Investor2"), initialBalance); var investor3 = new Investor(new Name("Investor3"), initialBalance); var investor4 = new Investor(new Name("Investor4"), initialBalance); var offerAmount1 = new Amount(100); venture.AddOffer(investor1, offerAmount1); Assert.AreEqual(initialBalance - offerAmount1, investor1.Balance); var offerAmount2 = new Amount(200); venture.AddOffer(investor2, offerAmount2); Assert.AreEqual(initialBalance - offerAmount2, investor2.Balance); var offerAmount3 = new Amount(400); venture.AddOffer(investor3, offerAmount3); Assert.AreEqual(initialBalance - offerAmount3, investor3.Balance); var offerAmount4 = new Amount(500); venture.AddOffer(investor4, offerAmount4); Assert.AreEqual(initialBalance - offerAmount4, investor4.Balance); venture.Start(); // check the new balances Assert.AreEqual(initialBalance - offerAmount1, investor1.Balance); Assert.AreEqual(initialBalance - offerAmount2, investor2.Balance); Assert.AreEqual(initialBalance - offerAmount3 + new Amount(100), investor3.Balance, "Partially accepted amount should have been refunded"); Assert.AreEqual(initialBalance, investor4.Balance); }
public void ShouldAcceptInvestmentOnlyIfGreaterThanMinimumAmount() { var venture = new Venture(new Name("Venture"), new Amount(1000000), new Amount(23538)); var investor = new Investor(new Name("investor"), new Amount(50000)); Assert.Throws<InvalidOfferException>(() => venture.AddOffer(investor, new Amount(3000))); }
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())); }
public void StartedVentureMayGoBankrupt() { var outlay = new Amount(40); var venture = new Venture(new Name("Ventura"), outlay, new Amount(1)); var initialCorpus = new Amount(100); var investor = new Investor(new Name("Investor0"), initialCorpus); venture.AddOffer(investor, new Amount(50)); venture.Start(); venture.GoBankrupt(); Assert.AreEqual(Venture.BANKRUPT_STATE, venture.State); }
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()); }
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)); }
public void ShouldSplitOutlayMoneyAccordingToRatio() { 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 percentage = new Percentage(0.2f); var terms = new TermsOfSplit(percentage, firstVentureName, secondVentureName); venture.AddOffer(new Investor(new Name("testName"), new Amount(1000)), new Amount(100)); venture.Start(); var ventures = venture.Split(terms); Assert.AreEqual(percentage.Apply(venture.Outlay), ventures.First().Outlay); Assert.AreEqual(percentage.ApplyRemaining(venture.Outlay), ventures.Last().Outlay); }
public void ShouldBeAbleToHandOutDividends() { var venture = new Venture(new Name("Venture"), new Amount(1000), new Amount(1)); var quarterInvestor = new Investor(new Name("investor"), new Amount(1000)); var threeFourthsInvestor = new Investor(new Name("investor"), new Amount(1000)); var dividend = new Amount(1000); venture.AddOffer(quarterInvestor, new Amount(250)); venture.AddOffer(threeFourthsInvestor, new Amount(750)); venture.Start(); venture.HandOutDividends(dividend); }