using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

using BookShopOnline.Model;
using BookShopOnline.WebConfig;
using BookShopOnline.SQLServerDal;
using NUnit.Framework;

namespace BookShopOnline.TestClass
{
    [TestFixture]
    public class TestShoppingCartDal
    {
        #region 同一个人，不同的图书
        [Test]
        public void TestInsertShoppingCart()
        {
            
            ShoppingCart shoppingCart=new ShoppingCart();
            shoppingCart.BookID=1;
            shoppingCart.CartGuid="sadfsdfs9-23423-23423";
            shoppingCart.Quatity=1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID=shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }

        [Test]
        public void TestInsertShoppingCart2()
        {

            ShoppingCart shoppingCart = new ShoppingCart();
            shoppingCart.BookID = 2;
            shoppingCart.CartGuid = "sadfsdfs9-23423-23423";
            shoppingCart.Quatity = 1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID = shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }
        #endregion

        #region 同一个人，同一本图书
        [Test]
        public void TestInsertShoppingCart3()
        {

            ShoppingCart shoppingCart = new ShoppingCart();
            shoppingCart.BookID = 5;
            shoppingCart.CartGuid = "33333333-333333333";
            shoppingCart.Quatity = 1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID = shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }

        [Test]
        public void TestInsertShoppingCart4()
        {

            ShoppingCart shoppingCart = new ShoppingCart();
            shoppingCart.BookID = 5;
            shoppingCart.CartGuid = "33333333-333333333";
            shoppingCart.Quatity = 1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID = shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }
        #endregion

        #region 不同人，同一本图书
        [Test]
        public void TestInsertShoppingCart5()
        {

            ShoppingCart shoppingCart = new ShoppingCart();
            shoppingCart.BookID = 5;
            shoppingCart.CartGuid = "555555555555-555555";
            shoppingCart.Quatity = 1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID = shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }

        [Test]
        public void TestInsertShoppingCart6()
        {

            ShoppingCart shoppingCart = new ShoppingCart();
            shoppingCart.BookID = 5;
            shoppingCart.CartGuid = "6666666666666-666666";
            shoppingCart.Quatity = 1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID = shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }
        #endregion

        #region 不同人，不同的图书
        [Test]
        public void TestInsertShoppingCart7()
        {

            ShoppingCart shoppingCart = new ShoppingCart();
            shoppingCart.BookID = 4;
            shoppingCart.CartGuid = "777777777777-7777777";
            shoppingCart.Quatity = 1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID = shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }

        [Test]
        public void TestInsertShoppingCart8()
        {

            ShoppingCart shoppingCart = new ShoppingCart();
            shoppingCart.BookID = 5;
            shoppingCart.CartGuid = "888888888888-8888888";
            shoppingCart.Quatity = 1;

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int cartID = shoppingCartDal.InsertShoppingCart(shoppingCart);

            Assert.IsTrue(cartID > 0);
        }
        #endregion

        #region TestSelectShoppingCartByCartGuid
        [Test]
        public void TestSelectShoppingCartByCartGuid()
        {
            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            DataSet ds = shoppingCartDal.SelectShoppingCartByCartGuid("sadfsdfs9-23423-23423");

            Assert.IsTrue(ds.Tables[0].Rows.Count==2);
        }
        #endregion

        #region TestUpdateShoppingCart
        [Test]
        public void TestUpdateShoppingCart()
        {
            IList<ShoppingCart> shoppingCartList = new List<ShoppingCart>();
           
            ShoppingCart shoppingCart1=new ShoppingCart();
            shoppingCart1.CartID=23;
            shoppingCart1.Quatity=10;
            shoppingCartList.Add(shoppingCart1);

            ShoppingCart shoppingCart2 = new ShoppingCart();
            shoppingCart2.CartID = 24;
            shoppingCart2.Quatity = 10;
            shoppingCartList.Add(shoppingCart2);

            ShoppingCartDal shoppingCartDal = new ShoppingCartDal();
            int result= shoppingCartDal.UpdateShoppingCart(shoppingCartList);

            Assert.IsTrue(result == 2);
        }
        #endregion

        #region TestDeleteShoppingCartByCartID
        [Test]
        public void TestDeleteShoppingCartByCartID()
        {
           int result= new ShoppingCartDal().DeleteShoppingCartByCartID(25);

           Assert.IsTrue(result > 0);
        }
        #endregion

        #region DeleteShoppingCartByCartGuid
        [Test]
        public void DeleteShoppingCartByCartGuid()
        {
            int result = new ShoppingCartDal().DeleteShoppingCartByCartGuid("00000000-0000-0000-0000-000000000000");

            Assert.IsTrue(result > 0);
        }
        #endregion
    }
}
