-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
CommandBuilderTests.cs
58 lines (48 loc) · 2.6 KB
/
CommandBuilderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.Data.Odbc.Tests
{
public class CommandBuilderTests : IntegrationTestBase
{
[ConditionalFact]
public void QuoteIdentifier_UseConnection()
{
var commandBuilder = new OdbcCommandBuilder();
// Get quote string
var quotedIdentifier = commandBuilder.QuoteIdentifier("Test", connection);
var qs = quotedIdentifier.Remove(quotedIdentifier.IndexOf("Test"));
Assert.NotEmpty(qs);
// Test -> 'Test'
var quotedTestString = commandBuilder.QuoteIdentifier("Source", connection);
Assert.Equal($"{qs}Source{qs}", quotedTestString);
// 'Test' -> Test
Assert.Equal("Source", commandBuilder.UnquoteIdentifier(quotedTestString, connection));
// Test' -> 'Test'''
quotedTestString = commandBuilder.QuoteIdentifier($"Test identifier{qs}", connection);
Assert.Equal($"{qs}Test identifier{qs}{qs}{qs}", quotedTestString);
// 'Test''' -> Test'
Assert.Equal($"Test identifier{qs}", commandBuilder.UnquoteIdentifier(quotedTestString, connection));
// Needs an active connection
Assert.Throws<InvalidOperationException>(() => commandBuilder.QuoteIdentifier("Test", null));
Assert.Throws<InvalidOperationException>(() => commandBuilder.QuoteIdentifier("Test"));
Assert.Throws<InvalidOperationException>(() => commandBuilder.UnquoteIdentifier("Test", null));
Assert.Throws<InvalidOperationException>(() => commandBuilder.UnquoteIdentifier("Test"));
}
[ConditionalFact]
public void QuoteIdentifier_CustomPrefixSuffix()
{
var commandBuilder = new OdbcCommandBuilder();
// Custom prefix & suffix
commandBuilder.QuotePrefix = "'";
commandBuilder.QuoteSuffix = "'";
Assert.Equal("'Test'", commandBuilder.QuoteIdentifier("Test", connection));
Assert.Equal("'Te''st'", commandBuilder.QuoteIdentifier("Te'st", connection));
Assert.Equal("Test", commandBuilder.UnquoteIdentifier("'Test'", connection));
Assert.Equal("Te'st", commandBuilder.UnquoteIdentifier("'Te''st'", connection));
// Ensure we don't need active connection:
Assert.Equal("'Test'", commandBuilder.QuoteIdentifier("Test", null));
Assert.Equal("Test", commandBuilder.UnquoteIdentifier("'Test'", null));
}
}
}