public void ShouldFetchMultipleOffersForInvestor() { Investor investor = CreateInvestor("Jagan1", 5000); InvestorRepository investorRepository = new InvestorRepository(session); investorRepository.Save(investor); Venture venture1 = CreateVenture(3000, 500, "Ram1"); Venture venture2 = CreateVenture(6000, 1000, "Ram2"); VentureRepository ventureRepository = new VentureRepository(session); ventureRepository.Save(venture1); ventureRepository.Save(venture2); Amount amount1 = new Amount(700); Amount amount2 = new Amount(800); Offer offer1 = new Offer(investor, amount1, venture1); Offer offer2 = new Offer(investor, amount2, venture2); OfferRepository offerRepository = new OfferRepository(session); offerRepository.Save(offer1); offerRepository.Save(offer2); session.Flush(); session.Clear(); Investor fetchedInvestor = investorRepository.GetInvestorById(investor.Id); Assert.AreEqual(new Amount(1500), fetchedInvestor.OfferValue); }
public void Should_Be_Able_To_Add() { Amount amount = new Amount(500); Amount another = new Amount(400); amount += another; Assert.AreEqual(new Amount(900), amount); }
public void Should_Be_Able_To_Divide() { Amount amount = new Amount(500); Amount another = new Amount(400); amount = amount / another; Assert.AreEqual(new Amount((decimal) 500/400), amount); }
public void Should_Be_Able_To_Subtract() { Amount amount = new Amount(500); Amount another = new Amount(400); amount -= another; Assert.AreEqual(new Amount(100), amount); }
public void Should_Be_Able_To_Multiply() { Amount amount = new Amount(500); Amount another = new Amount(400); amount = amount * another; Assert.AreEqual(new Amount((decimal)500 * 400), amount); }
public void DistributeDividends(Amount amount) { Dictionary<Investment, Amount> participation = CalculateParticipation(); foreach (var participant in participation) { participant.Key.GiveReturn(participant.Key.Venture, participant.Value * amount); } }
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()); }
public void Should_Be_Able_To_Distribute_Dividends_Fairly() { Amount profit = new Amount(1000); Holding holding = new Holding(); holding.Add(new Investment(new Investor(new Name("quarter"), new GringottsDate(DateTime.Now), new Amount(1500)), null, new Amount(250))); holding.Add(new Investment(new Investor(new Name("threeFourths"), new GringottsDate(DateTime.Now), new Amount(1000)), null, new Amount(750))); holding.DistributeDividends(profit); }
private Venture(Name name, Amount outlay) { this.name = name; Outlay = outlay; MinInvestment = new Amount(0); Subscription = new Subscription(); holding = new Holding(); }
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; }
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()); }
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); }
public Venture(Name name, Amount outlay, Amount minInvestment) : this(name, outlay) { if (minInvestment <= new Amount(0)) throw new Exception("Minimum investment must be greater than 0"); if (outlay < minInvestment) throw new Exception("Outlay must be greater than minimum investment"); MinInvestment = minInvestment; State = PROPOSED_STATE; AddEventToVentureHistory(VentureEvent.PROPOSED); }
//public static readonly string[] STATES = new string[] { PROPOSED_STATE, STARTED_STATE, CANCELLED_STATE, CLOSED_STATE }; public Venture(Name name, Amount outlay, Amount minInvestment) { if (minInvestment <= new Amount(0)) throw new Exception("Minimum investment must be greater than 0"); if (outlay < minInvestment) throw new Exception("Outlay must be greater than minimum investment"); Name = name; Outlay = outlay; MinInvestment = minInvestment; Subscription = new Subscription(); State = PROPOSED_STATE; holding = new Holding(); }
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()); }
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); }
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 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)); }
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 List<Investment> Confirm(Amount outlay) { var sortedInvestments = subscription.OrderBy(inv => inv.Value); Amount difference = outlay; List<Investment> finalSubscription = new List<Investment>(); Amount zero = new Amount(0); foreach(Offer offer in sortedInvestments) { Investment investment = offer.ToInvestment(); finalSubscription.Add(investment); difference -= offer.Value; if (difference <= zero) { investment.Value += difference; investment.CreditSurplus(difference.Abs()); break; } } return finalSubscription; }
public void ShouldFetchMultipleSubscriptionsForVenture() { Investor investor1 = CreateInvestor("Joy", 9000); Investor investor2 = CreateInvestor("Roy", 6000); InvestorRepository investorRepository = new InvestorRepository(session); investorRepository.Save(investor1); investorRepository.Save(investor2); Venture venture = CreateVenture(8000, 1920, "Ace Ventura"); VentureRepository ventureRepository = new VentureRepository(session); ventureRepository.Save(venture); Amount amount1 = new Amount(712); Amount amount2 = new Amount(423); Offer offer1 = new Offer(investor1, amount1, venture); Offer offer2 = new Offer(investor2, amount2, venture); OfferRepository offerRepository = new OfferRepository(session); offerRepository.Save(offer1); offerRepository.Save(offer2); session.Flush(); session.Clear(); Venture fetchedVenture = ventureRepository.GetVentureById(venture.Id); Assert.AreEqual(new Amount(1135), fetchedVenture.SubscribedAmount()); }
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 CanCreateInvestor() { var amount = new Amount(10); var investor = new Investor(new Name("Investor 1"), amount); Assert.AreEqual(amount, investor.Balance); }
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 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()); }
private bool MinimumInvestment(Amount investedAmount) { return investedAmount >= MinInvestment; }
public virtual void HandOutDividends(Amount dividend) { if (!IsStarted()) throw new InvalidOperationException("Cannot hand out dividends for an un-started venture"); holding.DistributeDividends(dividend); }
public VentureEvent(string eventType, Amount outlay) { EventType = eventType; Outlay = outlay; }
public void ShouldFetchOffersForInvestorAndVenture() { Investor investor = CreateInvestor("Jagan", 4000); InvestorRepository investorRepository = new InvestorRepository(session); investorRepository.Save(investor); Venture venture = CreateVenture(2000, 400, "Ram Capitalists"); VentureRepository ventureRepository = new VentureRepository(session); ventureRepository.Save(venture); Amount amount = new Amount(600); Offer offer = new Offer(investor, amount, venture); OfferRepository offerRepository = new OfferRepository(session); offerRepository.Save(offer); session.Flush(); session.Evict(investor); session.Evict(venture); session.Evict(offer); Investor fetchedInvestor = investorRepository.GetInvestorById(investor.Id); Assert.AreEqual(amount, fetchedInvestor.OfferValue); Venture fetchedVenture = ventureRepository.GetVentureById(venture.Id); Assert.AreEqual(amount, fetchedVenture.SubscribedAmount()); }