public void StockNotActiveAtDate() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(2020, 01, 01), false, AssetCategory.AustralianStocks); var transaction = new Aquisition() { Id = Guid.NewGuid(), Date = new Date(2000, 01, 01), Stock = stock, Comment = "Test Aquisition", Units = 100, AveragePrice = 10.00m, TransactionCosts = 20.00m, CreateCashTransaction = true }; var mockRepository = new MockRepository(MockBehavior.Strict); var holding = mockRepository.Create <IHolding>(); var cashAccount = mockRepository.Create <ICashAccount>(); var handler = new AquisitionHandler(); Action a = () => handler.Apply(transaction, holding.Object, cashAccount.Object); a.Should().Throw <StockNotActiveException>(); mockRepository.Verify(); }
public void NoCashTransactionNoTransactionCosts() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); var transaction = new Aquisition() { Id = Guid.NewGuid(), Date = new Date(2020, 01, 01), Stock = stock, Comment = "Test Aquisition", Units = 100, AveragePrice = 10.00m, TransactionCosts = 0.00m, CreateCashTransaction = false }; var mockRepository = new MockRepository(MockBehavior.Strict); var holding = mockRepository.Create <IHolding>(); holding.Setup(x => x.AddParcel(new Date(2020, 01, 01), new Date(2020, 01, 01), 100, 1000.00m, 1000.00m, transaction)).Returns(default(IParcel)).Verifiable(); var cashAccount = mockRepository.Create <ICashAccount>(); var handler = new AquisitionHandler(); handler.Apply(transaction, holding.Object, cashAccount.Object); mockRepository.Verify(); }
public void Apply(AquisitionOccurredEvent @event) { var holding = _Holdings[@event.Stock]; if (holding == null) { var stock = _StockResolver.GetStock(@event.Stock); holding = _Holdings.Add(stock, @event.Date); holding.CgtEventOccurred += Holding_CgtEventOccurred; } var aquisition = new Aquisition { Id = @event.TransactionId, Date = @event.Date, Stock = holding.Stock, Comment = @event.Comment, Units = @event.Units, AveragePrice = @event.AveragePrice, TransactionCosts = @event.TransactionCosts, CreateCashTransaction = @event.CreateCashTransaction }; var handler = _TransactionHandlers.GetService <Aquisition>(); handler.Apply(aquisition, holding, _CashAccount); _Transactions.Add(aquisition); }
public void DeserializeAquisition() { var serializer = new RestClientSerializer(); var transactionId = Guid.NewGuid(); var stockId = Guid.NewGuid(); var json = "{\"id\":\"" + transactionId + "\"," + "\"stock\":\"" + stockId + "\"," + "\"type\":\"aquisition\"," + "\"transactionDate\":\"2000-01-10\"," + "\"comment\":\"comment\"," + "\"description\":\"description\"," + "\"units\":\"100\"," + "\"averagePrice\":\"12.00\"," + "\"transactionCosts\":\"19.95\"," + "\"createCashTransaction\":\"true\"}"; var transaction = serializer.Deserialize <Transaction>(json); var expected = new Aquisition() { Id = transactionId, Stock = stockId, TransactionDate = new Date(2000, 01, 10), Comment = "comment", Description = "description", Units = 100, AveragePrice = 12.00m, TransactionCosts = 19.95m, CreateCashTransaction = true }; transaction.Should().BeEquivalentTo(expected); }
public void AquireSharesNoExistingHoldings() { 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>(); Aquisition transaction = null; handler.Setup(x => x.Apply(It.IsAny <IPortfolioTransaction>(), It.IsAny <IHolding>(), It.IsAny <ICashAccount>())) .Callback <IPortfolioTransaction, IHolding, ICashAccount>((t, h, c) => transaction = (Aquisition)t) .Verifiable(); var transactionHandlers = mockRepository.Create <IServiceFactory <ITransactionHandler> >(); transactionHandlers.Setup(x => x.GetService <Aquisition>()).Returns(handler.Object); var portfolio = new Portfolio(Guid.NewGuid(), stockResolver.Object, transactionHandlers.Object); var transactionId = Guid.NewGuid(); portfolio.AquireShares(stock.Id, new Date(2000, 01, 01), 100, 10.00m, 19.95m, true, "Comment", transactionId); using (new AssertionScope()) { portfolio.Holdings[stock.Id].EffectivePeriod.Should().Be(new DateRange(new Date(2000, 01, 01), Date.MaxValue)); transaction.Should().BeEquivalentTo(new { Id = transaction.Id, Date = new Date(2000, 01, 01), Stock = stock, Comment = "Comment", Units = 100, AveragePrice = 10.00m, TransactionCosts = 19.95m, CreateCashTransaction = true }); } mockRepository.Verify(); }
protected override void CopyFieldsToTransaction() { if (_Transaction == null) { _Transaction = new Aquisition(); } base.CopyFieldsToTransaction(); var aquisition = (Aquisition)_Transaction; aquisition.TransactionDate = RecordDate; aquisition.Units = Units; aquisition.AveragePrice = AveragePrice; aquisition.TransactionCosts = TransactionCosts; aquisition.CreateCashTransaction = CreateCashTransaction; }
public void AddTransaction() { var mockRepository = new MockRepository(MockBehavior.Strict); var transactionId = Guid.NewGuid(); var transaction = new Aquisition() { Id = transactionId }; var service = mockRepository.Create <IPortfolioTransactionService>(); service.Setup(x => x.ApplyTransaction(transaction)).Returns(ServiceResult.Ok()).Verifiable(); var controller = new TransactionController(); var result = controller.AddTransaction(service.Object, transaction); result.Should().BeOkResult(); mockRepository.VerifyAll(); }
public void AddTransactionValidationError() { var mockRepository = new MockRepository(MockBehavior.Strict); var transactionId = Guid.NewGuid(); var transaction = new Aquisition() { Id = transactionId }; var service = mockRepository.Create <IPortfolioTransactionService>(); service.Setup(x => x.ApplyTransaction(transaction)).Returns(ServiceResult.Error("Error message")).Verifiable(); var controller = new TransactionController(); var result = controller.AddTransaction(service.Object, transaction); result.Should().BeBadRequestObjectResult().Error.Should().BeEquivalentTo(new[] { "Error message" }); mockRepository.VerifyAll(); }
public void ApplyAquisition() { 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 Aquisition() { Id = Guid.NewGuid(), Stock = PortfolioTestCreator.Stock_ARG.Id, TransactionDate = new Date(2007, 01, 01), Units = 50, AveragePrice = 0.98m, TransactionCosts = 1.00m, Comment = "", CreateCashTransaction = true }; var result = service.ApplyTransaction(transaction); result.Should().HaveOkStatus(); events.Should().BeEquivalentTo(new[] { new AquisitionOccurredEvent(portfolio.Id, 1, transaction.Id, new Date(2007, 01, 01), PortfolioTestCreator.Stock_ARG.Id, "") { Units = 50, AveragePrice = 0.98m, TransactionCosts = 1.00m, CreateCashTransaction = true } }); mockRepository.Verify(); }
public void IncorrectTransactionType() { var transaction = new Aquisition() { Id = Guid.NewGuid(), Date = new Date(2020, 01, 01), Comment = "" }; var mockRepository = new MockRepository(MockBehavior.Strict); var holding = mockRepository.Create <IHolding>(); var cashAccount = mockRepository.Create <ICashAccount>(); var handler = new CashTransactionHandler(); Action a = () => handler.Apply(transaction, holding.Object, cashAccount.Object); a.Should().Throw <ArgumentException>(); mockRepository.Verify(); }
public AquisitionViewModel(Aquisition aquisition, RestClient restClient) : base(aquisition, "Aquisition", TransactionStockSelection.TradeableStocks, restClient) { }