コード例 #1
0
        public async Task ExecuteScalar_WithNoParameters_ExecuteReturnsExpectedString()
        {
            SqlProgram program = await SqlProgram.Create((Connection)DifferentLocalDatabaseConnectionString, name : "spReturnsScalar");

            string scalarResult = program.ExecuteScalar <string>();

            Assert.AreEqual("HelloWorld", scalarResult);
        }
コード例 #2
0
        public async Task Test_CheckMappedProgramReturnsExpectedResult()
        {
            DatabasesConfiguration configuration = DatabasesConfiguration.Active;

            // Get a program that is mapped by the configuration
            SqlProgram <string> mappedProgram = await configuration.GetSqlProgram <string>("test2", "TestProgram", "@P1");

            // Check the names were mapped.
            Assert.AreEqual("spTakesParamAndReturnsScalar", mappedProgram.Name);
            Assert.AreEqual("@firstName", mappedProgram.Parameters.Single().Key);

            // Check the sproc runs.
            string name   = Guid.NewGuid().ToString().Substring(0, 10);
            string result = mappedProgram.ExecuteScalar <string>(name);

            Assert.AreEqual("Hello " + name, result);
        }
コード例 #3
0
        public async Task ExecuteScalar_WithParameters_ReturnedExpectedString()
        {
            SqlProgram <string, int, decimal, bool> program =
                await SqlProgram <string, int, decimal, bool> .Create((Connection)DifferentLocalDatabaseConnectionString,
                                                                      name : "spWithParametersReturnsScalarString");

            string randomString = Random.RandomString(20, false);
            string scalarResult = program.ExecuteScalar <string>(
                c =>
            {
                c.SetParameter("@stringParam", randomString);
                c.SetParameter("@intParam", AInt);
                c.SetParameter("@decimalParam", ADecimal);
                c.SetParameter("@boolParam", ABool);
            });

            Assert.AreEqual(string.Format("{0} - {1} - {2} - 1", randomString, AInt, ADecimal), scalarResult);
        }
コード例 #4
0
        public async Task ExecuteScalar_WithOutputParameters_ExecutesSuccessfully()
        {
            SqlProgram <int, Out <int>, Out <int> > program =
                await SqlProgram <int, Out <int>, Out <int> > .Create((Connection)LocalDatabaseConnectionString, "spOutputParameters");

            const int inputVal       = 123;
            const int inputOutputVal = 321;

            Out <int> inputOutput = new Out <int>(inputOutputVal);
            Out <int> output      = new Out <int>();

            string scalarResult = program.ExecuteScalar <string>(inputVal, inputOutput, output);

            Assert.AreEqual("<foo>bar</foo>", scalarResult);

            Assert.IsNull(inputOutput.OutputError, inputOutput.OutputError?.Message);
            Assert.IsNull(output.OutputError, output.OutputError?.Message);

            Assert.AreEqual(inputOutputVal * 2, inputOutput.OutputValue.Value);
            Assert.AreEqual(inputVal, output.OutputValue.Value);
        }