public async Task ShouldRevoke( TestableContext context, Handler handler ) { context.UoW.Plan <Role>(context.Id()) .HasEvent <Events.Defined>(x => { x.RoleId = context.Id(); }); var command = new Commands.Revoke { RoleId = context.Id() }; await handler.Handle(command, context).ConfigureAwait(false); context.UoW.Check <Role>(context.Id()).Raised <Events.Revoked>(); }
public async Task ShouldNotRevokeDestroyed( TestableContext context, Handler handler ) { context.UoW.Plan <Role>(context.Id()) .HasEvent <Events.Defined>(x => { x.RoleId = context.Id(); }) .HasEvent <Events.Destroyed>(x => { x.RoleId = context.Id(); }); var command = new Commands.Revoke { RoleId = context.Id() }; await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(command, context)).ConfigureAwait(false); }
public async Task Handle(Commands.Revoke command, IMessageHandlerContext ctx) { var role = await ctx.For <Role>().Get(command.RoleId).ConfigureAwait(false); role.Revoke(); }