예제 #1
0
        public void TestSetQueryParameters()
        {
            // Initialize
            string         expression = "Id >= %0 AND Id <= %1";
            string         parameter1 = "0";
            string         parameter2 = "10";
            QueryCondition condition  = _reader.CreateQueryCondition(expression, parameter1, parameter2);

            Assert.IsNotNull(condition);

            // Test with null parameter
            ReturnCode result = condition.SetQueryParameters(null);

            Assert.AreEqual(ReturnCode.BadParameter, result);

            // Test with incorrect number of parameters
            result = condition.SetQueryParameters(parameter1);
            Assert.AreEqual(ReturnCode.Error, result);

            // Test with new parameters
            parameter1 = "20";
            parameter2 = "30";
            result     = condition.SetQueryParameters(parameter1, parameter2);
            Assert.AreEqual(ReturnCode.Ok, result);

            List <string> parameters = new List <string>();

            result = condition.GetQueryParameters(parameters);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(parameters);
            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual(parameter1, parameters[0]);
            Assert.AreEqual(parameter2, parameters[1]);
        }
예제 #2
0
        public void TestGetQueryParameters()
        {
            // Create a QueryCondition
            string         expression = "Id >= %0 AND Id <= %1";
            string         parameter1 = "0";
            string         parameter2 = "10";
            QueryCondition condition  = _reader.CreateQueryCondition(expression, parameter1, parameter2);

            Assert.IsNotNull(condition);

            // Test with null parameter
            ReturnCode result = condition.GetQueryParameters(null);

            Assert.AreEqual(ReturnCode.BadParameter, result);

            // Test with correct parameter
            List <string> parameters = new List <string>();

            result = condition.GetQueryParameters(parameters);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(parameters);
            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual(parameter1, parameters[0]);
            Assert.AreEqual(parameter2, parameters[1]);

            // Test without query parameters
            expression = "Id >= 0 AND Id <= 10";
            QueryCondition otherCondition = _reader.CreateQueryCondition(expression);

            Assert.IsNotNull(otherCondition);

            result = otherCondition.GetQueryParameters(parameters);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(parameters);
            Assert.AreEqual(0, parameters.Count);
        }