Exemplo n.º 1
0
        public async Task ShouldDestroyRole(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <Role>(context.Id())
            .HasEvent <Events.Defined>(x =>
            {
                x.RoleId = context.Id();
            })
            .HasEvent <Events.Deactivated>(x =>
            {
                x.RoleId = context.Id();
            });

            var command = new Commands.Destroy
            {
                RoleId = context.Id()
            };
            await handler.Handle(command, context).ConfigureAwait(false);

            context.UoW.Check <Role>(context.Id()).Raised <Events.Destroyed>(x =>
            {
                x.RoleId = context.Id();
            });
        }
Exemplo n.º 2
0
 public async Task ShouldNotDestroyUnknown(
     TestableContext context,
     Handler handler
     )
 {
     var command = new Commands.Destroy
     {
         RoleId = context.Id()
     };
     await Assert.ThrowsAsync <NotFoundException>(() => handler.Handle(command, context)).ConfigureAwait(false);
 }
Exemplo n.º 3
0
        public async Task ShouldNotDestroyActiveRole(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <Role>(context.Id())
            .HasEvent <Events.Defined>(x =>
            {
                x.RoleId = context.Id();
            })
            .HasEvent <Events.Activated>(x =>
            {
                x.RoleId = context.Id();
            });

            var command = new Commands.Destroy
            {
                RoleId = context.Id()
            };
            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(command, context)).ConfigureAwait(false);
        }
Exemplo n.º 4
0
        public async Task Handle(Commands.Destroy command, IMessageHandlerContext ctx)
        {
            var role = await ctx.For <Role>().Get(command.RoleId).ConfigureAwait(false);

            role.Destroy();
        }