Exemple #1
0
        public void IncreaseQuantity_WhenAddingExistingProduct()
        {
            var basketId = Guid.NewGuid();
            var itemId   = Guid.NewGuid();
            var basket   = new Basket().LoadFromHistory <Basket>(new Event[]
            {
                new BasketCreatedEvent(basketId, Customer, Country, DateTimeOffset.UtcNow),
                new NewProductAddedEvent(basketId, new ProductBasketItem
                {
                    ProductId   = 1234,
                    VariantId   = 1235,
                    Description = "boots",
                    ItemId      = itemId,
                    Price       = new ProductPrice(12.99, "£"),
                    Quantity    = 1
                })
            });

            var addProductResult = basket.AddVariant(new Variant
            {
                ProductId   = 1234,
                VariantId   = 1235,
                Description = "boots",
                GbpPrice    = 15.99
            }, 3);

            Assert.IsAssignableFrom <AddProductResult.ProductUpdated>(addProductResult);
            basket.ShouldHaveUncommitted <ExistingProductUpdatedEvent>()
            .WithProperty(e => e.ItemId, itemId)
            .WithProperty(e => e.Quantity, 3)
            .WithProperty(e => e.Item.VariantId, 1235)
            .WithProperty(e => e.Item.GbpPrice, 15.99)
            .AssertAll();
        }
Exemple #2
0
        public void ReturnMaxQuantityExceeded_WhenAddingExistingProductExceedsMaxQuantity()
        {
            var basketId = Guid.NewGuid();
            var itemId   = Guid.NewGuid();
            var basket   = new Basket().LoadFromHistory <Basket>(new Event[]
            {
                new BasketCreatedEvent(basketId, Customer, Country, DateTimeOffset.UtcNow),
                new NewProductAddedEvent(basketId, new ProductBasketItem
                {
                    ProductId   = 1234,
                    VariantId   = 1235,
                    Description = "boots",
                    ItemId      = itemId,
                    Price       = new ProductPrice(12.99, "£"),
                    Quantity    = 5
                })
            });

            var addProductResult = basket.AddVariant(new Variant
            {
                ProductId   = 1234,
                VariantId   = 1235,
                Description = "boots",
                GbpPrice    = 15.99
            }, 7);

            Assert.IsAssignableFrom <AddProductResult.QuantityExceeded>(addProductResult);
            Assert.Equal(addProductResult.Messages.First(), "Maximum item quantity exceeded by 2.");
            Assert.Empty(basket.GetUncommittedChanges());
        }
Exemple #3
0
        public void AddProduct()
        {
            var basketId = Guid.NewGuid();
            var basket   = new Basket().LoadFromHistory <Basket>(new []
            {
                new BasketCreatedEvent(basketId, Customer, Country, DateTimeOffset.UtcNow)
            });

            var addProductResult = basket.AddVariant(new Variant
            {
                ProductId   = 1234,
                VariantId   = 1235,
                Description = "boots",
                GbpPrice    = 12.99
            }, 1);

            Assert.IsAssignableFrom <AddProductResult.NewProductAdded>(addProductResult);
            basket.ShouldHaveUncommitted <NewProductAddedEvent>()
            .WithProperty(e => e.AggregateId, basketId)
            .WithProperty(e => e.ProductBasketItem.VariantId, 1235)
            .AssertAll();
        }