|
| 1 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 2 | +using SQLite.CodeFirst.Utility; |
| 3 | + |
| 4 | +namespace SQLite.CodeFirst.Test.Utility |
| 5 | +{ |
| 6 | + [TestClass] |
| 7 | + public class ConnectionStringParserTest |
| 8 | + { |
| 9 | + [TestMethod] |
| 10 | + public void GetDataSource_ReturnsCorrectDataSource() |
| 11 | + { |
| 12 | + // Arrange |
| 13 | + string connectionString = @"data source=.\db\footballDb\footballDb.sqlite;foreign keys=true"; |
| 14 | + |
| 15 | + |
| 16 | + // Act |
| 17 | + string result = ConnectionStringParser.GetDataSource(connectionString); |
| 18 | + |
| 19 | + // Assert |
| 20 | + Assert.AreEqual(@".\db\footballDb\footballDb.sqlite", result); |
| 21 | + } |
| 22 | + |
| 23 | + [TestMethod] |
| 24 | + public void GetDataSource_ReturnsCorrectDataSource_NotLowerCase() |
| 25 | + { |
| 26 | + // Arrange |
| 27 | + string connectionString = @"DatA SOurce=.\db\footballDb\footballDb.sqlite;foreign keys=true"; |
| 28 | + |
| 29 | + |
| 30 | + // Act |
| 31 | + string result = ConnectionStringParser.GetDataSource(connectionString); |
| 32 | + |
| 33 | + // Assert |
| 34 | + Assert.AreEqual(@".\db\footballDb\footballDb.sqlite", result); |
| 35 | + } |
| 36 | + |
| 37 | + [TestMethod] |
| 38 | + public void GetDataSource_ReturnsCorrectDataSource_WithSpace() |
| 39 | + { |
| 40 | + // Arrange |
| 41 | + string connectionString = @"DatA SOurce =.\db\footballDb\footballDb.sqlite;foreign keys=true"; |
| 42 | + |
| 43 | + |
| 44 | + // Act |
| 45 | + string result = ConnectionStringParser.GetDataSource(connectionString); |
| 46 | + |
| 47 | + // Assert |
| 48 | + Assert.AreEqual(@".\db\footballDb\footballDb.sqlite", result); |
| 49 | + } |
| 50 | + |
| 51 | + [TestMethod] |
| 52 | + public void GetDataSource_ReturnsCorrectDataSource_ReplacesDataDirectory() |
| 53 | + { |
| 54 | + // Arrange |
| 55 | + string connectionString = @"data source=|DataDirectory|\db\footballDb\footballDb.sqlite;foreign keys=true"; |
| 56 | + |
| 57 | + |
| 58 | + // Act |
| 59 | + string result = ConnectionStringParser.GetDataSource(connectionString); |
| 60 | + |
| 61 | + // Assert |
| 62 | + Assert.IsTrue(!result.StartsWith("|DataDirectory|")); |
| 63 | + Assert.IsTrue(result.EndsWith(@"db\footballDb\footballDb.sqlite")); |
| 64 | + } |
| 65 | + |
| 66 | + [TestMethod] |
| 67 | + public void GetDataSource_ReturnsCorrectDataSource_ReplacesDataDirectoryCaseIsIgnored() |
| 68 | + { |
| 69 | + // Arrange |
| 70 | + string connectionString = @"data source=|dAtadIrectory|\db\footballDb\footballDb.sqlite;foreign keys=true"; |
| 71 | + |
| 72 | + |
| 73 | + // Act |
| 74 | + string result = ConnectionStringParser.GetDataSource(connectionString); |
| 75 | + |
| 76 | + // Assert |
| 77 | + Assert.IsTrue(!result.StartsWith("|dAtadIrectory|")); |
| 78 | + Assert.IsTrue(result.EndsWith(@"\db\footballDb\footballDb.sqlite")); |
| 79 | + } |
| 80 | + |
| 81 | + [TestMethod] |
| 82 | + public void GetDataSource_ReturnsCorrectDataSource_ReplacesDataDirectoryAddsBackslash() |
| 83 | + { |
| 84 | + // Arrange |
| 85 | + string connectionString = @"data source=|DataDirectory|db\footballDb\footballDb.sqlite;foreign keys=true"; |
| 86 | + |
| 87 | + |
| 88 | + // Act |
| 89 | + string result = ConnectionStringParser.GetDataSource(connectionString); |
| 90 | + |
| 91 | + // Assert |
| 92 | + Assert.IsTrue(!result.StartsWith("|DataDirectory|")); |
| 93 | + Assert.IsTrue(result.EndsWith(@"\db\footballDb\footballDb.sqlite")); |
| 94 | + } |
| 95 | + |
| 96 | + [TestMethod] |
| 97 | + public void GetDataSource_ReturnsCorrectDataSource_RemovesQuotationMark() |
| 98 | + { |
| 99 | + // Arrange |
| 100 | + string connectionString = @"data source="".\db\footballDb\footballDb.sqlite"";foreign keys=true"; |
| 101 | + |
| 102 | + |
| 103 | + // Act |
| 104 | + string result = ConnectionStringParser.GetDataSource(connectionString); |
| 105 | + |
| 106 | + // Assert |
| 107 | + Assert.AreEqual(@".\db\footballDb\footballDb.sqlite", result); |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments