Example #1
0
        public void TestProductSelect()
        {
            using (var context = new LojaZeroDbContextFactory().CreateDbContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var prod = new Product()
                {
                    Name        = "Sorvete",
                    Description = "melhor Sorvete do mundo",
                    Value       = 20,
                    Weight      = 10,
                    Stock       = 10
                };

                var cart = new ShoppingCart()
                {
                    ProductSelects = new List <ProductSelect>()
                    {
                        new ProductSelect()
                        {
                            Product = prod,
                            Qtd     = 3
                        }
                    }
                };

                context.ShoppingCarts.Add(cart);
                context.SaveChanges();

                prod       = context.Products.FirstOrDefault(a => a.Id == 1);
                prod.Value = 10;
                context.SaveChanges();

                var     shopCart = context.ShoppingCarts.FirstOrDefault(a => a.Id == 1);
                decimal value    = 0;
                foreach (var product in shopCart.ProductSelects)
                {
                    value = product.UnitValue;
                }
                Assert.AreEqual(20, value);
            }
        }
Example #2
0
        static void Main()
        {
            var context = new LojaZeroDbContextFactory().CreateDbContext();

            var pro = new ProductDAL(context);

            var cli = new ClientDAL(context);

            var product = new Product()
            {
                Name        = "sorvete",
                Description = "sorvete muito bom",
                Stock       = 10,
                Value       = 1.3m,
                Weight      = 1,
                ProductTags = new List <ProductTag>()
                {
                    new ProductTag()
                    {
                        Tag = new Tag()
                        {
                            Name = "Comida"
                        }
                    },
                    new ProductTag()
                    {
                        Tag = new Tag()
                        {
                            Name = "delicia"
                        }
                    }
                }
            };

            var client = new Client()
            {
                FirstName  = "Felipe",
                LastName   = "pinheiro",
                CPF        = "012.109.651-35",
                DtBirthDay = new DateTime(1985, 5, 1),
                Gender     = Gender.Male,
                User       = new UserPerson()
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                },
                Phones = new List <Phone>()
                {
                    new Phone()
                    {
                        AreaCode    = 61,
                        CountryCode = 55,
                        Number      = 995599415
                    }
                },
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        Country  = "brasil",
                        State    = "DF",
                        City     = "Brasilia",
                        District = "taguatiga",
                        Number   = 25,
                        Street   = "qnb 03",
                        ZipCode  = 72115030
                    }
                }
            };

            pro.Create(product);
            cli.Create(client);

            Console.WriteLine(pro.Exist(1));
        }