public void ApplySplitConsolidationAddedEvent()
        {
            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 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 Split",
                OriginalUnits = 1,
                NewUnits      = 2
            })

                );

            mockRepository.Verify();
        }
        public void ApplyCapitalReturnAddedEvent()
        {
            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 CapitalReturnAddedEvent(stock.Id, 0, id, new Date(2000, 01, 01), "Test Capital Return", new Date(2000, 02, 01), 10.00m);

            corporateActionList.Apply(@event);

            corporateActionList.Should().SatisfyRespectively(

                first => first.Should().BeEquivalentTo(new
            {
                Id          = id,
                Stock       = stock,
                Date        = new Date(2000, 01, 01),
                Description = "Test Capital Return",
                PaymentDate = new Date(2000, 02, 01),
                Amount      = 10.00m
            })

                );

            mockRepository.Verify();
        }
        public void AddCapitalReturnWithBlankDescription()
        {
            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>();

            events.Setup(x => x.Add(It.IsAny <CapitalReturnAddedEvent>())).Verifiable();

            var corporateActionList = new CorporateActionList(stock, events.Object);

            var id = Guid.NewGuid();

            corporateActionList.AddCapitalReturn(id, new Date(2000, 01, 01), "", new Date(2000, 02, 01), 10.00m);

            corporateActionList.Should().SatisfyRespectively(

                first => first.Should().BeEquivalentTo(new
            {
                Id          = id,
                Stock       = stock,
                Date        = new Date(2000, 01, 01),
                Description = "Capital Return $10.00",
                PaymentDate = new Date(2000, 02, 01),
                Amount      = 10.00m
            })

                );

            mockRepository.Verify();
        }
        public void AddSplitConsolidationithBlankDescription()
        {
            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>();

            events.Setup(x => x.Add(It.IsAny <SplitConsolidationAddedEvent>())).Verifiable();

            var corporateActionList = new CorporateActionList(stock, events.Object);

            var id = Guid.NewGuid();

            corporateActionList.AddSplitConsolidation(id, new Date(2000, 01, 01), "", 1, 2);

            corporateActionList.Should().SatisfyRespectively(

                first => first.Should().BeEquivalentTo(new
            {
                Id            = id,
                Stock         = stock,
                Date          = new Date(2000, 01, 01),
                Description   = "1 for 2 Stock Split",
                OriginalUnits = 1,
                NewUnits      = 2
            })

                );

            mockRepository.Verify();
        }
        public void AddCompositeActionChildActions()
        {
            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>();

            events.Setup(x => x.Add(It.IsAny <CompositeActionAddedEvent>())).Verifiable();

            var corporateActionList = new CorporateActionList(stock, events.Object);

            var id = Guid.NewGuid();

            corporateActionList.StartCompositeAction(id, new Date(2000, 01, 01), "Test CompositeAction")
            .AddCapitalReturn("Capital Return", new Date(2000, 02, 01), 10.00m)
            .AddSplitConsolidation("Split", 1, 2)
            .Finish();

            corporateActionList.Should().SatisfyRespectively(

                first =>
            {
                first.Should().BeEquivalentTo(new
                {
                    Id          = id,
                    Stock       = stock,
                    Date        = new Date(2000, 01, 01),
                    Description = "Test CompositeAction"
                });
                first.Should().BeOfType <CompositeAction>().Which.ChildActions.Should().SatisfyRespectively(
                    child1 => child1.Should().BeOfType <CapitalReturn>().Which.Amount.Should().Be(10.00m),
                    child1 => child1.Should().BeOfType <SplitConsolidation>().Which.NewUnits.Should().Be(2)
                    );
            }

                );

            mockRepository.Verify();
        }
        public void ApplyTransformationAddedEvent()
        {
            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 stock2 = new Stock(Guid.NewGuid());

            stock2.List("XYZ", "XYZ 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 resultStocks = new TransformationAddedEvent.ResultingStock[] {
                new TransformationAddedEvent.ResultingStock(stock2.Id, 1, 2, 0.40m, new Date(2020, 02, 01))
            };
            var @event = new TransformationAddedEvent(stock.Id, 0, id, new Date(2000, 01, 01), "Test Transformation", new Date(2000, 02, 01), 1.20m, false, resultStocks);

            corporateActionList.Apply(@event);

            corporateActionList.Should().SatisfyRespectively(

                first => {
                first.Should().BeEquivalentTo(new
                {
                    Id                     = id,
                    Stock                  = stock,
                    Date                   = new Date(2000, 01, 01),
                    Description            = "Test Transformation",
                    CashComponent          = 1.20M,
                    RolloverRefliefApplies = false
                });
                first.Should().BeOfType <Transformation>().Which.ResultingStocks.Should().HaveCount(1);
            }

                );
            mockRepository.Verify();
        }
        public void AddTransformationWithBlankDescription()
        {
            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 stock2 = new Stock(Guid.NewGuid());

            stock2.List("XYZ", "XYZ Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks);

            var events = mockRepository.Create <IEventList>();

            events.Setup(x => x.Add(It.IsAny <TransformationAddedEvent>())).Verifiable();

            var corporateActionList = new CorporateActionList(stock, events.Object);

            var id           = Guid.NewGuid();
            var resultStocks = new Transformation.ResultingStock[] {
                new Transformation.ResultingStock(stock2.Id, 1, 2, 0.40m, new Date(2020, 02, 01))
            };

            corporateActionList.AddTransformation(id, new Date(2000, 01, 01), "", new Date(2000, 02, 01), 1.20m, false, resultStocks);

            corporateActionList.Should().SatisfyRespectively(

                first => first.Should().BeEquivalentTo(new
            {
                Id                     = id,
                Stock                  = stock,
                Date                   = new Date(2000, 01, 01),
                Description            = "Transformation",
                CashComponent          = 1.20M,
                RolloverRefliefApplies = false
            })

                );

            mockRepository.Verify();
        }
        public void AddDividend()
        {
            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>();

            events.Setup(x => x.Add(It.IsAny <DividendAddedEvent>())).Verifiable();

            var corporateActionList = new CorporateActionList(stock, events.Object);

            var id = Guid.NewGuid();

            corporateActionList.AddDividend(id, new Date(2000, 01, 01), "Test Dividend", new Date(2000, 02, 01), 1.20m, 1.00m, 2.50m);


            corporateActionList.Should().SatisfyRespectively(

                first => first.Should().BeEquivalentTo(new
            {
                Id             = id,
                Stock          = stock,
                Date           = new Date(2000, 01, 01),
                Description    = "Test Dividend",
                PaymentDate    = new Date(2000, 02, 01),
                DividendAmount = 1.20m,
                PercentFranked = 1.00m,
                DrpPrice       = 2.50m
            })

                );

            mockRepository.Verify();
        }
        public void AddCompositeActionWithBlankDescription()
        {
            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>();

            events.Setup(x => x.Add(It.IsAny <CompositeActionAddedEvent>())).Verifiable();

            var corporateActionList = new CorporateActionList(stock, events.Object);

            var id = Guid.NewGuid();

            corporateActionList.StartCompositeAction(id, new Date(2000, 01, 01), "").Finish();

            corporateActionList.Should().SatisfyRespectively(

                first =>
            {
                first.Should().BeEquivalentTo(new
                {
                    Id          = id,
                    Stock       = stock,
                    Date        = new Date(2000, 01, 01),
                    Description = "Complex corporate action"
                });
                first.Should().BeOfType <CompositeAction>().Which.ChildActions.Should().BeEmpty();
            }

                );

            mockRepository.Verify();
        }