public void TestKeywords_Invalid(DatabaseType databaseType)
        {
            var acc = new ConnectionStringKeywordAccumulator(databaseType);

            var ex = Assert.Throws <ArgumentException>(() => acc.AddOrUpdateKeyword("FLIBBLE", "false", ConnectionStringKeywordPriority.SystemDefaultLow));

            StringAssert.Contains("FLIBBLE", ex.Message);
        }
Пример #2
0
 /// <summary>
 /// Checks that the keyword is valid syntax for the <see cref="DatabaseType"/> and can be set on a <see cref="DbConnectionStringBuilder"/>
 /// </summary>
 /// <param name="notifier"></param>
 public void Check(ICheckNotifier notifier)
 {
     try
     {
         var accumulator = new ConnectionStringKeywordAccumulator(DatabaseType);
         accumulator.AddOrUpdateKeyword(Name, Value, ConnectionStringKeywordPriority.SystemDefaultLow);
         notifier.OnCheckPerformed(new CheckEventArgs("Integrity of keyword is ok according to ConnectionStringKeywordAccumulator", CheckResult.Success));
     }
     catch (Exception e)
     {
         notifier.OnCheckPerformed(new CheckEventArgs(e.Message, CheckResult.Fail, e));
     }
 }
        public void TestKeywords()
        {
            var acc = new ConnectionStringKeywordAccumulator(DatabaseType.MySql);

            acc.AddOrUpdateKeyword("AutoEnlist", "false", ConnectionStringKeywordPriority.SystemDefaultLow);

            DbConnectionStringBuilder connectionStringBuilder = helpers[DatabaseType.MySql].GetConnectionStringBuilder("localhost", "mydb", "frank", "kangaro");

            StringAssert.DoesNotContain("autoenlist", connectionStringBuilder.ConnectionString);

            acc.EnforceOptions(connectionStringBuilder);

            Assert.IsTrue(connectionStringBuilder.ConnectionString.IndexOf("AutoEnlist=false", StringComparison.InvariantCultureIgnoreCase) != -1);
        }
Пример #4
0
        public void TestKeywords()
        {
            var acc = new ConnectionStringKeywordAccumulator(DatabaseType.MySql);

            acc.AddOrUpdateKeyword("AutoEnlist", "false", ConnectionStringKeywordPriority.SystemDefaultLow);

            DbConnectionStringBuilder connectionStringBuilder = helpers[DatabaseType.MySql].GetConnectionStringBuilder("localhost", "mydb", "frank", "kangaro");

            StringAssert.DoesNotContain("autoenlist", connectionStringBuilder.ConnectionString);

            acc.EnforceOptions(connectionStringBuilder);

            StringAssert.Contains("autoenlist=False", connectionStringBuilder.ConnectionString);
        }
        public void TestKeywords_OverrideWithNovelButEquivalentKeyword_Ignored(DatabaseType databaseType, string key1, string value1, string equivalentKey, string value2)
        {
            var acc = new ConnectionStringKeywordAccumulator(databaseType);

            acc.AddOrUpdateKeyword(key1, value1, ConnectionStringKeywordPriority.SystemDefaultHigh);

            DbConnectionStringBuilder connectionStringBuilder = helpers[databaseType].GetConnectionStringBuilder("localhost", "mydb", "frank", "kangaro");

            acc.EnforceOptions(connectionStringBuilder);

            StringAssert.Contains(key1 + "=" + value1, connectionStringBuilder.ConnectionString);

            //attempt override with low priority setting it to true but also use the alias
            acc.AddOrUpdateKeyword(equivalentKey, value2, ConnectionStringKeywordPriority.SystemDefaultLow);

            acc.EnforceOptions(connectionStringBuilder);

            StringAssert.Contains(key1 + "=" + value1, connectionStringBuilder.ConnectionString, "ConnectionStringKeywordAccumulator did not realise that keywords are equivalent");
        }
        public void TestKeywords_OverrideWithHigherPriority_Respected(ConnectionStringKeywordPriority newPriority)
        {
            var acc = new ConnectionStringKeywordAccumulator(DatabaseType.MicrosoftSQLServer);

            acc.AddOrUpdateKeyword("Pooling", "false", ConnectionStringKeywordPriority.SystemDefaultHigh);

            DbConnectionStringBuilder connectionStringBuilder = helpers[DatabaseType.MicrosoftSQLServer].GetConnectionStringBuilder("localhost", "mydb", "frank", "kangaro");

            StringAssert.DoesNotContain("pooling", connectionStringBuilder.ConnectionString);

            acc.EnforceOptions(connectionStringBuilder);

            StringAssert.Contains("Pooling=False", connectionStringBuilder.ConnectionString);

            //attempt override with low priority setting it to true (note we flipped case of P just to be a curve ball)
            acc.AddOrUpdateKeyword("pooling", "true", newPriority);

            acc.EnforceOptions(connectionStringBuilder);

            StringAssert.Contains("Pooling=True", connectionStringBuilder.ConnectionString);
        }