コード例 #1
0
 public void ExtractQuotedTest()
 {
     Assert.AreEqual("hello", ErrorMessageParser.ExtractQuotedText("hello"));
     Assert.AreEqual("hello", ErrorMessageParser.ExtractQuotedText("\"hello\""));
     Assert.AreEqual("hello", ErrorMessageParser.ExtractQuotedText("!!\"hello\""));
     Assert.AreEqual("hello", ErrorMessageParser.ExtractQuotedText("\"hello\"!!"));
     Assert.AreEqual("hello", ErrorMessageParser.ExtractQuotedText("!!\"hello\"!!"));
     Assert.AreEqual(string.Empty, ErrorMessageParser.ExtractQuotedText("\"\"!!"));
 }
コード例 #2
0
        public void RealMessagesTest()
        {
            var parser = CreateParser(true,
                                      "Cannot insert the value NULL into column '%.*ls', table '%.*ls'; column does not allow nulls. %ls fails.",
                                      "The %ls statement conflicted with the %ls constraint \"%.*ls\". The conflict occurred in database \"%.*ls\", table \"%.*ls\"%ls%.*ls%ls.",
                                      "Cannot insert duplicate key row in object '%.*ls' with unique index '%.*ls'. The duplicate key value is %ls.",
                                      "Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'. The duplicate key value is %ls.");

            const string canNotInsertNull = "Cannot insert the value NULL into column 'col', table 'DO40-Tests.dbo.Table_1'; column does not allow nulls. INSERT fails.";
            var          result           = parser.Parse(1, canNotInsertNull);

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual("col", result[1]);
            Assert.AreEqual("Table_1", ErrorMessageParser.CutDatabaseAndSchemaPrefix(result[2]));
            Assert.AreEqual("INSERT", result[3]);

            const string violationOfForeignKey = "The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_Table_2_Table_1\". The conflict occurred in database \"DO40-Tests\", table \"dbo.Table_1\", column 'col'.";

            result = parser.Parse(2, violationOfForeignKey);
            Assert.AreEqual(6, result.Count);
            Assert.AreEqual("INSERT", result[1]);
            Assert.AreEqual("FOREIGN KEY", result[2]);
            Assert.AreEqual("FK_Table_2_Table_1", result[3]);
            Assert.AreEqual("DO40-Tests", result[4]);
            Assert.AreEqual("Table_1", ErrorMessageParser.CutSchemaPrefix(result[5]));
            Assert.AreEqual("col", ErrorMessageParser.ExtractQuotedText(result[6]));

            const string canNotInsertDuplicateKey = "Cannot insert duplicate key row in object 'dbo.Table_1' with unique index 'Test'. The duplicate key value is (1).";

            result = parser.Parse(3, canNotInsertDuplicateKey);
            Assert.AreEqual(3, result.Count);
            Assert.AreEqual("Table_1", ErrorMessageParser.CutSchemaPrefix(result[1]));
            Assert.AreEqual("Test", result[2]);
            Assert.AreEqual("(1)", result[3]);

            const string violationOfPrimaryKey = "Violation of PRIMARY KEY constraint 'PK_Table_1'. Cannot insert duplicate key in object 'dbo.Table_1'. The duplicate key value is (1).";

            result = parser.Parse(4, violationOfPrimaryKey);
            Assert.AreEqual(4, result.Count);
            Assert.AreEqual("PRIMARY KEY", result[1]);
            Assert.AreEqual("PK_Table_1", result[2]);
            Assert.AreEqual("Table_1", ErrorMessageParser.CutSchemaPrefix(result[3]));
            Assert.AreEqual("(1)", result[4]);
        }