public void ToOrderedChangeEvent_Should_ReturnChangeForEachItem()
        {
            var product = ProductFactory.GetProduct("0");

            product.Price.Should().BeApproximately(1.0, 0.000001);

            var changes = ProductFactory.GetProductPriceChanges(product.Id);

            var actual = ChangeFactory.ToOrderedChangeEvent <Product, ProductPriceChange, string, double, DateTime>(
                x => x.Price,
                0.8,
                changes,
                x => x.Id,
                x => x.Price,
                x => x.ChangeDate).ToList();

            Assert.Equal(changes.Count, actual.Count);
            var change1 = actual[0];
            var change2 = actual.Last();

            change1.Revert(product);
            product.Price.Should().BeApproximately(0.8, 0.000001);

            change2.Apply(product);
            product.Price.Should().BeApproximately(changes.Last().Price, 0.000001);
        }
Exemplo n.º 2
0
        internal static List <IEvent <Product, string> > GetChanges(Guid itemId)
        {
            var priceChanges         = ProductFactory.GetProductPriceChanges(itemId).ToList();
            var stockMutationChanges = ProductFactory.GetProductStockMutations(itemId).ToList();

            var changes = ChangeFactory.ToOrderedChangeEvent <Product, ProductPriceChange, string, double, DateTime>(
                x => x.Price,
                0,
                priceChanges,
                x => x.Id,
                x => x.Price,
                x => x.ChangeDate).Cast <IEvent <Product, string> >().ToList();

            changes.AddRange(MutationFactory.ToMutationEvent <Product, ProductStockMutation, string, int>(
                                 x => x.Available,
                                 stockMutationChanges,
                                 x => x.Id,
                                 x => x.ApplyableAmount).Cast <IEvent <Product, string> >());

            changes.AddRange(MutationFactory.ToOrderedMutationEvent <Product, ProductStockMutation, string, int, DateTime>(
                                 x => x.InStock,
                                 stockMutationChanges,
                                 x => x.Id,
                                 x => x.ApplyableAmount,
                                 x => x.DeliveryDate.Date).Cast <IEvent <Product, string> >());

            return(changes);
        }
Exemplo n.º 3
0
        internal static DL.Models.Product SetProduct(ProductStock.DL.Models.Product product)
        {
            if (!ProductStocks.ContainsKey(product.Id))
            {
                ProductStocks.Add(product.Id, product);

                var result = new DL.Models.Product(product.Id, product.Number, product.Description);
                Products.Add(product.Id, result);

                var priceChanges = ChangeFactory.ToOrderedChangeEvent <
                    DL.Models.Product,
                    ProductStock.DL.Models.ProductPrice,
                    Guid,
                    double,
                    DateTimeOffset>(
                    x => x.Price,
                    0,
                    product.Prices,
                    x => x.Id,
                    x => x.Price,
                    x => x.RegisterDate).
                                   Cast <IEvent <DL.Models.Product, Guid> >().ToList();

                var stockAvailableMutations = MutationFactory.ToOrderedMutationEvent <
                    DL.Models.Product,
                    ProductStock.DL.Models.ProductStockMutation,
                    Guid,
                    int,
                    DateTimeOffset>(
                    x => x.Available,
                    product.StockMutations,
                    x => x.Id,
                    x => x.Amount * (x.Type == ProductStock.DL.Enums.MutationType.Purchase ? -1 : 1),
                    x => x.OrderDate).Cast <IEvent <DL.Models.Product, Guid> >().ToList();

                var stockInStockMutations = MutationFactory.ToOrderedMutationEvent <
                    DL.Models.Product,
                    ProductStock.DL.Models.ProductStockMutation,
                    Guid,
                    int,
                    DateTimeOffset>(
                    x => x.InStock,
                    product.StockMutations,
                    x => x.Id,
                    x => x.Amount * (x.Type == ProductStock.DL.Enums.MutationType.Purchase ? -1 : 1),
                    x => x.ShipmentDate).Cast <IEvent <DL.Models.Product, Guid> >().ToList();

                AddEvents(product.Id, new OrderedEventCollection <DL.Models.Product, Guid, DateTimeOffset>(priceChanges.ToList()));
                AddEvents(product.Id, new OrderedEventCollection <DL.Models.Product, Guid, DateTimeOffset>(stockAvailableMutations.ToList()));
                AddEvents(product.Id, new OrderedEventCollection <DL.Models.Product, Guid, DateTimeOffset>(stockInStockMutations.ToList()));

                return(result);
            }

            return(Products[product.Id]);
        }