Esempio n. 1
0
        public async Task RevokePermission_Success()
        {
            //arrange
            var command = new RevokePermission
            {
                Id          = UserWithPermissionsOnProduceInventoryItemHandler.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new RevokePermissionHandler(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 <Permission> >();

            Assert.That(events.Count, Is.EqualTo(1));
            Assert.That(events[0].Trigger, Is.EqualTo(Trigger.Removed));
            Assert.That(events[0].Entity, Is.EqualTo(UserWithPermissionsOnProduceInventoryItemHandler));
            Assert.That(events[0].RaisedBy, Is.EqualTo(command.InitiatorId));
        }
Esempio n. 2
0
        public void RevokePermission_FailFor_RevokingOnRevokePermissionHandler()
        {
            //arrange
            var command = new RevokePermission
            {
                Id          = GlobalAdminOnProduceInventoryItemHandler.Id,
                InitiatorId = GlobalAdmin.Id
            };
            var handler = new RevokePermissionHandler(EntityRepository, EventTransmitter);

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

            Assert.That(ex.Message, Is.EqualTo(RevokingGlobalAdminPermission(GlobalAdmin)));
            Assert.That(GetRecordedEvents <DomainEvent <Permission> >(), Is.Empty);
        }