Exemplo n.º 1
0
        public void TestUpsertProductModifiers()
        {
            TestHandler.Handle((DbContextOptions <POSContext> options) => {
                var productId = 1;

                using (var context = new POSContext(options))
                {
                    context.CreateProductData();
                    context.CreateModifierData(total: 2, totalItemModifier: 2);
                    context.SaveChanges();


                    context.Add(new ProductModifier {
                        ModifierId = 1, ProductId = 1
                    });
                    context.SaveChanges();


                    var dto = new List <ProductModifier>()
                    {
                        new ProductModifier {
                            ProductId = productId, ModifierId = 1
                        },
                        new ProductModifier {
                            ProductId = productId, ModifierId = 2
                        },
                    };

                    //assert add one more
                    var productService = new ProductService(context);
                    var product        = productService.GetProduct(productId).Result;
                    productService.UpsertDeleteProductModifiers(product, dto);
                    context.SaveChanges();

                    Assert.AreEqual(2, context.Product.FirstOrDefault().ProductModifier.Count());
                }

                using (var context = new POSContext(options))
                {
                    //asssert remove all
                    var dto = new List <ProductModifier>()
                    {
                    };
                    var productService = new ProductService(context);
                    var product2       = productService.GetProduct(productId).Result;
                    productService.UpsertDeleteProductModifiers(product2, dto);
                    context.SaveChanges();

                    Assert.AreEqual(0, context.Product.FirstOrDefault().ProductModifier.Count());
                }
            });
        }