/// <summary> /// Public constructor with read only database version /// </summary> /// <param name="setup"></param> /// <param name="profileId"></param> /// <param name="repositoryId"></param> /// <param name="runTestData"></param> public DvcController(DatabaseVersionSetup setup, string profileId, bool runTestData) { _setup = setup; _runTestData = runTestData; Log.Info(string.Format("Loading profile {0}", profileId)); _profile = _setup.GetProfile(profileId); if (_profile == null){ throw new Exception(string.Format("Could not find profile {0} in list of profiles", profileId)); } //add variable from repository to profile _profile.AddRepositoryProperties(GetDefaultRepository().Properties); }
private void LoadProfiles(DatabaseVersionSetup versionSetup, IEnumerable<XElement> enumerable) { foreach (var element in enumerable) { var profile = new DatabaseVersionSetup.Profile() { Id = (string) element.Attribute("Id"), ConnectionString = element.Element("ConnectionString").Value, Tracking = LoadTracking(element.Element("Tracking")) }; versionSetup.Profiles.Add(profile); } }
private void LoadProfiles(DatabaseVersionSetup versionSetup, IEnumerable<XElement> enumerable) { foreach (var element in enumerable) { string value = element.Attribute("id").Value; IRepositoryProfile profile = null; XElement databaseProfile = element.Element("repositoryProfile"); KeyValuePair<string,string>[] props; if (databaseProfile != null) { XElement trackingByTable = databaseProfile.Element("trackingByTable"); ITracker databaseTrackingTable = null; if (trackingByTable != null) { databaseTrackingTable = new AgnosticDatabaseTrackingTable(trackingByTable.Attribute("tableName").Value, Convert.ToBoolean(trackingByTable.Attribute("autoCreate").Value)); } var databaseProfileType = databaseProfile.Attribute("type").Value; if (databaseProfileType == "sqlServer") { int commandTimeoutValue = 30; var commandTimeoutString = databaseProfile.Attribute("commandTimeout"); if(commandTimeoutString != null) commandTimeoutValue = int.Parse(commandTimeoutString.Value); profile = new SqlServerDatabaseProfile( databaseProfile.Attribute("connectionString").Value, databaseProfile.Attribute("databaseName").Value, databaseProfile.Attribute("repositoryID").Value, commandTimeoutValue, databaseTrackingTable); } else if (databaseProfileType == "mySql") { int commandTimeoutValue = 30; var commandTimeoutString = databaseProfile.Attribute("commandTimeout"); if (commandTimeoutString != null) commandTimeoutValue = int.Parse(commandTimeoutString.Value); profile = new MySqlRepositoryProfile( databaseProfile.Attribute("connectionString").Value, databaseProfile.Attribute("databaseName").Value, databaseProfile.Attribute("repositoryID").Value, commandTimeoutValue, databaseTrackingTable); } else { throw new Exception(string.Format("Unknown databaseProfile type {0}", databaseProfileType)); } XElement properties = databaseProfile.Element("properties"); props = LoadProperties(properties); } else{ throw new Exception("repositoryProfile missing from profile"); } var newProfile = new DatabaseVersionSetup.Profile(value,profile); if (props != null) newProfile.AddProperties(props); versionSetup.Profiles.Add(newProfile); } }
public void Setup() { _databaseVersionSetup = new DatabaseVersionSetup(); _mockIRepositoryProfile = new Mock<IRepositoryProfile>(MockBehavior.Strict); _databaseVersionSetup.DefaultProfile = DefaultProfile; var profile = new DatabaseVersionSetup.Profile(DefaultProfile, _mockIRepositoryProfile.Object); _mockITracker = new Mock<ITracker>(MockBehavior.Strict); _mockIDatabase = new Mock<IConnection>(MockBehavior.Strict); _mockITransaction = new Mock<ITransaction>(MockBehavior.Strict); _databaseVersionSetup.Profiles.Add(profile); _mockIRunner = new Mock<IRunner>(MockBehavior.Strict); var runner = new UpdatesMetadata(1, DateTime.MinValue.ToShortDateString(), "FirstUpdate", "Rolf", _mockIRunner.Object); _databaseVersionSetup.Repository.Add(new DatabaseRepository("Repo",runner)); _mockIRepositoryProfile.Setup(mc => mc.DatabaseRepository) .Returns("Repo"); _dvcController = new DvcController(_databaseVersionSetup, DefaultProfile, true); }
public DatabaseVersionSetup GetVersionSetup() { var versionSetup = new DatabaseVersionSetup(); mockSqlServerDatabaseProfile = new Mock<SqlServerDatabaseProfile>(MockBehavior.Strict, "Data Source=GMV-RW-LT;Initial Catalog=Intercontinental;Integrated Security=True" , "Intercontinental4" , "Intercontinental" , _mockITracker.Object); var profile = new DatabaseVersionSetup.Profile("Default", mockSqlServerDatabaseProfile.Object); profile.AddProperties("test1", "test1Prof|withvar|${dp.DatabaseName}|"); profile.AddProperties("test2", "test2"); profile.AddProperties("test2", "test2|over"); profile.AddProperties("insert", "insert.sql"); profile.AddProperties("update", "update.sql"); profile.AddProperties("delete", "delete.sql"); versionSetup.Profiles.Add(profile); var runner = new SqlRunner("CREATE DATABASE ${dp.DatabaseName};", "USE Master; DROP DATABASE ${dp.DatabaseName};"); var repository = new DatabaseRepository("Intercontinental", new UpdatesMetadata(1, "Todau", "Initialize", "rolf", runner)); repository.AddProperties("test0", "test0"); repository.AddProperties("test1", "test1"); var versions = new UpdatesMetadata(2, "2010-04-16", "First update", "Rolf Wessels", new SqlRunner( @"Create2 ${test0} ${test1} ${test2} ${test3}", @"RoleBack2 ${test0} ${test1} ${test2} ${test3}", @"TestData2 ${test0} ${test1} ${test2} ${test3}" ) ); repository.Updates.Add(versions); versions = new UpdatesMetadata(3, "2010-04-16", "First update", "Rolf Wessels", new SqlRunner( @"Create3 ${test0} ${test1} ${test2} ${test3}", @"RoleBack3 ${test0} ${test1} ${test2} ${test3}", @"TestData3 ${test0} ${test1} ${test2} ${test3}" ) ); repository.Updates.Add(versions); File.WriteAllText(@"resources\insert.sql", @"Create4 ${test0} ${test1} ${test2} ${test3}"); File.WriteAllText(@"resources\update.sql", @"RoleBack4 ${test0} ${test1} ${test2} ${test3}"); File.WriteAllText(@"resources\delete.sql", @"TestData4 ${test0} ${test1} ${test2} ${test3}"); repository.Updates.Add(new UpdatesMetadata(4, "2010-04-16", "First update", "Rolf Wessels", new SqlRunner(new SqlFilesExecuter(new[] { @"resources\${insert}" }), new SqlFilesExecuter(new[] { @"resources\${update}" }), new SqlFilesExecuter(new[] { @"resources\${delete}" })))); versionSetup.Repository.Add(repository); return versionSetup; }