Beispiel #1
0
        public void ScalarFunctionThrowDivideByZeroTest()
        {
            string divbyzero = "[dbydbtest].[DivideByZero]";

            dbyDB mycaller = new dbyDB(m_connectionstring);

            //	This is just a call to a scalar function that returns 1/0.
            var ex = Assert.Throws <SqlException>(() => mycaller.ScalarFunction(divbyzero));

            //	**LOOKOUT!!** Note that the class library itself does the bare minimum here. Rather than translate all (or any)
            //	of the SqlExceptions into corresponding non-sql exceptions, we leave you to do that.
            //	Now we check the details of the exception
            Assert.AreEqual("Divide by zero error encountered.", ex.Message);
        }
Beispiel #2
0
        public void ScalarFunctionNoParametersSecondTest()
        {
            string getdate = "getdate()";

            //	All we want to do is find out what time it is
            dbyDB mycaller = new dbyDB(m_connectionstring);

            var now = mycaller.ScalarFunction(getdate);

            Assert.IsNotNull(now);

            //	Better parse the results of our efforts so as to check that it's really a datetime
            DateTime nowdt;

            Assert.IsTrue(DateTime.TryParse(now.ToString(), out nowdt));
        }
Beispiel #3
0
        public void EmptyConnectionStringTest()
        {
            //	This test checks to see what would happen if we tried to run with a null connection string
            string mynullstring = null;

            string getdate = "getdate";

            //	All we want to do is find out what time it is
            dbyDB mycaller = new dbyDB(mynullstring);

            //	Valid sql with an empty connection string
            var ex = Assert.Throws <ArgumentException>(() => mycaller.ScalarFunction(getdate));

            //	Now we check the details of the exception
            Assert.AreEqual("Connection string parameter cannot be null, empty or whitespace (Parameter 'm_connectionstring')", ex.Message);
            Assert.AreEqual(nameof(m_connectionstring), ex.ParamName);
        }