public void CanReadConfigurationSection() { using (var file = TemporaryConfigurationFile.OpenFromResource("XmlFiles.ConfigFileWithDatabaseDeployment_FormatWithDeploymentInConnection.xml")) { var section = file.GetConfigSection(); Assert.IsNotNull(section); Assert.IsTrue(section.ElementInformation.IsPresent); Assert.IsNotNull(section.Connections); Assert.IsTrue(section.Connections.ElementInformation.IsPresent); Assert.IsTrue(section.Connections.ElementInformation.IsCollection); Assert.AreEqual(3, section.Connections.Count); // check first connection without databasedeployment configuration Assert.IsNotNull(section.Connections[0]); Assert.IsTrue(section.Connections[0].ElementInformation.IsPresent); Assert.AreEqual("test1", section.Connections[0].Name); Assert.AreEqual("p1", section.Connections[0].ProviderName); Assert.AreEqual("c1", section.Connections[0].ConnectionString); Assert.IsNotNull(section.Connections[0].DatabaseDepoyment); // instance should be there although it doesnt exist in config. use elementinformation Assert.IsFalse(section.Connections[0].DatabaseDepoyment.ElementInformation.IsPresent); Assert.IsNotNull(section.Connections[0].DatabaseDepoyment.DeployerConfig); Assert.IsFalse(section.Connections[0].DatabaseDepoyment.DeployerConfig.ElementInformation.IsPresent); // check second connection with databasdedeployment configuration and deployerconfig element Assert.IsNotNull(section.Connections[1]); Assert.IsTrue(section.Connections[1].ElementInformation.IsPresent); Assert.AreEqual("test2", section.Connections[1].Name); Assert.AreEqual("p2", section.Connections[1].ProviderName); Assert.AreEqual("c2", section.Connections[1].ConnectionString); Assert.IsNotNull(section.Connections[1].DatabaseDepoyment); Assert.IsTrue(section.Connections[1].DatabaseDepoyment.ElementInformation.IsPresent); Assert.IsTrue(section.Connections[1].DatabaseDepoyment.CreateUniqueDatabaseName); Assert.IsTrue(section.Connections[1].DatabaseDepoyment.DropDatabaseOnExit); Assert.IsNotNull(section.Connections[1].DatabaseDepoyment.DeployerConfig); Assert.IsTrue(section.Connections[1].DatabaseDepoyment.DeployerConfig.ElementInformation.IsPresent); Assert.AreSame(typeof(TestDeployerConfigElement), section.Connections[1].DatabaseDepoyment.DeployerConfig.GetType()); Assert.AreEqual("testvalue", ((TestDeployerConfigElement)section.Connections[1].DatabaseDepoyment.DeployerConfig).TestProperty); // check third connection with databasdedeployment configuration without deployerconfig element Assert.IsNotNull(section.Connections[2]); Assert.IsTrue(section.Connections[2].ElementInformation.IsPresent); Assert.AreEqual("test3", section.Connections[2].Name); Assert.AreEqual("p3", section.Connections[2].ProviderName); Assert.AreEqual("c3", section.Connections[2].ConnectionString); Assert.IsNotNull(section.Connections[2].DatabaseDepoyment); Assert.IsTrue(section.Connections[2].DatabaseDepoyment.ElementInformation.IsPresent); Assert.IsFalse(section.Connections[2].DatabaseDepoyment.CreateUniqueDatabaseName); Assert.IsFalse(section.Connections[2].DatabaseDepoyment.DropDatabaseOnExit); Assert.IsNotNull(section.Connections[2].DatabaseDepoyment.DeployerConfig); Assert.IsFalse(section.Connections[2].DatabaseDepoyment.DeployerConfig.ElementInformation.IsPresent); } }
public void TestMethod1() { using (var file = TemporaryConfigurationFile.OpenFromResource("XmlFiles.ConfigFileWith3Connections.xml")) { var section = file.GetConfigSection(); var config = ConfigurationFileTestConfigFactory.CreateFromConfiguration(section); Assert.IsNotNull(config); Assert.IsNotNull(config.Connections2); Assert.AreEqual(3, config.Connections2.Count); var con0 = config.Connections2[0]; Assert.IsNotNull(con0); Assert.AreEqual("con0", con0.Name); Assert.AreEqual("System.Data.SqlClient", con0.ProviderName); Assert.IsNotNull(con0.Provider); Assert.AreEqual("c1", con0.ConnectionString); Assert.IsNull(con0.Deployment); var con1 = config.Connections2[1]; Assert.IsNotNull(con1); Assert.AreEqual("con1", con1.Name); Assert.AreEqual("System.Data.SqlClient", con1.ProviderName); Assert.IsNotNull(con1.Provider); Assert.AreEqual("c2", con1.ConnectionString); Assert.IsNotNull(con1.Deployment); Assert.AreSame(con1, con1.Deployment.ConnectionContext); Assert.IsTrue(con1.Deployment.CreateUniqueDatabaseName); Assert.IsTrue(con1.Deployment.DropDatabaseOnExit); Assert.IsNotNull(con1.Deployment.DeployerConfig); Assert.AreSame(typeof(TestDeployerConfig), con1.Deployment.DeployerConfig.GetType()); Assert.AreEqual("testvalue", ((TestDeployerConfig)con1.Deployment.DeployerConfig).TestProperty); Assert.IsNotNull(con1.Deployment.DatabaseDeployer); Assert.AreSame(typeof(TestDeployer), con1.Deployment.DatabaseDeployer.GetType()); var con2 = config.Connections2[2]; Assert.IsNotNull(con2); Assert.AreEqual("con2", con2.Name); Assert.AreEqual("System.Data.SqlClient", con2.ProviderName); Assert.IsNotNull(con2.Provider); Assert.AreEqual("c3", con2.ConnectionString); Assert.IsNotNull(con2.Deployment); Assert.AreSame(con2, con2.Deployment.ConnectionContext); Assert.IsFalse(con2.Deployment.CreateUniqueDatabaseName); Assert.IsFalse(con2.Deployment.DropDatabaseOnExit); Assert.IsNull(con2.Deployment.DeployerConfig); Assert.IsNotNull(con2.Deployment.DatabaseDeployer); Assert.AreSame(typeof(TestDeployer), con2.Deployment.DatabaseDeployer.GetType()); } }