Beispiel #1
0
        public async Task ArchiveShopCategory_Success()
        {
            //adhere
            var initialShops = ShopCategoryToArchive.Shops.DeepCopy();

            //arrange
            ShopCategoryToArchive.Shops.Remove(ShopToRemove);
            var command = new ArchiveShopCategory()
            {
                Id          = ShopCategoryToArchive.Id,
                InitiatorId = GlobalAdmin.Id
            };

            var handler = new ArchiveShopCategoryHandler(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 <ShopCategory> >();

            Assert.That(events.Count, Is.EqualTo(1));
            Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Removed));
            Assert.That(events[0].Entity, Is.EqualTo(ShopCategoryToArchive));

            //annul
            ShopCategoryToArchive.Shops = initialShops;
        }
Beispiel #2
0
        public void ArchiveShopCategory_FailFor_ArchivingShopCategoryWithShops()
        {
            //arrange
            var command = new ArchiveShopCategory()
            {
                Id          = ShopCategoryToArchive.Id,
                InitiatorId = GlobalAdmin.Id
            };

            var handler = new ArchiveShopCategoryHandler(EntityRepository, EventTransmitter);

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

            Assert.That(ex.Message, Is.EqualTo(ArchivingShopCategoryWithShops(ShopCategoryToArchive)));
        }