public int AddProduct(Product info)
 {
     using (var context = new NWContext())
     {
         context.Products.Add(info);
         context.SaveChanges();
         return info.ProductID;
     }
 }
 public void DeleteProduct(Product info)
 {
     using (var context = new NWContext())
     {
         var found = context.Products.Find(info.ProductID);
         if (found != null)
         {
             context.Products.Remove(found);
             context.SaveChanges();
         }
     }
 }
Exemple #3
0
        public void Should_Delete_Products()
        {
            //Arrange
            var sut = new NorthwindManager();
            var actual = new Product()
            {
                ProductName = "Product to delete"
            };
            actual.ProductID = sut.AddProduct(actual);

            //Act
            sut.DeleteProduct(actual);
            //Assert
            Product p = sut.GetProduct(actual.ProductID);

            Assert.Null(p);
        }
Exemple #4
0
        public void Should_Add_Product()
        {
            //Arrange
            var sut = new NorthwindManager();
            var product = new Product()
            {
                ProductName = "MSP Basic Product",
                Discontinued = false
            };

            //Act

            var productID = sut.AddProduct(product);
            //Assert
            Assert.True(productID > 0);
            Product actual = sut.GetProduct(productID);
            Assert.Equal(productID, actual.ProductID);
        }
Exemple #5
0
        public void Should_Add_Product()
        {
            //Arrange
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            var expected = new Product()
            {
                ProductName = "Double Double",
                UnitsInStock = 777
            };

            //Act
            var actualId = sut.AddProduct(expected);

            //Assert
            Assert.True(actualId > 0);
            Product actual = sut.GetProduct(actualId);
            Assert.Equal(expected.ProductName, actual.ProductName);
            Assert.Equal(expected.UnitsInStock, actual.UnitsInStock);
            Assert.Equal(actualId, actual.ProductID);
        }
Exemple #6
0
        public void Should_Update_Products(Product existing)
        {
            //Arrange
            existing.ProductName = "TIN'S OLD PRODUCT";
            var sut = new NorthwindManager();

            //Act
            sut.UpdateProduct(existing);

            //Assert
            var actual = sut.GetProduct(existing.ProductID);
            Assert.NotNull(actual);
            Assert.Equal(existing.ProductName, actual.ProductName);
        }
 public void UpdateProduct(Product info)
 {
     //NOTE: See question and commentary on
     //  http://stackoverflow.com/questions/15336248/entity-framework-5-updating-a-record
     using (var context = new NWContext())
     {
         context.Products.Attach(info);
         context.Entry(info).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemple #8
0
        public void Should_Delete_Product()
        {
            //Arrange
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            var expected = new Product()
            {
                ProductName = "Double Double",
                UnitsInStock = 777
            };

            expected.ProductID = sut.AddProduct(expected);

            //Act
            sut.DeleteProduct(expected);

            //Assert
            Shipper actual = sut.GetShipper(expected.ProductID);
            Assert.Null(actual);
        }
Exemple #9
0
        public void Should_Update_Product(Product existing)
        {
            //Arrange
            existing.UnitsInStock = 777;
            var sut = new NorthwindManager();  //sut is short for 'Scenario Under Test'
            existing.UnitsInStock = 999;

            //Act
            sut.UpdateProduct(existing);

            //Assert
            var actual = sut.GetProduct(existing.ProductID);
            Assert.NotNull(actual);
            Assert.Equal(existing.ProductName, actual.ProductName);
            Assert.Equal(existing.UnitsInStock, actual.UnitsInStock);
        }
Exemple #10
0
        public void UpdateProduct(Product info)
        {
            using (var context = new NWContext())
            {
                context.Products.Attach(info);
                context.Entry(info).State = EntityState.Modified;
                context.SaveChanges();

            }
        }