public async Task ShouldDeactivate( TestableContext context, Handler handler ) { context.UoW.Plan <Role>(context.Id()) .HasEvent <Events.Defined>(x => { x.RoleId = context.Id(); }); var command = new Commands.Deactivate { RoleId = context.Id() }; await handler.Handle(command, context).ConfigureAwait(false); context.UoW.Check <Role>(context.Id()).Raised <Events.Deactivated>(); }
public async Task ShouldNotDeactivateDestroyed( 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.Deactivate { RoleId = context.Id() }; await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(command, context)).ConfigureAwait(false); }
public async Task Handle(Commands.Deactivate command, IMessageHandlerContext ctx) { var role = await ctx.For <Role>().Get(command.RoleId).ConfigureAwait(false); role.Deactivate(); }