示例#1
0
        public void TestMethodInsertIntoUserData()
        {
            Boolean expectedInsert   = true;
            Boolean expectedDelete   = true;
            string  expectedUserName = "******";
            string  expectedPassword = "******";
            string  expectedFullName = "John Sampleson";
            string  expectedType     = "SA";

            List <object> bookstore = new List <object>(
                new object[] { expectedUserName, expectedPassword, expectedType, 0, expectedFullName }
                );

            Boolean actualInsert = dbQ.INSERT_INTO_TABLE("UserData", bookstore);    //Insert method for database

            Assert.AreEqual(expectedInsert, actualInsert);

            ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM UserData WHERE UserName = '******'");
            string actualUserName = ds.Tables[0].Rows[0]["UserName"].ToString();
            string actualPassword = ds.Tables[0].Rows[0]["Password"].ToString();
            string actualFullName = ds.Tables[0].Rows[0]["FullName"].ToString();
            string actualType     = ds.Tables[0].Rows[0]["Type"].ToString();

            Assert.AreEqual(expectedUserName, actualUserName);
            Assert.AreEqual(expectedPassword, actualPassword);
            Assert.AreEqual(expectedFullName, actualFullName);
            Assert.AreEqual(expectedType, actualType);

            Boolean actualDelete = dbQ.DELETE_FROM_TABLE("DELETE FROM UserData WHERE UserName = '******'");

            Assert.AreEqual(expectedDelete, actualDelete);
        }
        public void TestMethodRegisterUser()
        {
            inputName      = "TestUser";
            inputPassword  = "******";
            inputPasswordV = "ts0987";
            inputFullName  = "TestUserFull";

            bool expectedRegister = true;
            bool expectedLogin    = true;
            bool expectedDelete   = true;

            var c = new SqlConnection(Properties.Settings.Default.dbConnectionString);

            bool actualRegister = userRegister.Register(inputName, inputPassword, inputPasswordV, inputFullName);
            bool actualLogin    = userData.LogIn(inputName, inputPassword);
            int  actualUserId   = userData.UserID;

            ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM UserData WHERE UserName = '******'");
            int expectedUserId = Int32.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());

            Assert.AreEqual(expectedRegister, actualRegister);
            Assert.AreEqual(expectedLogin, actualLogin);
            Assert.AreEqual(expectedUserId, actualUserId);

            DBDelete dbD          = new DBDelete();
            bool     actualDelete = dbD.deleteRow("DELETE FROM UserData WHERE UserName = '******'", c);

            Assert.AreEqual(expectedDelete, actualDelete);
            c.Close();
        }
示例#3
0
        public void TestMethodDeleteFromSupplier()
        {
            var     c = new SqlConnection(Properties.Settings.Default.dbConnectionString);
            Boolean expectedInsert     = true;
            Boolean expectedDelete     = true;
            string  expectedName       = "Google";
            int     expectedSupplierID = dbG.GetID("Supplier", c);

            List <object> bookstore = new List <object>(
                new object[] { expectedName }
                );

            Boolean actualInsert = dbQ.INSERT_INTO_TABLE("Supplier", bookstore);

            Assert.AreEqual(expectedInsert, actualInsert);

            ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM Supplier WHERE Name = '" + expectedName + "'");
            int    actualSupplierID = Int32.Parse(ds.Tables[0].Rows[0]["SupplierId"].ToString());
            string actualName       = ds.Tables[0].Rows[0]["Name"].ToString();

            Assert.AreEqual(expectedSupplierID, actualSupplierID);
            Assert.AreEqual(expectedName, actualName);

            //Delete from Database
            Boolean actualDelete = dbQ.DELETE_FROM_TABLE("DELETE FROM Supplier WHERE Name = '" + expectedName + "'");

            Assert.AreEqual(expectedDelete, actualDelete);

            Boolean expectedFinalDeleteReturn = true;
            Boolean finalDeleteReturn         = false;

            ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM Supplier WHERE Name = '" + expectedName + "'");

            if (ds.Tables[0].Rows.Count == 0)
            {
                finalDeleteReturn = true;
            }

            Assert.AreEqual(expectedFinalDeleteReturn, finalDeleteReturn);
            c.Close();
        }
示例#4
0
        public void TestDatabaseSelectFromBookData()
        {
            int    expectedCategoryID  = 2;
            int    expectedSupplierID  = 1;
            int    expectedYear        = 2002;
            int    expectedEdition     = 1;
            double expectedPrice       = 70.40;
            string expectedISBN        = "0135974445";
            string expectedTitle       = "Agile Software Development, Principles, Patterns, and Practices";
            string expectedAuthor      = "Robert C. Martin";
            string expectedPublisher   = "Pearson";
            string expectedDescription = "Written by a software developer for software developers, this book is a unique collection of the latest software development methods. The author includes OOD, UML, Design Patterns, Agile and XP methods with a detailed description of a complete software design for reusable programs in C++ and Java.";

            ds = dbQ.SELECT_FROM_TABLE("SELECT * FROM BookData WHERE ISBN = '" + expectedISBN + "'");
            int    actualCategoryID  = Int32.Parse(ds.Tables[0].Rows[0]["CategoryID"].ToString());
            int    actualSupplierID  = Int32.Parse(ds.Tables[0].Rows[0]["SupplierId"].ToString());
            int    actualYear        = Int32.Parse(ds.Tables[0].Rows[0]["Year"].ToString());
            int    actualEdition     = Int32.Parse(ds.Tables[0].Rows[0]["Edition"].ToString());
            double actualPrice       = Double.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
            string actualISBN        = ds.Tables[0].Rows[0]["ISBN"].ToString();
            string actualTitle       = ds.Tables[0].Rows[0]["Title"].ToString();
            string actualAuthor      = ds.Tables[0].Rows[0]["Author"].ToString();
            string actualPublisher   = ds.Tables[0].Rows[0]["Publisher"].ToString();
            string actualDescription = ds.Tables[0].Rows[0]["Description"].ToString();

            Assert.AreEqual(expectedCategoryID, actualCategoryID);
            Assert.AreEqual(expectedSupplierID, actualSupplierID);
            Assert.AreEqual(expectedYear, actualYear);
            Assert.AreEqual(expectedEdition, actualEdition);
            Assert.AreEqual(expectedPrice, actualPrice);
            Assert.AreEqual(expectedISBN, actualISBN);
            Assert.AreEqual(expectedTitle, actualTitle);
            Assert.AreEqual(expectedAuthor, actualAuthor);
            Assert.AreEqual(expectedPublisher, actualPublisher);
            Assert.AreEqual(expectedDescription, actualDescription);
        }