Beispiel #1
0
 private Holding GetSplittedHolding(Percentage percentage)
 {
     var aHolding = new Holding();
     foreach (var investment in Investments)
     {
         Investment inv = new Investment(investment.Investor, percentage.Apply(investment.Value));
         aHolding.Add(inv);
         inv.Investor.AddInvestmentToPortfolio(inv);
     }
     return aHolding;
 }
Beispiel #2
0
        public IList<Holding> Split(Percentage percentage)
        {
            IList<Holding> holdings = new List<Holding>();
            Holding aHolding = GetSplittedHolding(percentage);
            var aSecondHolding = GetSplittedHolding(percentage.RemainingPercentage);

            holdings.Add(aHolding);
            holdings.Add(aSecondHolding);

            return holdings;
        }
Beispiel #3
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());
        }
Beispiel #4
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 #5
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));
        }
Beispiel #6
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 #7
0
 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);
 }
Beispiel #8
0
 public void ShouldBeAbleToApplyRemainingPercentage()
 {
     var percentage = new Percentage(0.4f);
     Assert.AreEqual(new Amount(60.0f).Denomination, percentage.ApplyRemaining(new Amount(100)).Denomination,0.1f);
 }
Beispiel #9
0
 public void ShouldBeAbleToApplyPercentage()
 {
     var percentage = new Percentage(0.4f);
     Assert.AreEqual(new Amount(40.0f), percentage.Apply(new Amount(100)));
 }
Beispiel #10
0
        public void ShouldCreateVentureEventWhenVentureSplits()
        {
            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 newVentures = venture.Split(terms);

            Assert.IsTrue(newVentures.First().IsStarted());
            Assert.IsTrue(newVentures.Last().IsStarted());

            VentureEvent ventureEventSplit1 = new VentureEvent(VentureEvent.SPLIT,new Amount(8));
            VentureEvent ventureEventStarted1 = new VentureEvent(VentureEvent.STARTED,new Amount(8));
            VentureEvent ventureEventSplit2 = new VentureEvent(VentureEvent.SPLIT,new Amount(32));
            VentureEvent ventureEventStarted2 = new VentureEvent(VentureEvent.STARTED,new Amount(32));

            VentureHistory ventureHistory1 = newVentures.First().GetVentureHistory();
            VentureHistory ventureHistory2 = newVentures.Last().GetVentureHistory();

            Assert.Contains(ventureEventSplit1, ventureHistory1.GetEvents());
            Assert.Contains(ventureEventStarted1, ventureHistory1.GetEvents());

            Assert.Contains(ventureEventSplit2, ventureHistory2.GetEvents());
            Assert.Contains(ventureEventStarted2, ventureHistory2.GetEvents());
        }
Beispiel #11
0
 public TermsOfSplit(Percentage ratio, Name firstVentureName, Name secondVentureName)
 {
     Ratio = ratio;
     FirstVentureName = firstVentureName;
     SecondVentureName = secondVentureName;
 }
Beispiel #12
0
 public bool Equals(Percentage other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Ratio == Ratio;
 }