public void SerializationShouldGenerateCorrectXml() { string expectedXml = ResourceHelper.ReadString( "Galen.Ci.EntityFramework.Deployer.Tests.Data.SerializationShouldGenerateCorrectXml_Expected.xml"); string actualXml; var config = new DeploymentConfiguration() { MigrationConfigurationInfo = new MigrationConfigurationInfo { Type = "Galen.Enterprise.Data.Migrations.SomeContext.Configuration" }, InitializerConfigurationInfo=new InitializerConfigurationInfo { Type = "Galen.Enterprise.Data.Initializers.SomeContextCreateDatabaseIfNotExists", ServiceAccount = new ServiceAccountInfo() { Name = "SomeWindowsAccountName", Domain = "SomeDomainName", DatabaseUser = "******", AccountType = "Windows" } } }; using (var memoryStream = new MemoryStream()) { var sut = new DeploymentConfigurationXmlStore(memoryStream); sut.Save(config); memoryStream.Position=0; using (var sr = new StreamReader(memoryStream)) { actualXml=sr.ReadToEnd(); } } Assert.AreEqual(expectedXml, actualXml); }
public void Save(DeploymentConfiguration configuration) { Stream stream = null; try { stream = m_Stream ?? new FileStream(m_FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None); var serializer = new System.Xml.Serialization.XmlSerializer(typeof (DeploymentConfiguration)); serializer.Serialize(stream, configuration); } catch (Exception ex) { Log.Error(ex, "Unable to save deployment configuration XML to path {filePath}", m_FilePath); throw; } finally { if (m_Stream == null && stream != null) //We own the stream stream.Dispose(); } }
public void Save(DeploymentConfiguration configuration) { Stream stream = null; try { stream = m_Stream ?? new FileStream(m_FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None); var serializer = new System.Xml.Serialization.XmlSerializer(typeof(DeploymentConfiguration)); serializer.Serialize(stream, configuration); } catch (Exception ex) { Log.Error(ex, "Unable to save deployment configuration XML to path {filePath}", m_FilePath); throw; } finally { if (m_Stream == null && stream != null) //We own the stream { stream.Dispose(); } } }
public void TestConfigurationXmlShouldConfigureDeployerCorrectly() { var connections = new[] { new DatabaseEndpoint() {DatabaseName = "Db1", ServerName = "Server1"}, }; var arguments = new Arguments() { Database=new DatabaseEndpoints() { Endpoints=connections }, DeployedAssemblyOverridePath=@"c:\some dir\some other dir\MyAssembly1.dll", TargetAssemblyPath=@".\MyAssembly1.dll", RunServerMigrationsInTransaction=false, Mode=DeploymentMode.MigrationOnly }; var expectedConfig = new DeploymentConfiguration() { MigrationConfigurationInfo=new MigrationConfigurationInfo { Type = "Galen.Enterprise.Security.Core.Data.Migrations.SecurityDbContext.Configuration" }, InitializerConfigurationInfo=new InitializerConfigurationInfo { Type = "Galen.Enterprise.Security.Core.Data.Initializers.SecurityDbContextCreateIfNotExistsWithTestData", DisableForcedSeeding = true, ServiceAccount = new ServiceAccountInfo() { Name = "EnterpriseServiceAccount", AccountType = "Sql", DatabaseUser = "******", DatabaseUserPassword = "******", } } }; var sut = new ConfigurationArgumentMapper(new DeploymentConfigurationXmlStore(ResourceHelper.ReadStream( "Galen.Ci.EntityFramework.Deployer.Tests.Data.TestConfiguration.xml"))); var actualConfig = sut.FromArguments(arguments); Assert.IsNotNull(actualConfig); Assert.IsNotNull(actualConfig.InitializationConfig); Assert.IsNotNull(actualConfig.MigrationConfig); Assert.AreEqual(expectedConfig.MigrationConfigurationInfo.Type, actualConfig.MigrationConfig.Type); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.Type, actualConfig.InitializationConfig.Type); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.DisableForcedSeeding, actualConfig.InitializationConfig.DisableForcedSeeding); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.Name, actualConfig.InitializationConfig.ServiceAccount.Name); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.Domain, actualConfig.InitializationConfig.ServiceAccount.Domain); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.DatabaseUser, actualConfig.InitializationConfig.ServiceAccount.DatabaseUser); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.AccountType, actualConfig.InitializationConfig.ServiceAccount.AccountType); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.DatabaseUserPassword, actualConfig.InitializationConfig.ServiceAccount.DatabaseUserPassword); }
public void DeserializationShouldResultInCorrectConfiguration() { byte[] sourceData = ResourceHelper.ReadBytes("Galen.Ci.EntityFramework.Deployer.Tests.Data.DeserializationShouldResultInCorrectConfiguration_Source.xml"); DeploymentConfiguration actualConfig; var expectedConfig = new DeploymentConfiguration() { MigrationConfigurationInfo=new MigrationConfigurationInfo { Type = "Galen.Enterprise.Data.Migrations.SomeContext.Configuration" }, InitializerConfigurationInfo=new InitializerConfigurationInfo { Type = "Galen.Enterprise.Data.Initializers.SomeContextCreateDatabaseIfNotExists", ServiceAccount = new ServiceAccountInfo() { Name = "SomeWindowsAccountName", Domain = "SomeDomainName", DatabaseUser = "******", AccountType = "Windows" } } }; using (var stream = new MemoryStream(sourceData)) { var sut = new DeploymentConfigurationXmlStore(stream); actualConfig=sut.Load(); } Assert.IsNotNull(actualConfig); Assert.IsNotNull(actualConfig.InitializerConfigurationInfo); Assert.IsNotNull(actualConfig.MigrationConfigurationInfo); Assert.AreEqual(expectedConfig.MigrationConfigurationInfo.Type, actualConfig.MigrationConfigurationInfo.Type); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.Type, actualConfig.InitializerConfigurationInfo.Type); Assert.IsTrue((actualConfig.InitializerConfigurationInfo.ServiceAccount!=null &&expectedConfig.InitializerConfigurationInfo.ServiceAccount!=null) ||(actualConfig.InitializerConfigurationInfo.ServiceAccount==null &&expectedConfig.InitializerConfigurationInfo.ServiceAccount==null), "Service account info mismatch"); if (actualConfig.InitializerConfigurationInfo.ServiceAccount!=null) { Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.Name, actualConfig.InitializerConfigurationInfo.ServiceAccount.Name); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.Domain, actualConfig.InitializerConfigurationInfo.ServiceAccount.Domain); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.DatabaseUser, actualConfig.InitializerConfigurationInfo.ServiceAccount.DatabaseUser); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.AccountType, actualConfig.InitializerConfigurationInfo.ServiceAccount.AccountType); Assert.AreEqual(expectedConfig.InitializerConfigurationInfo.ServiceAccount.DatabaseUserPassword, actualConfig.InitializerConfigurationInfo.ServiceAccount.DatabaseUserPassword); } }