[InlineData("Run\\ProcedureUnknown", "2")] // Stored Procedure Name not recognized

        public void SpTestRunner_RunProcNonQueryFail(string testPath, string testCase)
        {
            // ARRANGE
            string basePath = "TestCases\\SpRunner\\RunProcNonQuery\\Fail";
            // Save the Connection String and Stored Procedure name in case they are set at the class level
            string savedConn   = SpRunner.ConnectionString;
            string savedSPName = SpRunner.SpName;

            // Temporarily clear the connection string and spName from the class property so the input files can simulate missing values
            SpRunner.ConnectionString = "";
            SpRunner.SpName           = "";


            // Prepare input and expected
            var input    = JsonConvert.DeserializeObject <SpExecInputNonQuery>(File.ReadAllText($"{basePath}\\{testPath}\\input{testCase}.json"));
            var expected = JsonConvert.DeserializeObject <SpExecResultNonQuery>(File.ReadAllText($"{basePath}\\{testPath}\\expected{testCase}.json"));

            ////ACT
            SpExecResultNonQuery actual = SpRunner.RunProcNonQuery(input);

            // restore class level settings for subsequent tests in this same run. Do this before Assert in case an error is thrown during Assert.
            SpRunner.ConnectionString = savedConn;
            SpRunner.SpName           = savedSPName;

            // ASSERT
            Assert.True(actual.ResultText == expected.ResultText);
        }
        public void SpTestRunner_RunProcNonQueryGood(string testPath, string testCase)
        {
            //ARRANGE
            string basePath = "TestCases\\SpRunner\\RunProcNonQuery\\Good";

            // Create the input model
            var input = JsonConvert.DeserializeObject <SpExecInputNonQuery>(File.ReadAllText($"{basePath}\\{testPath}\\input{testCase}.json"));


            // Create the expected model
            var expected = JsonConvert.DeserializeObject <SpExecResultNonQuery>(File.ReadAllText($"{basePath}\\{testPath}\\expected{testCase}.json"));


            ////ACT
            SpExecResultNonQuery actual = SpRunner.RunProcNonQuery(input);

            //TODO Add json trap

            ////ASSERT
            /// SpExecOutput.IsEquivalent method performs deep compare and generates detailed error messages to ResultText property and the Console Log
            /// NOTE!!!
            /// Comparison for SpExecResult.Duration passes when expected Duration is greater than 0 and actual.Duration IS LESS THAN OR EQUAL TO expected.Duration
            /// To disable this check set expected.Duration to 0
            ///
            Assert.True(actual.IsEquivalent(expected));
        }
示例#3
0
        public static SpExecResultNonQuery ExecProcNonQuery(SqlCommand cmd, SpExecInputNonQuery input)
        {
            Stopwatch            stopWatch = new Stopwatch();
            SpExecResultNonQuery result    = new SpExecResultNonQuery();
            SqlTransaction       transaction;
            SqlExecResult        postTestResult;

            //Declare the reader to gather the post run results
            SqlDataReader rdr;


            //Start run timer to record elapsed time
            stopWatch.Start();
            try
            {
                result.ReturnValue = cmd.ExecuteNonQuery();
                //TODO add check for return value??
                stopWatch.Stop();
                result.ResultText = "Success";
            }
            catch (Exception e)
            {
                string errMsg = DebugLogger.CreateErrorDetail("SqlSpClient.Execute", e.Message, e.InnerException?.Message);
                DebugLogger.LogError(errMsg);
                result.ResultText = errMsg;
            }

            //Add duration
            if (stopWatch != null)
            {
                result.Duration = (stopWatch.ElapsedMilliseconds);
            }

            //Capture json output if needed to create test case "expected" records.
            string jsonString = JsonConvert.SerializeObject(result, Formatting.Indented);

            return(result);
        }