public void SetUp() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); db = factory.Create("OracleTest"); DbCommand insertionCommand = db.GetSqlStringCommand(insertString); DbCommand countCommand = db.GetSqlStringCommand(countQuery); baseFixture = new ExecuteNonQueryFixture(db, insertString, countQuery, insertionCommand, countCommand); }
public void TestInitialize() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); db = factory.CreateDefault(); DbCommand insertCommand = db.GetSqlStringCommand(insertString); DbCommand queryCommand = db.GetSqlStringCommand(queryString); baseFixture = new ExecuteReaderFixture(db, insertString, insertCommand, queryString, queryCommand); }
public void TestInitialize() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); db = factory.Create("OracleTest"); storedProcedure = db.GetStoredProcCommand("CustOrdersOrders"); connection = db.CreateConnection(); connection.Open(); storedProcedure.Connection = connection; cache = new ParameterCache(); baseFixture = new ParameterDiscoveryFixture(storedProcedure); }
public void Initialize() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); db = factory.Create("OracleTest"); try { DeleteStoredProcedures(); } catch {} CreateStoredProcedures(); base.SetUp(); }
public void SetUp() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); db = factory.Create("OracleTest"); try { DeleteStoredProcedures(); } catch {} CreateStoredProcedures(); baseFixture = new TransactionScopeFixture(db); baseFixture.Clenaup(); }
private void CacheManagerTest(string instanceName) { CacheManagerFactory factory = new CacheManagerFactory(TestConfigurationSource.GenerateConfiguration()); CacheManager mgr = factory.Create(instanceName); string key = "key1"; string val = "value123"; mgr.Add(key, val); string result = (string)mgr.GetData(key); Assert.AreEqual(val, result, "result"); }
protected override void Arrange() { base.Arrange(); sourceSection = new ConfigurationSourceSection() { ParentSource = "MissingParentSource" }; var localSource = new TestConfigurationSource(); localSource.Add(ConfigurationSourceSection.SectionName, sourceSection); hierarchicalConfigurationSourceHandler = new HierarchicalConfigurationSourceHandler(localSource); localSource.SetHierarchyHandler(hierarchicalConfigurationSourceHandler); }
public void ConnectionTest() { DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NewDatabase"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); DbConnection connection = sqlDatabase.CreateConnection(); Assert.IsNotNull(connection); Assert.IsTrue(connection is SqlConnection); connection.Open(); DbCommand cmd = sqlDatabase.GetSqlStringCommand("Select * from Region"); cmd.CommandTimeout = 60; Assert.AreEqual(cmd.CommandTimeout, 60); }
public static DictionaryConfigurationSource CreateConfigurationSource() { DictionaryConfigurationSource configSource = TestConfigurationSource.CreateConfigurationSource(); var connectionString = new ConnectionStringSettings( OracleConnectionStringName, OracleConnectionString, OracleProviderName); var connectionStrings = new ConnectionStringsSection(); connectionStrings.ConnectionStrings.Add(connectionString); configSource.Add("connectionStrings", connectionStrings); return(configSource); }
public void Initialize() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); db = factory.Create("OracleTest"); // ensure that stored procedures are dropped before trying to create them try { DeleteStoredProcedures(); } catch { } CreateStoredProcedures(); base.SetUp(); }
public void DisposesProvidersOnRemoval() { var provider1 = new TestConfigurationProvider("foo", "foo-value"); var provider2 = new DisposableTestConfigurationProvider("bar", "bar-value"); var provider3 = new TestConfigurationProvider("baz", "baz-value"); var provider4 = new DisposableTestConfigurationProvider("qux", "qux-value"); var provider5 = new DisposableTestConfigurationProvider("quux", "quux-value"); var source1 = new TestConfigurationSource(provider1); var source2 = new TestConfigurationSource(provider2); var source3 = new TestConfigurationSource(provider3); var source4 = new TestConfigurationSource(provider4); var source5 = new TestConfigurationSource(provider5); var config = new ConfigurationManager(); IConfigurationBuilder builder = config; builder.Add(source1); builder.Add(source2); builder.Add(source3); builder.Add(source4); builder.Add(source5); Assert.Equal("foo-value", config["foo"]); Assert.Equal("bar-value", config["bar"]); Assert.Equal("baz-value", config["baz"]); Assert.Equal("qux-value", config["qux"]); Assert.Equal("quux-value", config["quux"]); builder.Sources.Remove(source2); builder.Sources.Remove(source4); // While only provider2 and provider4 need to be disposed here, we do not assert provider5 is not disposed // because even though it's unnecessary, Configuration disposes all providers on removal and rebuilds // all the sources. While not optimal, this should be a pretty rare scenario. Assert.True(provider2.IsDisposed); Assert.True(provider4.IsDisposed); config.Dispose(); Assert.True(provider2.IsDisposed); Assert.True(provider4.IsDisposed); Assert.True(provider5.IsDisposed); }
protected override void Arrange() { ConfigurationSourceSection configurationSourcesSection = CreateConfigurationSourceSection(); MainSource = new TestConfigurationSource(); MainSource.Add(ConfigurationSourceSection.SectionName, configurationSourcesSection); CompositionHandler = new TestCompositeConfigurationSourceHandler(MainSource); MainSource.SetCompositeHandler(CompositionHandler); ChildSource1 = (TestConfigurationSource)CompositionHandler["Source1"]; ChildSource2 = (TestConfigurationSource)CompositionHandler["Source2"]; MainSourceEventListener = new ConfigurationSourceEventListener(MainSource); ChildSource1.Add(SectionInChildSource1, new DummySection { Name = SectionInChildSource1, Value = 15 }); }
public void CanInsertNullStringParameter() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); Database db = factory.Create("OracleTest"); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { string sqlString = "insert into Customers (CustomerID, CompanyName, ContactName) Values (:id, :name, :contact)"; DbCommand insert = db.GetSqlStringCommand(sqlString); db.AddInParameter(insert, ":id", DbType.Int32, 1); db.AddInParameter(insert, ":name", DbType.String, "fee"); db.AddInParameter(insert, ":contact", DbType.String, null); db.ExecuteNonQuery(insert, transaction); transaction.Rollback(); } } }
public void CanExecuteProcedureWithUnicaodeParametersInSql() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); SqlDatabase db = factory.CreateDefault() as SqlDatabase; object procedureOutput = null; using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { db.ExecuteNonQuery(transaction, CommandType.Text, @"CREATE PROCEDURE CanAddSqlTypeParameters @UnicodeParam nvarchar(50) AS SELECT @UnicodeParam"); DbCommand commandToCustOrderHist = db.GetStoredProcCommand("CanAddSqlTypeParameters"); db.AddInParameter(commandToCustOrderHist, "UnicodeParam", SqlDbType.NVarChar, "PROCEDURE INPUT \u0414"); procedureOutput = db.ExecuteScalar(commandToCustOrderHist, transaction); transaction.Rollback(); } } Assert.AreEqual("PROCEDURE INPUT \u0414", procedureOutput); }
public void DisposesChangeTokenRegistrationsOnRemoval() { var changeToken = new TestChangeToken(); var providerMock = new Mock <IConfigurationProvider>(); providerMock.Setup(p => p.GetReloadToken()).Returns(changeToken); var source = new TestConfigurationSource(providerMock.Object); var config = new ConfigurationManager(); IConfigurationBuilder builder = config; builder.Add(source); Assert.NotEmpty(changeToken.Callbacks); builder.Sources.Remove(source); Assert.Empty(changeToken.Callbacks); }
protected override void Arrange() { LocalSource = new TestConfigurationSource(); var sectionForLocalSource = Arrange_GetLocalSourceSection(); if (sectionForLocalSource != null) { LocalSource.Add(SectionName, sectionForLocalSource); } ParentSource = new TestConfigurationSource(); var sectionForParentSource = Arrange_GetParentSourceSection(); if (sectionForParentSource != null) { ParentSource.Add(SectionName, sectionForParentSource); } HierarchicalSourceHandler = new HierarchicalConfigurationSourceHandler(LocalSource, ParentSource); LocalSource.SetHierarchyHandler(HierarchicalSourceHandler); }
private void CreateUser() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); Database adminDb = factory.CreateDefault(); using (DbConnection connection = adminDb.CreateConnection()) { connection.Open(); string query; DbCommand addUser; try { query = string.Format("exec sp_addlogin '{0}', '{1}', 'Northwind'", TestConfigurationSource.NorthwindDummyUser, TestConfigurationSource.NorthwindDummyPassword); addUser = adminDb.GetSqlStringCommand(query); adminDb.ExecuteNonQuery(addUser); } catch (Exception e) { Console.WriteLine(e.Message); } try { query = string.Format("exec sp_grantdbaccess '{0}', '{0}'", TestConfigurationSource.NorthwindDummyUser); addUser = adminDb.GetSqlStringCommand(query); adminDb.ExecuteNonQuery(addUser); } catch { } try { query = string.Format("exec sp_addrolemember N'db_owner', N'{0}'", TestConfigurationSource.NorthwindDummyUser); addUser = adminDb.GetSqlStringCommand(query); adminDb.ExecuteNonQuery(addUser); } catch { } } }
public void CheckNoPasswordInConnectionStringWithPersistInfoEqualsFalse() { try { CreateUser(); DatabaseConfigurationView view = new DatabaseConfigurationView(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = view.GetConnectionStringSettings("NorthwindPersistFalse"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); DbConnection dbConnection = sqlDatabase.CreateConnection(); dbConnection.Open(); dbConnection.Close(); string connectionString = dbConnection.ConnectionString; if (connectionString.ToLower().Contains("pwd") || connectionString.ToLower().Contains("password")) { Assert.Fail(); } } finally { DeleteUser(); } }
public void Setup() { provider = new ConfigurationProvider(); source = new TestConfigurationSource(); UpdateConfig(initialConfig); }
public void CanGetConnectionForStringWithNoCredentials() { DatabaseSyntheticConfigSettings settings = new DatabaseSyntheticConfigSettings(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = settings.GetConnectionStringSettings("NewDatabase"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); Assert.AreEqual(String.Format(@"server={0};database=northwind;integrated security=true;", ConfigurationManager.AppSettings["SqlServerDatabaseInstance"]), sqlDatabase.ConnectionStringWithoutCredentials); }
private void NullEncryptorTests(string instanceName) { MockStorageEncryptionProvider.Encrypted = false; MockStorageEncryptionProvider.Decrypted = false; CacheManagerSettings settings = (CacheManagerSettings)TestConfigurationSource.GenerateConfiguration().GetSection(CacheManagerSettings.SectionName); CacheStorageData cacheStorageData = settings.BackingStores.Get(settings.CacheManagers.Get(instanceName).CacheStorage); StorageEncryptionProviderData encryptionProviderData = settings.EncryptionProviders.Get(cacheStorageData.StorageEncryption); IStorageEncryptionProvider provider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>(encryptionProviderData.Name, TestConfigurationSource.GenerateConfiguration()); Assert.IsNotNull(provider); byte[] input = new byte[] { 0, 1, 2, 3, 4, 5 }; byte[] encrypted = provider.Encrypt(input); Assert.IsTrue(MockStorageEncryptionProvider.Encrypted, "static encrypted"); Assert.IsTrue(CompareBytes(input, encrypted), "no encryption performed"); byte[] decrypted = provider.Decrypt(encrypted); Assert.IsTrue(MockStorageEncryptionProvider.Decrypted, "static decrypted"); Assert.IsTrue(CompareBytes(encrypted, decrypted), "no decryption performed"); Assert.IsTrue(CompareBytes(input, decrypted), "no decryption performed2"); }
public void CanGetConnectionForStringWithNoCredentials() { DatabaseSyntheticConfigSettings settings = new DatabaseSyntheticConfigSettings(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = settings.GetConnectionStringSettings("NewDatabase"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); Assert.AreEqual(@"server=(localdb)\v11.0;database=northwind;integrated security=true;", sqlDatabase.ConnectionStringWithoutCredentials); }
public void CanGetConnectionWithoutCredentials() { DatabaseSyntheticConfigSettings settings = new DatabaseSyntheticConfigSettings(TestConfigurationSource.CreateConfigurationSource()); ConnectionStringSettings data = settings.GetConnectionStringSettings("DbWithSqlServerAuthn"); SqlDatabase sqlDatabase = new SqlDatabase(data.ConnectionString); Assert.AreEqual(@"server=(localdb)\v11.0;database=northwind;", sqlDatabase.ConnectionStringWithoutCredentials); }
public void SetUp() { DatabaseProviderFactory factory = new DatabaseProviderFactory(TestConfigurationSource.CreateConfigurationSource()); db = factory.CreateDefault(); }
public void SetUp() { testSource = new TestConfigurationSource(); }