|
| 1 | +// Copyright Subatomix Research Inc. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +using System.Collections; |
| 5 | + |
| 6 | +namespace PSql; |
| 7 | + |
| 8 | +[TestFixture] |
| 9 | +public class SqlCmdPreprocessorTests |
| 10 | +{ |
| 11 | + // This test class only backfills coverage gaps in other tests. |
| 12 | + |
| 13 | + [Test] |
| 14 | + public void EnableVariableReplacementInComments_Get() |
| 15 | + { |
| 16 | + new SqlCmdPreprocessor() |
| 17 | + .EnableVariableReplacementInComments.ShouldBeFalse(); |
| 18 | + } |
| 19 | + |
| 20 | + [Test] |
| 21 | + public void EnableVariableReplacementInComments_Set() |
| 22 | + { |
| 23 | + new SqlCmdPreprocessor { EnableVariableReplacementInComments = true } |
| 24 | + .EnableVariableReplacementInComments.ShouldBeTrue(); |
| 25 | + } |
| 26 | + |
| 27 | + [Test] |
| 28 | + public void SetVariables_NullEntries() |
| 29 | + { |
| 30 | + var preprocessor = new SqlCmdPreprocessor(); |
| 31 | + |
| 32 | + preprocessor.SetVariables(null); |
| 33 | + |
| 34 | + preprocessor.Process("a").ShouldBe(["a"]); |
| 35 | + } |
| 36 | + |
| 37 | + [Test] |
| 38 | + public void SetVariables_DictionaryEnumeratesUnexpectedType() |
| 39 | + { |
| 40 | + TestSetVariablesWith(entry: new object()); // Not a DictionaryEntry |
| 41 | + } |
| 42 | + |
| 43 | + [Test] |
| 44 | + public void SetVariables_EntryHasNullKey() |
| 45 | + { |
| 46 | + TestSetVariablesWith(entry: new DictionaryEntry(null!, "value")); |
| 47 | + } |
| 48 | + |
| 49 | + [Test] |
| 50 | + public void SetVariables_EntryHasEmptyKey() |
| 51 | + { |
| 52 | + TestSetVariablesWith(entry: new DictionaryEntry("", "value")); |
| 53 | + } |
| 54 | + |
| 55 | + private static void TestSetVariablesWith(object entry) |
| 56 | + { |
| 57 | + var preprocessor = new SqlCmdPreprocessor(); |
| 58 | + |
| 59 | + var dictionary = new Mock<IDictionary>(MockBehavior.Strict); |
| 60 | + var enumerator = new Mock<IDictionaryEnumerator>(MockBehavior.Strict); |
| 61 | + var sequence = new MockSequence(); |
| 62 | + |
| 63 | + dictionary.InSequence(sequence).Setup(x => x.GetEnumerator()).Returns(enumerator.Object); |
| 64 | + enumerator.InSequence(sequence).Setup(x => x.MoveNext()).Returns(true); |
| 65 | + enumerator.InSequence(sequence).Setup(x => x.Current).Returns(entry); |
| 66 | + enumerator.InSequence(sequence).Setup(x => x.MoveNext()).Returns(false); |
| 67 | + |
| 68 | + preprocessor.SetVariables(dictionary.Object); |
| 69 | + |
| 70 | + preprocessor.Process("a").ShouldBe(["a"]); |
| 71 | + } |
| 72 | +} |
0 commit comments