public void SingleParcelOwned()
        {
            var stock = new Stock(Guid.NewGuid());

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

            var transaction = new CostBaseAdjustment()
            {
                Id         = Guid.NewGuid(),
                Date       = new Date(2020, 02, 01),
                Stock      = stock,
                Comment    = "Test Costbase Adjustment",
                Percentage = 0.40m,
            };

            var mockRepository = new MockRepository(MockBehavior.Strict);

            var parcel = mockRepository.Create <IParcel>();

            parcel.Setup(x => x.Properties[new Date(2020, 02, 01)]).Returns(new ParcelProperties(50, 1000.00m, 1500.00m));
            parcel.Setup(x => x.Change(new Date(2020, 02, 01), 0, 0.00m, -900.00m, transaction)).Verifiable();

            var holding = mockRepository.Create <IHolding>();

            holding.Setup(x => x.IsEffectiveAt(new Date(2020, 02, 01))).Returns(true);
            holding.Setup(x => x.Parcels(new Date(2020, 02, 01))).Returns(new IParcel[] { parcel.Object });

            var cashAccount = mockRepository.Create <ICashAccount>();

            var handler = new CostBaseAdjustmentHandler();

            handler.Apply(transaction, holding.Object, cashAccount.Object);

            mockRepository.Verify();
        }
Esempio n. 2
0
        public void DeserializeCostBaseAdjustment()
        {
            var serializer = new RestClientSerializer();

            var transactionId = Guid.NewGuid();
            var stockId       = Guid.NewGuid();

            var json = "{\"id\":\"" + transactionId + "\","
                       + "\"stock\":\"" + stockId + "\","
                       + "\"type\":\"costbaseadjustment\","
                       + "\"transactionDate\":\"2000-01-10\","
                       + "\"comment\":\"comment\","
                       + "\"description\":\"description\","
                       + "\"percentage\":0.35}";

            var transaction = serializer.Deserialize <Transaction>(json);

            var expected = new CostBaseAdjustment()
            {
                Id              = transactionId,
                Stock           = stockId,
                TransactionDate = new Date(2000, 01, 10),
                Comment         = "comment",
                Description     = "description",
                Percentage      = 0.35m
            };

            transaction.Should().BeEquivalentTo(expected);
        }
        public void NoSharesOwned()
        {
            var stock = new Stock(Guid.NewGuid());

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

            var transaction = new CostBaseAdjustment()
            {
                Id         = Guid.NewGuid(),
                Date       = new Date(2020, 02, 01),
                Stock      = stock,
                Comment    = "Test Costbase Adjustment",
                Percentage = 0.40m,
            };

            var mockRepository = new MockRepository(MockBehavior.Strict);

            var holding = mockRepository.Create <IHolding>();

            holding.Setup(x => x.IsEffectiveAt(new Date(2020, 02, 01))).Returns(false);

            var cashAccount = mockRepository.Create <ICashAccount>();

            var handler = new CostBaseAdjustmentHandler();

            Action a = () => handler.Apply(transaction, holding.Object, cashAccount.Object);

            a.Should().Throw <NoSharesOwnedException>();

            mockRepository.Verify();
        }
Esempio n. 4
0
        public void ApplyCostBaseAdjustment()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var portfolio = PortfolioTestCreator.CreateDefaultPortfolio();

            var events     = new List <Event>();
            var repository = mockRepository.Create <IRepository <Portfolio> >();

            repository.Setup(x => x.Update(It.IsAny <Portfolio>())).Callback <Portfolio>(x => events.AddRange(x.FetchEvents()));

            var service = new PortfolioTransactionService(portfolio, repository.Object);

            var transaction = new CostBaseAdjustment()
            {
                Id              = Guid.NewGuid(),
                Stock           = PortfolioTestCreator.Stock_ARG.Id,
                TransactionDate = new Date(2007, 01, 01),
                Comment         = "",
                Percentage      = 0.50m
            };
            var result = service.ApplyTransaction(transaction);

            result.Should().HaveOkStatus();
            events.Should().BeEquivalentTo(new[]
            {
                new CostBaseAdjustmentOccurredEvent(portfolio.Id, 1, transaction.Id, new Date(2007, 01, 01), PortfolioTestCreator.Stock_ARG.Id, "")
                {
                    Percentage = 0.50m
                }
            });

            mockRepository.Verify();
        }
        protected override void CopyFieldsToTransaction()
        {
            if (_Transaction == null)
            {
                _Transaction = new CostBaseAdjustment();
            }

            base.CopyFieldsToTransaction();

            var costBaseAdjustment = (CostBaseAdjustment)_Transaction;

            costBaseAdjustment.TransactionDate = RecordDate;
            costBaseAdjustment.Percentage      = Percentage / 100;
        }
        public void AdjustCostBase()
        {
            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 stockResolver = mockRepository.Create <IStockResolver>();

            stockResolver.Setup(x => x.GetStock(stock.Id)).Returns(stock);

            var handler = mockRepository.Create <ITransactionHandler>();
            CostBaseAdjustment transaction = null;

            handler.Setup(x => x.Apply(It.IsAny <IPortfolioTransaction>(), It.IsAny <IHolding>(), It.IsAny <ICashAccount>()))
            .Callback <IPortfolioTransaction, IHolding, ICashAccount>((t, h, c) => transaction = (CostBaseAdjustment)t)
            .Verifiable();

            var transactionHandlers = mockRepository.Create <IServiceFactory <ITransactionHandler> >();

            transactionHandlers.Setup(x => x.GetService <CostBaseAdjustment>()).Returns(handler.Object);
            transactionHandlers.Setup(x => x.GetService <OpeningBalance>()).Returns(new OpeningBalanceHandler());

            var portfolio = new Portfolio(Guid.NewGuid(), stockResolver.Object, transactionHandlers.Object);

            portfolio.AddOpeningBalance(stock.Id, new Date(1999, 01, 01), new Date(1999, 01, 01), 100, 100.00m, "", Guid.Empty);

            var transactionId = Guid.NewGuid();

            portfolio.AdjustCostBase(stock.Id, new Date(2000, 01, 01), 0.50m, "Comment", transactionId);

            transaction.Should().BeEquivalentTo(new
            {
                Id         = transaction.Id,
                Date       = new Date(2000, 01, 01),
                Stock      = stock,
                Comment    = "Comment",
                Percentage = 0.50m
            });

            mockRepository.Verify();
        }
        public void Apply(CostBaseAdjustmentOccurredEvent @event)
        {
            var holding = _Holdings[@event.Stock];

            if (holding == null)
            {
                throw new NoSharesOwnedException("No shares owned");
            }

            var costBaseAdjustment = new CostBaseAdjustment
            {
                Id         = @event.TransactionId,
                Date       = @event.Date,
                Stock      = holding.Stock,
                Comment    = @event.Comment,
                Percentage = @event.Percentage
            };

            var handler = _TransactionHandlers.GetService <CostBaseAdjustment>();

            handler.Apply(costBaseAdjustment, holding, _CashAccount);
            _Transactions.Add(costBaseAdjustment);
        }
 public CostBaseAdjustmentViewModel(CostBaseAdjustment costBaseAdjustment, RestClient restClient)
     : base(costBaseAdjustment, "Costbase Adjustment", TransactionStockSelection.Holdings, restClient)
 {
 }