Пример #1
0
        public async Task ScalarFunctionNoParametersFirstTest()
        {
            string getdate = "getdate";

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

            //	Here's where we call the getdate function
            var now = await mycaller.ScalarFunctionAsync(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));
        }
Пример #2
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 = NUnit.Framework.Assert.ThrowsAsync <SqlException>(async() => await mycaller.ScalarFunctionAsync(divbyzero));

            //	All we do is check that the exception was thrown, and that we handled it.
            Assert.AreEqual("Divide by zero error encountered.", ex.Message);
        }
Пример #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 = NUnit.Framework.Assert.ThrowsAsync <ArgumentException>(async() => await mycaller.ScalarFunctionAsync(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);
        }