Beispiel #1
0
        public void ArchiveCustomer_FailFor_CustomerHasActiveOrders()
        {
            var command = new ArchiveCustomer
            {
                Id          = CustomerDoorsBuyer.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new ArchiveCustomerHandler(EntityRepository, EventTransmitter);

            var ex = Assert.ThrowsAsync <DomainException>(async() => await handler.HandleAsync(command));

            Assert.That(ex.Message, Is.EqualTo(ArchivingCustomerWithActiveOrders(CustomerDoorsBuyer)));
            Assert.That(GetRecordedEvents <DomainEvent <Customer> >(), Is.Empty);
        }
Beispiel #2
0
        public async Task ArchiveCustomer_Success()
        {
            var command = new ArchiveCustomer
            {
                Id          = CustomerToArchive.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new ArchiveCustomerHandler(EntityRepository, EventTransmitter);

            await handler.HandleAsync(command);

            Assert.That(CallsTo(EntityRepository, nameof(EntityRepository.RemoveAsync)), Is.EqualTo(1));

            var events = GetRecordedEvents <DomainEvent <Customer> >();

            Assert.That(events.Count, Is.EqualTo(1));
            Assert.That(events[0].Entity, Is.EqualTo(CustomerToArchive));
            Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Removed));
            Assert.That(events[0].RaisedBy, Is.EqualTo(command.InitiatorId));
        }