public void NewSutFromEventHistoryAppliesEvents() { // Arrange var amount = 10.99M; var card = new Card("1234567890", new ExpiryDate(2020, 10)); var id = Guid.NewGuid(); var eventHistory = new List <Event>() { { new AddedEvent(amount, card) { Version = 1, Id = Guid.NewGuid(), SourceId = id } }, { new AuthorizedEvent(amount) { Version = 2, Id = Guid.NewGuid(), SourceId = id } } }; // Act var sut = new TransactionAggregate(id, eventHistory); // Assert Assert.AreEqual(amount, sut.Amount); Assert.AreEqual(card, sut.Card); Assert.AreEqual(amount, sut.AuthorizedAmount); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> public void Execute(TransactionDividendCommand command) { if (command.Shares == 0) { throw new DomainValidationException("Shares", "Cannot sell zero units"); } //TODO: Further Validation if (_book.GetOrAddOpenPosition(command.StockId).Shares < command.Shares) { throw new DomainValidationException("Shares", "The amount of available units for the stock is smaller than those used in the dividend."); } //Create new transaction var transaction = new TransactionAggregate(); transaction.CreateDividendTransaction( command.AggregateId, command.OrderDate, command.Shares, command.PricePerShare, command.OrderCosts, command.Description, command.Tag, command.Image, command.StockId, command.Taxes); //Save transaction _repository.Save(transaction, -1); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> public void Execute(TransactionSplitCommand command) { if (command.Shares == 0) { throw new DomainValidationException("Shares", "Cannot sell zero units"); } //TODO: Further Validation if (_book.GetOrAddOpenPosition(command.StockId).Shares == 0) { throw new DomainValidationException("Shares", "The amount of available shares cannot be zero for a split/reverse split."); } //Create new transaction var transaction = new TransactionAggregate(); transaction.CreateSplitTransaction( command.AggregateId, command.OrderDate, command.Shares, command.PricePerShare, command.StockId); //Save transaction _repository.Save(transaction, -1); }
public void NewSutRaisesAddedEvent() { // Arrange & Act var sut = new TransactionAggregate(Guid.NewGuid(), 10.99M, new Card("1234567890", new ExpiryDate(2020, 10))); // Assert Assert.That(sut.UncommittedEvents.First(), Is.TypeOf <AddedEvent>()); }
protected override Task OnDeactivate(bool close) { if (close) { InvTypes = null; TransactionAggregate = null; } return(base.OnDeactivate(close)); }
private async Task load(DateTime start, DateTime end) { _eventAggregator.PublishOnUIThread(new StatusEvent(this, "Loading...")); List <Transaction> transactions = await _tradeSummaryService.GetTransactions(start, end).ConfigureAwait(false); _eventAggregator.PublishOnUIThread(new StatusEvent(this, "Analyzing...")); Summary = new TransactionAggregate(transactions.GroupBy(t => t.TransactionDate.Date)); _eventAggregator.PublishOnUIThread(new StatusEvent(this, "Analysis complete")); }
public void AuthorizingRaisesAuthorizedEvent() { // Arrange var amount = 10.99M; var sut = new TransactionAggregate(Guid.NewGuid(), amount, new Card("1234567890", new ExpiryDate(2020, 10))); // Act sut.UncommittedEvents.Clear(); sut.Authorize(amount); // Assert AuthorizedEvent authorizedEvent; Assert.That(authorizedEvent = (AuthorizedEvent)sut.UncommittedEvents.First(), Is.TypeOf <AuthorizedEvent>()); Assert.AreEqual(amount, authorizedEvent.AuthorizedAmount); Assert.AreEqual(amount, sut.AuthorizedAmount); }
private async Task LoadItem(InvType type) { _eventAggregator.PublishOnUIThread(new StatusEvent(this, "Processing trade details...")); if (type == null) { return; } setActualViewperiod(); Transactions = await _transactionDetailsService.GetTransactions(type, ActualViewStart, ActualViewEnd); if (Transactions.Any()) { Order order = await _transactionDetailsService.GetOrder(type).ConfigureAwait(false); TransactionAggregate = new TransactionAggregate(Transactions.GroupBy(t => t.TransactionDate.Date), type, order); } else { TransactionAggregate = new TransactionAggregate(); } _eventAggregator.PublishOnUIThread(new StatusEvent(this, "Trade details loaded")); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> public void Execute(TransactionBuyCommand command) { //TODO: Validation //Create new transaction var transaction = new TransactionAggregate(); transaction.CreateBuyingTransaction( command.AggregateId, command.OrderDate, command.Units, command.PricePerUnit, command.OrderCosts, command.Description, command.Tag, command.Image, command.InitialSL, command.InitialTP, command.StockId, command.StrategyId); //Save transaction _repository.Save(transaction, -1); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> public void Execute(TransactionSellCommand command) { if (command.Shares == 0) { throw new DomainValidationException("Units", "Cannot sell zero units"); } //TODO: Further Validation if (_book.GetOrAddOpenPosition(command.StockId).Shares < command.Shares) { throw new DomainValidationException("Units", "The amount of available units for the stock is smaller than those sold."); } //TODO: Validation MAE must be smaller than share price if long, else higher, same for MFE //Create new transaction var transaction = new TransactionAggregate(); transaction.CreateSellingTransaction( command.AggregateId, command.OrderDate, command.Shares, command.PricePerShare, command.OrderCosts, command.Description, command.Tag, command.Image, command.StockId, command.Taxes, command.MAE, command.MFE, command.Feedback); //Save transaction _repository.Save(transaction, -1); }
private void ExecuteViewTradeDetails(TransactionAggregate entry) { _eventAggregator.PublishOnUIThread(new ViewTransactionDetailsEvent(entry.InvType)); }
private void ExecuteViewOrder(TransactionAggregate entry) { _eventAggregator.PublishOnUIThread(new ViewOrderEvent(entry.InvType)); }
private bool CanViewOrder(TransactionAggregate entry) { return(entry != null && entry.Order != null); }