Beispiel #1
0
        public async Task ShouldNotUnmarkReorder(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <Product>(context.Id())
            .HasEvent <Events.Added>(x =>
            {
                x.ProductId      = context.Id();
                x.CatalogBrandId = context.Id();
                x.CatalogTypeId  = context.Id();
                x.Name           = "test";
                x.Price          = 1;
            });

            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(new Commands.UnMarkReordered
            {
                ProductId = context.Id()
            }, context)).ConfigureAwait(false);
        }
Beispiel #2
0
        public async Task ShouldNotIdentifyUser(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <User>(context.Id())
            .HasEvent <Events.Registered>(x =>
            {
                x.UserName  = context.Id();
                x.GivenName = "test";
                x.Password  = PasswordStorage.CreateHash("test");
            });

            var command = new Commands.Identify
            {
                UserName = context.Id(),
                Password = "******"
            };
            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(command, context)).ConfigureAwait(false);
        }
Beispiel #3
0
        public async Task should_create_world(
            TestableContext context,
            Handler handler
            )
        {
            await handler.Handle(new SayHello
            {
                MessageId = context.Id(1),
                Message   = "test"
            }, context).ConfigureAwait(false);

            context.UoW.Check <Domain.World>("World")
            .Raised <WorldCreated>(x => { })
            .Check <Domain.Message>(context.Id(1))
            .Raised <SaidHello>(x =>
            {
                x.MessageId = context.Id(1);
                x.Message   = "test";
            });
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public async Task ShouldDisableUser(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <User>(context.Id())
            .HasEvent <Events.Registered>(x =>
            {
                x.UserName  = context.Id();
                x.GivenName = "test";
                x.Password  = "******";
            });

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

            context.UoW.Check <User>(context.Id()).Raised <Events.Disabled>();
        }
Beispiel #6
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();
            });
        }
Beispiel #7
0
        public async Task ShouldUserIdentified(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <User>(context.Id())
            .HasEvent <Events.Registered>(x =>
            {
                x.UserName  = context.Id();
                x.GivenName = "test";
                x.Password  = PasswordStorage.CreateHash("test");
            });

            var command = new Commands.Identify
            {
                UserName = context.Id(),
                Password = "******"
            };
            await handler.Handle(command, context).ConfigureAwait(false);

            context.UoW.Check <User>(context.Id()).Raised <Events.Identified>();
        }
Beispiel #8
0
        public async Task ShouldChangeQuantity(
            TestableContext context,
            BasketItemIndex handler
            )
        {
            context.App.Plan <Models.BasketItemIndex>(BasketItemIndex.ItemIdGenerator(context.Id(), context.Id())).Exists(new Models.BasketItemIndex
            {
                Quantity = 1
            });

            var @event = context.Create <Entities.Item.Events.QuantityUpdated>(x =>
            {
                x.BasketId  = context.Id();
                x.ProductId = context.Id();
                x.Quantity  = 2;
            });

            await handler.Handle(@event, context).ConfigureAwait(false);

            context.App.Check <Models.BasketItemIndex>(BasketItemIndex.ItemIdGenerator(context.Id(), context.Id())).Updated(x =>
                                                                                                                            x.Quantity == 2
                                                                                                                            );
        }
Beispiel #9
0
        public async Task should_say_hello(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <Domain.World>("World").HasEvent <WorldCreated>(x =>
            {
            });

            await handler.Handle(new SayHello
            {
                MessageId = context.Id(),
                Message   = "test"
            }, context).ConfigureAwait(false);

            context.UoW.Check <Domain.World>("World").Check <Domain.Message>(context.Id())
            .Raised <SaidHello>(x => x.Message == "test")
            .Raised <SaidHello>(x =>
            {
                x.MessageId = context.Id();
                x.Message   = "test";
            });
        }
Beispiel #10
0
        public async Task ShouldNotClaimBucket(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <Identity.User.User>(context.Id()).Exists();
            context.UoW.Plan <Basket>(context.Id())
            .HasEvent <Events.Initiated>(x => { x.BasketId = context.Id(); })
            .HasEvent <Events.BasketClaimed>(x => { x.BasketId = context.Id(); x.UserName = context.Id(); });

            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(new Commands.ClaimBasket
            {
                BasketId = context.Id(),
                UserName = context.Id()
            }, context)).ConfigureAwait(false);
        }
Beispiel #11
0
        public async Task ShouldAddItem(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <Basket>(context.Id())
            .HasEvent <eShop.Basket.Basket.Events.Initiated>(x =>
            {
                x.BasketId = context.Id();
            });
            context.UoW.Plan <Catalog.Product.Product>(context.Id()).Exists();

            await handler.Handle(new Commands.AddItem
            {
                BasketId  = context.Id(),
                ProductId = context.Id()
            }, context).ConfigureAwait(false);

            context.UoW.Check <Basket>(context.Id()).Check <Item>(context.Id()).Raised <Events.ItemAdded>();
        }
Beispiel #12
0
        public async Task ShouldDestroyProduct(
            TestableContext context,
            Handler handler
            )
        {
            context.UoW.Plan <Product>(context.Id()).HasEvent <Events.Added>(x =>
            {
                x.ProductId      = context.Id();
                x.CatalogBrandId = context.Id();
                x.CatalogTypeId  = context.Id();
                x.Name           = "test";
                x.Price          = 1;
            });

            await handler.Handle(new Commands.Remove
            {
                ProductId = context.Id(),
            }, context).ConfigureAwait(false);

            context.UoW.Check <Product>(context.Id()).Raised <Events.Removed>(x =>
            {
                x.ProductId = context.Id();
            });
        }