public void ShouldLoadNamedConnectionFromSpecifiedConfigFile() { string configPath = GetPath("WithConnectionString.config"); var sut = new ConnectionStringManager(configManagerMock.Object, announcerMock.Object, CONNECTION_NAME, configPath, TARGET, DATABASE); configManagerMock.Setup(m => m.LoadFromFile(configPath)) .Returns(LoadFromFile(configPath)); sut.LoadConnectionString(); Assert.That(sut.ConnectionString, Is.EqualTo("From Arbitrary Config")); }
public void ShouldLoadMachineNameConnectionFromSpecifiedConfigIfNoConnectionNameSpecified() { string configPath = GetPath("WithConnectionString.config"); var sut = new ConnectionStringManager(configManagerMock.Object, announcerMock.Object, null, configPath, TARGET, DATABASE); configManagerMock.Setup(m => m.LoadFromFile(configPath)) .Returns(LoadFromFile(configPath)); sut.MachineNameProvider = () => "MACHINENAME"; sut.LoadConnectionString(); Assert.That(sut.ConnectionString, Is.EqualTo("From Machine Name")); }
private IMigrationProcessor InitializeProcessor(string assemblyLocation) { var manager = new ConnectionStringManager(new NetConfigManager(), RunnerContext.Connection, RunnerContext.ConnectionStringConfigPath, assemblyLocation, RunnerContext.Database); manager.LoadConnectionString(); if (RunnerContext.Timeout == 0) { RunnerContext.Timeout = 30; // Set default timeout for command } var processorFactory = ProcessorFactory.GetFactory(RunnerContext.Database); var processor = processorFactory.Create(manager.ConnectionString, RunnerContext.Announcer, new ProcessorOptions { PreviewOnly = RunnerContext.PreviewOnly, Timeout = RunnerContext.Timeout }); return processor; }
public void IfNoPathSpecifiedLoadFromTargetAssemblyPath() { string configPath = GetPath("WithConnectionString.exe.config"); var configManagerMock = new Mock<INetConfigManager>(); configManagerMock.Setup(x => x.LoadFromFile(It.IsAny<string>())) .Returns(LoadFromFile(configPath)); var sut = new ConnectionStringManager(configManagerMock.Object, CONNECTION_NAME, null, TARGET, DATABASE); sut.LoadConnectionString(); configManagerMock.VerifyAll(); Assert.That(sut.ConnectionString, Is.EqualTo("From App Config")); }
public void ShouldLoadNamedConnectionFromMachineConfigIfTargetAssemblyConfigHasNoMatch() { string configPath = GetPath("WithWrongConnectionString.config"); string machineConfigPath = GetPath("FromMachineConfig.config"); configManagerMock.Setup(x => x.LoadFromFile(TARGET)) .Returns(LoadFromFile(configPath)); configManagerMock.Setup(x => x.LoadFromMachineConfiguration()) .Returns(LoadFromFile(machineConfigPath)); var sut = new ConnectionStringManager(configManagerMock.Object, announcerMock.Object, CONNECTION_NAME, null, TARGET, DATABASE); sut.LoadConnectionString(); configManagerMock.VerifyAll(); Assert.That(sut.ConnectionString, Is.EqualTo("From Machine Config")); }
public void IfNoConnectionMatchesAppConfigLoadFromMachineConfig() { string configPath = GetPath("WithWrongConnectionString.config"); string machineConfigPath = GetPath("FromMachineConfig.config"); var configManagerMock = new Mock<INetConfigManager>(); configManagerMock.Setup(x => x.LoadFromFile(It.IsAny<string>())) .Returns(LoadFromFile(configPath)); configManagerMock.Setup(x => x.LoadFromMachineConfiguration()) .Returns(LoadFromFile(machineConfigPath)); var sut = new ConnectionStringManager(configManagerMock.Object, CONNECTION_NAME, null, TARGET, DATABASE); sut.LoadConnectionString(); configManagerMock.VerifyAll(); Assert.That(sut.ConnectionString, Is.EqualTo("From Machine Config")); }
private IMigrationProcessor InitializeProcessor(string assemblyLocation) { var manager = new ConnectionStringManager(new NetConfigManager(), RunnerContext.Announcer, RunnerContext.Connection, RunnerContext.ConnectionStringConfigPath, assemblyLocation, RunnerContext.Database); manager.LoadConnectionString(); if (RunnerContext.Timeout == 0) { RunnerContext.Timeout = 30; // Set default timeout for command } var processorFactory = ProcessorFactory.GetFactory(RunnerContext.Database); if (processorFactory == null) throw new ProcessorFactoryNotFoundException(string.Format("The provider or dbtype parameter is incorrect. Available choices are {0}: ", ProcessorFactory.ListAvailableProcessorTypes())); var processor = processorFactory.Create(manager.ConnectionString, RunnerContext.Announcer, new ProcessorOptions { PreviewOnly = RunnerContext.PreviewOnly, Timeout = RunnerContext.Timeout }); return processor; }
public void ShouldUseAsConnectionStringIfNoConnectionMatchesAndNoMatchInMachineConfig() { string configPath = GetPath("WithWrongConnectionString.config"); string machineConfigPath = GetPath("FromMachineConfig.config"); configManagerMock.Setup(x => x.LoadFromFile(TARGET)) .Returns(LoadFromFile(configPath)); configManagerMock.Setup(x => x.LoadFromMachineConfiguration()) .Returns(LoadFromFile(machineConfigPath)); var sut = new ConnectionStringManager(configManagerMock.Object, announcerMock.Object, "This is a connection string", null, TARGET, DATABASE); sut.LoadConnectionString(); Assert.That(sut.ConnectionString, Is.EqualTo("This is a connection string")); }
public void ShouldLoadNamedConnectionFromTargetAssemblyConfig() { string configPath = GetPath("WithConnectionString.exe.config"); configManagerMock.Setup(x => x.LoadFromFile(TARGET)) .Returns(LoadFromFile(configPath)); var sut = new ConnectionStringManager(configManagerMock.Object, announcerMock.Object, CONNECTION_NAME, null, TARGET, DATABASE); sut.LoadConnectionString(); Assert.That(sut.ConnectionString, Is.EqualTo("From App Config")); }
private string LoadConnectionString(IAssemblyCollection assemblyCollection) { var singleAssembly = (assemblyCollection != null && assemblyCollection.Assemblies != null && assemblyCollection.Assemblies.Length == 1) ? assemblyCollection.Assemblies[0] : null; var singleAssemblyLocation = singleAssembly != null ? singleAssembly.Location : string.Empty; var manager = new ConnectionStringManager(new NetConfigManager(), RunnerContext.Announcer, RunnerContext.Connection, RunnerContext.ConnectionStringConfigPath, singleAssemblyLocation, RunnerContext.Database); manager.LoadConnectionString(); return manager.ConnectionString; }
public void ShouldObfuscatePasswordOfConnectionString() { string configPath = GetPath("WithWrongConnectionString.config"); string machineConfigPath = GetPath("FromMachineConfig.config"); configManagerMock.Setup(x => x.LoadFromFile(TARGET)) .Returns(LoadFromFile(configPath)); configManagerMock.Setup(x => x.LoadFromMachineConfiguration()) .Returns(LoadFromFile(machineConfigPath)); var sut = new ConnectionStringManager(configManagerMock.Object, announcerMock.Object, @"server=.\SQLEXPRESS;uid=test;pwd=test;Trusted_Connection=yes;database=FluentMigrator", null, TARGET, DATABASE); sut.LoadConnectionString(); announcerMock.Verify(a => a.Say(@"Using Database sqlserver2008 and Connection String server=.\SQLEXPRESS;uid=test;pwd=********;Trusted_Connection=yes;database=FluentMigrator"), Times.Once()); }
private string LoadConnectionString(string assemblyLocation) { var manager = new ConnectionStringManager(new NetConfigManager(), RunnerContext.Announcer, RunnerContext.Connection, RunnerContext.ConnectionStringConfigPath, assemblyLocation, RunnerContext.Database); manager.LoadConnectionString(); return manager.ConnectionString; }