public async Task SaveAggregateAsync_save_new_aggregate() { var aggregate = new TestAggregateRoot() { Id = ObjectId.Parse(_aggregateId) }; aggregate.ApplyChange(new AnotherTestEventV1() { Id = ObjectId.GenerateNewId(), FirstName = "Joe", SurName = "Bloggs", IsValid = true }); await _aggregateRepository.SaveAggregateAsync(aggregate); var events = (await _eventStore.GetDomainEventsAsync(_aggregateId)).ToList(); Assert.That(events.Count, Is.EqualTo(1)); var lastEvent = events.Last(); Assert.That(lastEvent.AggregateId, Is.EqualTo(_aggregateId)); Assert.That(lastEvent.Type, Is.EqualTo("AnotherTestEvent")); Assert.That(lastEvent.Version, Is.EqualTo(1)); Assert.That(lastEvent.Commit, Is.EqualTo(1)); Assert.That(lastEvent.Index, Is.EqualTo(1)); }
public async Task <string> Handle(PaymentRequestCommand command, CancellationToken cancellationToken) { if (command == null) { throw new ArgumentNullException(nameof(command)); } _logger.LogTrace($"Handling {nameof(PaymentRequestCommand)} with id {command.Id}."); var payment = new PaymentAggregate(command.Id, command.MerchantId, command.CardNumber, command.ExpMonth, command.ExpYear, command.Amount, command.Currency); await payment.RequestAsync(_bank, command.CVV); await _repository.SaveAggregateAsync(payment); return(payment.Status.ToString()); }