示例#1
0
        public async Task ArchiveShop_Success()
        {
            //arrange
            var command = new ArchiveShop
            {
                Id          = ShopToRemove.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new ArchiveShopHandler(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 <Shop> >();

            Assert.That(events.Count, Is.EqualTo(1));
            Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Removed));
            Assert.That(events[0].Entity, Is.EqualTo(ShopToRemove));
            Assert.That(events[0].RaisedBy, Is.EqualTo(command.InitiatorId));
        }
示例#2
0
        public void ArchiveShop_FailFor_InventoryStillInStock()
        {
            //arrange
            var command = new ArchiveShop
            {
                Id          = ProductAssemblyShop.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new ArchiveShopHandler(EntityRepository, EventTransmitter);

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

            Assert.That(ex.Message, Is.EqualTo(ArchivingShopWithInventory(ProductAssemblyShop)));
            Assert.That(GetRecordedEvents <DomainEvent <Shop> >(), Is.Empty);
        }