private CorporateAction CorporateActionFromEvent(CompositeActionAddedEvent @event) { var childActions = @event.ChildActions.Select(x => CorporateActionFromEvent(x)); var compositeAction = new CompositeAction(@event.ActionId, Stock, @event.ActionDate, @event.Description, childActions); return(compositeAction); }
public void AddOneOfEachTypeOfChildAction() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); CompositeActionAddedEvent @event = null; var id = Guid.NewGuid(); var builder = new CompositeActionBuilder(stock, id, new Date(2000, 01, 01), "Test Composite Action", (x) => { @event = x; }); builder.AddSplitConsolidation("Test Split", 1, 2) .AddCapitalReturn("Test Capital Return", new Date(2000, 02, 01), 10.00m) .AddDividend("Test Dividend", new Date(2000, 02, 01), 1.20m, 1.00m, 2.50m) .Finish(); using (new AssertionScope()) { @event.Should().BeEquivalentTo( new { EntityId = stock.Id, Version = 1, ActionId = id, ActionDate = new Date(2000, 01, 01), Description = "Test Composite Action" }); @event.ChildActions.Should().SatisfyRespectively( first => first.Should().BeOfType <SplitConsolidationAddedEvent>(), second => second.Should().BeOfType <CapitalReturnAddedEvent>(), third => third.Should().BeOfType <DividendAddedEvent>() ); }; }
public void NoChildActions() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); CompositeActionAddedEvent @event = null; var id = Guid.NewGuid(); var builder = new CompositeActionBuilder(stock, id, new Date(2000, 01, 01), "Test Composite Action", (x) => { @event = x; }); builder.Finish(); using (new AssertionScope()) { @event.Should().BeEquivalentTo( new { EntityId = stock.Id, Version = 1, ActionId = id, ActionDate = new Date(2000, 01, 01), Description = "Test Composite Action" }); @event.ChildActions.Should().BeEmpty(); }; }
public CompositeActionBuilder(Stock stock, Guid id, Date recordDate, string description, Action <CompositeActionAddedEvent> callback) { _ChildEvents = new EventList(); _ChildActions = new CorporateActionList(stock, _ChildEvents); _Event = new CompositeActionAddedEvent(stock.Id, stock.Version, id, recordDate, description); _Callback = callback; }
public void AddMultipleOfTheSameTypeOfChildAction() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); CompositeActionAddedEvent @event = null; var id = Guid.NewGuid(); var builder = new CompositeActionBuilder(stock, id, new Date(2000, 01, 01), "Test Composite Action", (x) => { @event = x; }); builder.AddCapitalReturn("Test Capital Return 1", new Date(2000, 02, 01), 10.00m) .AddCapitalReturn("Test Capital Return 2", new Date(2000, 02, 01), 12.00m) .Finish(); using (new AssertionScope()) { @event.Should().BeEquivalentTo( new { EntityId = stock.Id, Version = 1, ActionId = id, ActionDate = new Date(2000, 01, 01), Description = "Test Composite Action" }); @event.ChildActions.Should().SatisfyRespectively( first => { first.Should().BeOfType <CapitalReturnAddedEvent>(); if (first is CapitalReturnAddedEvent capitalReturn) { capitalReturn.EntityId.Should().Be(stock.Id); capitalReturn.Version.Should().Be(1); capitalReturn.ActionDate.Should().Be(new Date(2000, 01, 01)); capitalReturn.Description.Should().Be("Test Capital Return 1"); capitalReturn.PaymentDate.Should().Be(new Date(2000, 02, 01)); capitalReturn.Amount.Should().Be(10.00m); } }, second => { second.Should().BeOfType <CapitalReturnAddedEvent>(); if (second is CapitalReturnAddedEvent capitalReturn) { capitalReturn.EntityId.Should().Be(stock.Id); capitalReturn.Version.Should().Be(1); capitalReturn.ActionDate.Should().Be(new Date(2000, 01, 01)); capitalReturn.Description.Should().Be("Test Capital Return 2"); capitalReturn.PaymentDate.Should().Be(new Date(2000, 02, 01)); capitalReturn.Amount.Should().Be(12.00m); } } ); }; }
public void AddTransformation() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); var stock2 = new Stock(Guid.NewGuid()); stock2.List("XYZ", "XYZ Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); CompositeActionAddedEvent @event = null; var id = Guid.NewGuid(); var builder = new CompositeActionBuilder(stock, id, new Date(2000, 01, 01), "Test Composite Action", (x) => { @event = x; }); var resultStocks = new Transformation.ResultingStock[] { new Transformation.ResultingStock(stock2.Id, 1, 2, 0.40m, new Date(2020, 02, 01)) }; builder.AddTransformation("Test Transformation", new Date(2000, 02, 01), 1.20m, false, resultStocks) .Finish(); using (new AssertionScope()) { @event.Should().BeEquivalentTo( new { EntityId = stock.Id, Version = 1, ActionId = id, ActionDate = new Date(2000, 01, 01), Description = "Test Composite Action" }); @event.ChildActions.Should().SatisfyRespectively( first => { first.Should().BeOfType <TransformationAddedEvent>(); if (first is TransformationAddedEvent transformation) { transformation.EntityId.Should().Be(stock.Id); transformation.Version.Should().Be(1); transformation.ActionDate.Should().Be(new Date(2000, 01, 01)); transformation.Description.Should().Be("Test Transformation"); transformation.ImplementationDate.Should().Be(new Date(2000, 02, 01)); transformation.CashComponent.Should().Be(1.20m); transformation.RolloverRefliefApplies.Should().BeFalse(); transformation.ResultingStocks.Should().HaveCount(1); } } ); }; }
public void AddDividend() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); CompositeActionAddedEvent @event = null; var id = Guid.NewGuid(); var builder = new CompositeActionBuilder(stock, id, new Date(2000, 01, 01), "Test Composite Action", (x) => { @event = x; }); builder.AddDividend("Test Dividend", new Date(2000, 02, 01), 1.20m, 1.00m, 2.50m) .Finish(); using (new AssertionScope()) { @event.Should().BeEquivalentTo( new { EntityId = stock.Id, Version = 1, ActionId = id, ActionDate = new Date(2000, 01, 01), Description = "Test Composite Action" }); @event.ChildActions.Should().SatisfyRespectively( first => { first.Should().BeOfType <DividendAddedEvent>(); if (first is DividendAddedEvent dividend) { dividend.EntityId.Should().Be(stock.Id); dividend.Version.Should().Be(1); dividend.ActionDate.Should().Be(new Date(2000, 01, 01)); dividend.Description.Should().Be("Test Dividend"); dividend.PaymentDate.Should().Be(new Date(2000, 02, 01)); dividend.DividendAmount.Should().Be(1.20m); dividend.PercentFranked.Should().Be(1.00m); dividend.DrpPrice.Should().Be(2.50m); } } ); }; }
public void ApplyCompositeActionAddedEvent() { var mockRepository = new MockRepository(MockBehavior.Strict); var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); var events = mockRepository.Create <IEventList>(); var corporateActionList = new CorporateActionList(stock, events.Object); var id = Guid.NewGuid(); var @event = new CompositeActionAddedEvent(stock.Id, 0, id, new Date(2000, 01, 01), "Test Complex Action"); @event.ChildActions.Add(new SplitConsolidationAddedEvent(stock.Id, 0, id, new Date(2000, 01, 01), "Test Split", 1, 2)); corporateActionList.Apply(@event); corporateActionList.Should().SatisfyRespectively( first => { first.Should().BeEquivalentTo(new { Id = id, Stock = stock, Date = new Date(2000, 01, 01), Description = "Test Complex Action" }); first.Should().BeOfType <CompositeAction>().Which.ChildActions.Should().SatisfyRespectively( child1 => child1.Should().BeOfType <SplitConsolidation>().Which.Should().BeEquivalentTo(new { Date = new Date(2000, 01, 01), Description = "Test Split", OriginalUnits = 1, NewUnits = 2 }) ); } ); mockRepository.Verify(); }
public void AddSplitConsolidation() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); CompositeActionAddedEvent @event = null; var id = Guid.NewGuid(); var builder = new CompositeActionBuilder(stock, id, new Date(2000, 01, 01), "Test Composite Action", (x) => { @event = x; }); builder.AddSplitConsolidation("Test Split", 1, 2) .Finish(); using (new AssertionScope()) { @event.Should().BeEquivalentTo( new { EntityId = stock.Id, Version = 1, ActionId = id, ActionDate = new Date(2000, 01, 01), Description = "Test Composite Action" }); @event.ChildActions.Should().SatisfyRespectively( first => { first.Should().BeOfType <SplitConsolidationAddedEvent>(); if (first is SplitConsolidationAddedEvent splitConsolidation) { splitConsolidation.EntityId.Should().Be(stock.Id); splitConsolidation.Version.Should().Be(1); splitConsolidation.ActionDate.Should().Be(new Date(2000, 01, 01)); splitConsolidation.Description.Should().Be("Test Split"); splitConsolidation.OriginalUnits.Should().Be(1); splitConsolidation.NewUnits.Should().Be(2); } } ); }; }
public void AddCompositeAction() { var action = new RestApi.CorporateActions.CompositeAction() { Id = Guid.NewGuid(), Stock = _StockWithoutCorporateActions, ActionDate = new Date(2001, 01, 01), Description = "Restructure" }; action.ChildActions.Add(new RestApi.CorporateActions.CapitalReturn() { Id = Guid.NewGuid(), Stock = _StockWithoutCorporateActions, ActionDate = new Date(2001, 01, 01), Description = "Capital Return", PaymentDate = new Date(2001, 01, 15), Amount = 10.00m }); action.ChildActions.Add(new RestApi.CorporateActions.SplitConsolidation() { Id = Guid.NewGuid(), Stock = _StockWithoutCorporateActions, ActionDate = new Date(2001, 01, 01), Description = "Split", OriginalUnits = 1, NewUnits = 2 }); var result = _Service.AddCorporateAction(_StockWithoutCorporateActions, action); result.Should().HaveOkStatus(); var @event = new CompositeActionAddedEvent(_StockWithoutCorporateActions, 1, action.Id, new Date(2001, 01, 01), "Restructure"); @event.ChildActions.Add(new CapitalReturnAddedEvent(_StockWithoutCorporateActions, 1, action.Id, new Date(2001, 01, 01), "Capital Return", new Date(2001, 01, 15), 10.00m)); @event.ChildActions.Add(new SplitConsolidationAddedEvent(_StockWithoutCorporateActions, 1, action.Id, new Date(2001, 01, 01), "Split", 1, 2)); _Events.Should().BeEquivalentTo(new[] { @event }, x => x.Excluding(x => x.ChildActions[0].ActionId).Excluding(x => x.ChildActions[1].ActionId)); }