示例#1
0
        public async Task ArchiveSupplier_Success()
        {
            //arrange
            var command = new ArchiveSupplier
            {
                Id          = SupplierToArchive.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new ArchiveSupplierHandler(EntityRepository, EventTransmitter);

            //act
            await handler.HandleAsync(command);

            //assert
            var ids = GetRecordedIds(EntityRepository, nameof(EntityRepository.RemoveAsync));

            Assert.That(ids.Count, Is.EqualTo(1));
            Assert.That(ids[0], Is.EqualTo(command.Id));

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

            Assert.That(events.Count, Is.EqualTo(1));
            Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Removed));
            Assert.That(events[0].Entity, Is.EqualTo(SupplierToArchive));
            Assert.That(events[0].RaisedBy, Is.EqualTo(command.InitiatorId));
        }
示例#2
0
        public void ArchiveSupplier_FailFor_ActiveMaterialRequests()
        {
            //arrange
            var command = new ArchiveSupplier
            {
                Id          = Material1TimberSupplier.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new ArchiveSupplierHandler(EntityRepository, EventTransmitter);

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

            Assert.That(ex.Message, Is.EqualTo(ArchivingSupplierWithActiveMaterialRequests(Material1TimberSupplier)));
            Assert.That(GetRecordedEvents <DomainEvent <Supplier> >(), Is.Empty);
        }