public void AddProductShouldAddProduct()
        {
            using (var context = new Entity.MochaMomentDBContext(options)) {
                IRepository _repo = new RepoDB(context);
                _repo.AddProduct(new Model.Product("Espresso", 1.99, "Espresso?"));
            }

            using (var assertContext = new Entity.MochaMomentDBContext(options)) {
                var result = assertContext.Products.FirstOrDefault(product => product.ProductId == 3);
                Assert.NotNull(result);
                Assert.Equal("Espresso", result.ItemName);
            }
        }
        public void AddLineItemShouldAddLineItem()
        {
            using (var context = new Entity.MochaMomentDBContext(options)) {
                IRepository _repo = new RepoDB(context);
                _repo.AddCustomer(new Model.Customer("firstName", "lastName", "birthdate", "phone#", "email", "Mailing Address"));
                _repo.AddLocation(new Model.Location("name", "address", "city", "state"));
                _repo.AddProduct(new Model.Product("name", 1.99, "description"));
                _repo.AddOrder(new Model.Order(1, 1, 1, 1.99, ""), new Model.Location("name", "address", "city", "state"), new Model.Customer("firstName", "lastName", "birthdate", "phone#", "email", "Mailing Address"));
                _repo.AddLineItem(new Model.LineItem(1, 1, 1), new Model.Product("name", 1.99, "description"));
            }

            using (var assertContext = new Entity.MochaMomentDBContext(options)) {
                var result = assertContext.LineItems.FirstOrDefault(li => li.LineItemId == 1);
                Assert.NotNull(result);
                Assert.Equal(1, result.Quantity);
            }
        }
예제 #3
0
 public void AddProduct()
 {
     using (var context = new Entity.StoreAppDBContext(options))
     {
         IRepository _repo = new RepoDB(context);
         _repo.AddProduct(
             new Model.Product("BBT", 3.00m, "BBT01")
             );
     }
     using (var assertContext = new Entity.StoreAppDBContext(options))
     {
         //IRepository _repo = new RepoDB(assertContext);
         var result = assertContext.Products.FirstOrDefault(c => c.Id == 3);
         Assert.NotNull(result);
         Assert.Equal("BBT", result.Name);
     }
 }
예제 #4
0
        public void TestProductBeingAdded()
        {
            // var mockRepo = new Mock<IRepository>();
            Product c = new Product("My Product", 12.99);
            using (var context = new StoreDBContext(options)){
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                IRepository _repo = new RepoDB(context);
                _repo.AddProduct(c);

            }
            //Using a new context check for Product
            using (var context = new StoreDBContext(options)){
                IRepository _repo = new RepoDB(context);
                List<Product> cs = _repo.GetAllProducts();
                Product cdb = cs.ToArray()[0];
                Assert.Equal(c.Name, cdb.Name);
                Assert.Equal(c.Price, cdb.Price);
                Assert.True(cs.Count == 1);
                Assert.Equal(c.ProductID, cdb.ProductID);
                context.Database.EnsureDeleted();

               }
        }