Example #1
0
        public void Test_DeleteItem_RemovesAProductFromCart()
        {
            //Arrange
            User testUser = new User("Allie", "Holcombe", "eylookturkeys", "password", false);

            testUser.Save();
            CartProduct testCartProduct = new CartProduct(testUser.GetId(), 2, 5);

            testCartProduct.Save();
            CartProduct secondCartProduct = new CartProduct(testUser.GetId(), 3, 5);

            secondCartProduct.Save();


            //Act
            testUser.DeleteItem(2);
            List <CartProduct> expected = new List <CartProduct> {
                secondCartProduct
            };
            List <CartProduct> result = testUser.GetCartProducts();

            Console.WriteLine(string.Format("EXPECTED Id: {0}   user_id: {1}   product_id: {2}   quantity: {3}", expected[0].GetId(), expected[0].GetUserId(), expected[0].GetProductId(), expected[0].GetQuantity()));
            Console.WriteLine(string.Format("RESULT Id: {0}   user_id: {1}   product_id: {2}   quantity: {3}", result[0].GetId(), result[0].GetUserId(), result[0].GetProductId(), result[0].GetQuantity()));

            //Assert
            Assert.Equal(expected, result);
        }
Example #2
0
        public void GetTotal_ReturnsTotalPriceOfAllItems_decimal()
        {
            //Arrange
            User testUser = new User("Allie", "Holcombe", "eylookturkeys", "password", false);

            testUser.Save();
            Product firstProduct = new Product("Vegetti", 13, 5, 2.00m, "Great item for shredding zukes");

            firstProduct.Save();
            Product secondProduct = new Product("Vegetti", 13, 5, 20.00m, "Great item for shredding zukes");

            secondProduct.Save();
            CartProduct testCartProduct = new CartProduct(testUser.GetId(), firstProduct.GetId(), 1);

            testCartProduct.Save();
            CartProduct secondCartProduct = new CartProduct(testUser.GetId(), secondProduct.GetId(), 2);

            secondCartProduct.Save();

            //Act
            List <Product> expected = new List <Product> {
                firstProduct, secondProduct
            };
            List <Product> result = testUser.GetCart();

            decimal actualResult   = testUser.GetTotal();
            decimal expectedResult = 42.00m;

            Assert.Equal(expectedResult, actualResult);
        }
Example #3
0
        //Gets the cart_products rows associated with the user
        public List <CartProduct> GetCartProducts()
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT * FROM cart_products WHERE user_id = @UserId;", conn);

            cmd.Parameters.Add(new SqlParameter("@UserId", this.GetId().ToString()));

            SqlDataReader      rdr             = cmd.ExecuteReader();
            List <CartProduct> allCartProducts = new List <CartProduct> {
            };

            while (rdr.Read())
            {
                int id        = rdr.GetInt32(0);
                int userId    = rdr.GetInt32(1);
                int productId = rdr.GetInt32(2);
                int quantity  = rdr.GetInt32(3);

                CartProduct newCartProduct = new CartProduct(userId, productId, quantity, id);
                allCartProducts.Add(newCartProduct);
            }

            DB.CloseSqlConnection(conn, rdr);
            return(allCartProducts);
        }
Example #4
0
        public void GetCartProducts_GetsRowsFromCartProductsTable_List()
        {
            //Arrange
            User testUser = new User("Allie", "Holcombe", "eylookturkeys", "password", false);

            testUser.Save();
            Product firstProduct = new Product("Vegetti", 13, 5, 20.99m, "Great item for shredding zukes");

            firstProduct.Save();
            Product secondProduct = new Product("Vegetti", 13, 5, 20.99m, "Great item for shredding zukes");

            secondProduct.Save();
            CartProduct testCartProduct = new CartProduct(testUser.GetId(), firstProduct.GetId(), 5);

            testCartProduct.Save();
            CartProduct secondCartProduct = new CartProduct(testUser.GetId(), secondProduct.GetId(), 5);

            secondCartProduct.Save();

            //Act
            List <CartProduct> expected = new List <CartProduct> {
                testCartProduct, secondCartProduct
            };
            List <CartProduct> result = testUser.GetCartProducts();

            //Assert
            Assert.Equal(expected, result);
        }
Example #5
0
        public void GetCart_GetAllProductsFromUsersCart_ReturnTheListOfProductsFromTheUser()
        {
            //Arrange
            User testUser = new User("Allie", "Holcombe", "eylookturkeys", "password", false);

            testUser.Save();
            Product firstProduct = new Product("Vegetti", 13, 5, 20.99m, "Great item for shredding zukes");

            firstProduct.Save();
            Product secondProduct = new Product("Vegetti", 13, 5, 20.99m, "Great item for shredding zukes");

            secondProduct.Save();
            CartProduct testCartProduct = new CartProduct(testUser.GetId(), firstProduct.GetId(), 5);

            testCartProduct.Save();
            CartProduct secondCartProduct = new CartProduct(testUser.GetId(), secondProduct.GetId(), 5);

            secondCartProduct.Save();
            CartProduct thirdCartProduct = new CartProduct(1, firstProduct.GetId(), 1);

            thirdCartProduct.Save();

            //Act
            List <Product> expected = new List <Product> {
                firstProduct, secondProduct
            };
            List <Product> result = testUser.GetCart();

            //Assert
            Assert.Equal(expected, result);
        }
Example #6
0
        public void EmptyCart_RemovesAllProductsFromUsersCart_void()
        {
            //Arrange
            User testUser = new User("Allie", "Holcombe", "eylookturkeys", "password", false);

            testUser.Save();
            CartProduct testCartProduct = new CartProduct(testUser.GetId(), 2, 5);

            testCartProduct.Save();
            CartProduct secondCartProduct = new CartProduct(testUser.GetId(), 3, 5);

            secondCartProduct.Save();
            CartProduct thirdCartProduct = new CartProduct(1, 3, 1);

            thirdCartProduct.Save();

            //Act
            testUser.EmptyCart();
            List <CartProduct> expected = new List <CartProduct> {
                thirdCartProduct
            };
            List <CartProduct> result = CartProduct.GetAll();

            //Assert
            Assert.Equal(expected, result);
        }
Example #7
0
        //Gets all rows in cartproducts
        public static List <CartProduct> GetAll()
        {
            List <CartProduct> allCartProducts = new List <CartProduct> {
            };

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand    cmd = new SqlCommand("SELECT * FROM cart_products;", conn);
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int         cartProductId  = rdr.GetInt32(0);
                int         userId         = rdr.GetInt32(1);
                int         productId      = rdr.GetInt32(2);
                int         quantity       = rdr.GetInt32(3);
                CartProduct newCartProduct = new CartProduct(userId, productId, quantity, cartProductId);
                allCartProducts.Add(newCartProduct);
            }

            DB.CloseSqlConnection(conn, rdr);
            return(allCartProducts);
        }
Example #8
0
        public static CartProduct Find(int id)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("SELECT * FROM cart_products WHERE id = @ProductId;", conn);

            cmd.Parameters.Add(new SqlParameter("@ProductId", id.ToString()));
            SqlDataReader rdr = cmd.ExecuteReader();

            int cartProductId = 0;
            int userId        = 0;
            int productId     = 0;
            int quantity      = 0;

            while (rdr.Read())
            {
                cartProductId = rdr.GetInt32(0);
                userId        = rdr.GetInt32(1);
                productId     = rdr.GetInt32(2);
                quantity      = rdr.GetInt32(3);
            }
            CartProduct foundCartProduct = new CartProduct(userId, productId, quantity, cartProductId);

            DB.CloseSqlConnection(conn, rdr);
            return(foundCartProduct);
        }
        public void EqualOverride_CartProductsAreSame_true()
        {
            //Arrange, Act
            CartProduct firstCartProduct  = new CartProduct(2, 2, 5);
            CartProduct secondCartProduct = new CartProduct(2, 2, 5);

            Assert.Equal(firstCartProduct, secondCartProduct);
        }
Example #10
0
 public void Dispose()
 {
     User.DeleteAll();
     Product.DeleteAll();
     Review.DeleteAll();
     Profile.DeleteAll();
     CartProduct.DeleteAll();
 }
        public void GetAll_ForNoCartProducts_EmptyList()
        {
            //Arrange, Act, Assert
            List <CartProduct> actualResult   = CartProduct.GetAll();
            List <CartProduct> expectedResult = new List <CartProduct> {
            };

            Assert.Equal(expectedResult, actualResult);
        }
        public void UpdateQuantity_ChangesCartProductQuantity_void()
        {
            CartProduct testCartProduct = new CartProduct(2, 2, 2);

            testCartProduct.Save();

            testCartProduct.UpdateQuantity(5);

            int expectedResult = 5;
            int actualResult   = testCartProduct.GetQuantity();

            Assert.Equal(expectedResult, actualResult);
        }
        public void Test_Find_FindsCartProductInDatabase()
        {
            //Arrange
            CartProduct testCartProduct = new CartProduct(2, 2, 5);

            testCartProduct.Save();
            // CartProduct secondCartProduct = new CartProduct(1,3,5);
            // secondCartProduct.Save();

            //Act
            CartProduct foundCartProduct = CartProduct.Find(testCartProduct.GetId());

            //Assert
            Assert.Equal(testCartProduct, foundCartProduct);
        }
        public void Save_ForCartProduct_SavesToDatabase()
        {
            //Arrange
            CartProduct newCartProduct = new CartProduct(2, 2, 5);

            //Act
            newCartProduct.Save();

            //Assert
            List <CartProduct> actualResult   = CartProduct.GetAll();
            List <CartProduct> expectedResult = new List <CartProduct> {
                newCartProduct
            };

            Assert.Equal(expectedResult, actualResult);
        }
Example #15
0
 public override bool Equals(System.Object otherCartProduct)
 {
     if (!(otherCartProduct is CartProduct))
     {
         return(false);
     }
     else
     {
         CartProduct newCartProduct    = (CartProduct)otherCartProduct;
         bool        idEquality        = this.GetId() == newCartProduct.GetId();
         bool        userIdEquality    = this.GetUserId() == newCartProduct.GetUserId();
         bool        productIdEquality = this.GetProductId() == newCartProduct.GetProductId();
         bool        quantityEquality  = this.GetQuantity() == newCartProduct.GetQuantity();
         return(idEquality && userIdEquality && productIdEquality && quantityEquality);
     }
 }
        public void Test_DeleteItem_RemovesAProductFromCart()
        {
            //Arrange
            CartProduct testCartProduct = new CartProduct(2, 2, 5);

            testCartProduct.Save();
            CartProduct secondCartProduct = new CartProduct(1, 3, 5);

            secondCartProduct.Save();

            //Act
            testCartProduct.DeleteItem();
            List <CartProduct> expected = new List <CartProduct> {
                secondCartProduct
            };
            List <CartProduct> result = CartProduct.GetAll();

            Console.WriteLine(string.Format("EXPECTED Id: {0}   user_id: {1}   product_id: {2}   quantity: {3}", expected[0].GetId(), expected[0].GetUserId(), expected[0].GetProductId(), expected[0].GetQuantity()));
            Console.WriteLine(string.Format("RESULT Id: {0}   user_id: {1}   product_id: {2}   quantity: {3}", result[0].GetId(), result[0].GetUserId(), result[0].GetProductId(), result[0].GetQuantity()));

            //Assert
            Assert.Equal(expected, result);
        }
Example #17
0
        public void Checkout_ChecksoutProductsFromUser_updatesTables()
        {
            //Arrange
            User testUser = new User("Allie", "Holcombe", "eylookturkeys", "password", false);

            testUser.Save();
            Product firstProduct = new Product("Vegetti", 13, 5, 2.00m, "Great item for shredding zukes");

            firstProduct.Save();
            Product secondProduct = new Product("Banana Corer", 13, 5, 20.99m, "Kind of weird");

            secondProduct.Save();
            CartProduct testCartProduct = new CartProduct(testUser.GetId(), firstProduct.GetId(), 5);

            testCartProduct.Save();
            CartProduct secondCartProduct = new CartProduct(testUser.GetId(), secondProduct.GetId(), 2);

            secondCartProduct.Save();

            //Act
            testUser.Checkout();

            //Checks that count was Updated
            int expectedCount = 8;
            // int actualCount = firstProduct.GetCount();
            int actualCount = Product.Find(firstProduct.GetId()).GetCount();

            Assert.Equal(expectedCount, actualCount);

            //Checks that cart is empty
            List <Product> expectedCart = new List <Product> {
            };
            List <Product> actualCart   = testUser.GetCart();

            Assert.Equal(expectedCart, actualCart);
        }
 //clears all rows in table
 public void Dispose()
 {
     CartProduct.DeleteAll();
 }