Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ChangeDB.Agent.MySql/MySqlExpressionTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ SqlExpressionDescriptor ConstantValue(string expression, string storeType = null
{
var sql = string.IsNullOrEmpty(storeType) ? $"select {expression}" : $"select cast({expression} as {storeType})";

var val = ValueCache.GetOrAdd(sql, (s) => context.AgentInfo.Connection.ExecuteScalar(s));
var val = ValueCache.GetOrAdd(sql, (s) => context.Connection.ExecuteScalar(s));
return new SqlExpressionDescriptor { Constant = val };
}

Expand Down
12 changes: 12 additions & 0 deletions src/ChangeDB.Agent.MySql/MySqlRepr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public class MySqlRepr : IRepr
["\'"] = @"\'",
};

public string ReprValue(object value, string storeType)
{
return ReprValue(value);
}

public string ReprValue(object value, DbType dbType)
{
return ReprValue(value);
}

public string ReprValue(object value)
{
return ReprConstant(value);
Expand Down Expand Up @@ -84,6 +94,8 @@ private static StringBuilder Replace(StringBuilder sb,
}
return sb;
}


}

}
9 changes: 3 additions & 6 deletions test/ChangeDB.Agent.MySql.UnitTest/DatabaseEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DatabaseEnvironment : IDisposable, ICollectionFixture<DatabaseEnvir
public DatabaseEnvironment()
{

DBPort = Utility.GetAvailableTcpPort(3306);
DBPort = Utility.GetRandomTcpPort();
DockerCompose.Up(new Dictionary<string, object>
{
["DBPORT"] = DBPort
Expand All @@ -26,7 +26,7 @@ public DatabaseEnvironment()
defaultConnectionFactory = new Lazy<DbConnection>(CreateNewDatabase);
}

public uint DBPort { get; set; }
public int DBPort { get; set; }

private string connectionTemplate;

Expand Down Expand Up @@ -56,10 +56,7 @@ public DbConnection CreateNewDatabase()

public void Dispose()
{
if (defaultConnectionFactory.IsValueCreated)
{
defaultConnectionFactory.Value.Dispose();
}
DockerCompose.Down();
}
}
}
4 changes: 2 additions & 2 deletions test/ChangeDB.Agent.MySql.UnitTest/MySqlDataMigratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public MySqlDataMigratorTest(DatabaseEnvironment databaseEnvironment)

_migrationContext = new MigrationContext
{
Target = new AgentRunTimeInfo { Connection = _dbConnection },
Source = new AgentRunTimeInfo { Connection = _dbConnection },
TargetConnection = _dbConnection,
SourceConnection = _dbConnection
};

}
Expand Down
5 changes: 3 additions & 2 deletions test/ChangeDB.Agent.MySql.UnitTest/MySqlDataTypeMapperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public MySqlDataTypeMapperTest(DatabaseEnvironment databaseEnvironment)
_dbConnection = databaseEnvironment.DbConnection;
_migrationContext = new MigrationContext
{
Target = new AgentRunTimeInfo { Connection = _dbConnection },
Source = new AgentRunTimeInfo { Connection = _dbConnection },
TargetConnection = _dbConnection,
SourceConnection = _dbConnection,
Source = new AgentRunTimeInfo { Agent = new MySqlMigrationAgent() },
SourceDatabase = new DatabaseInfo() { ConnectionString = databaseEnvironment.NewConnectionString(_dbConnection.Database) }
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public MySqlDatabaseManagerTest(DatabaseEnvironment databaseEnvironment)
_dbConnection = databaseEnvironment.NewDatabaseConnection();
_migrationContext = new MigrationContext
{
Target = new AgentRunTimeInfo { Connection = _dbConnection }
TargetConnection = _dbConnection,
};

_dbConnection.CreateDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public MySqlMetadataMigratorTest(DatabaseEnvironment databaseEnvironment)
_dbConnection = databaseEnvironment.CreateNewDatabase();
_migrationContext = new MigrationContext
{
Target = new AgentRunTimeInfo { Connection = _dbConnection },
Source = new AgentRunTimeInfo { Connection = _dbConnection },
TargetConnection = _dbConnection,
SourceConnection = _dbConnection,
Source = new AgentRunTimeInfo { Agent = new MySqlMigrationAgent() },
SourceDatabase = new DatabaseInfo() { ConnectionString = _dbConnection.ConnectionString }
};
}
Expand Down
2 changes: 1 addition & 1 deletion test/ChangeDB.Agent.MySql.UnitTest/MySqlReprTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MySqlReprTest(DatabaseEnvironment databaseEnvironment)

public void ShouldReprString(string value)
{
var reprValue = _repr.ReprValue(value);
var reprValue = _repr.ReprValue(value,"varchar");
var valueFromDatabase = _databaseEnvironment.DbConnection.ExecuteScalar<string>($"select {reprValue}");
valueFromDatabase.Should().Be(value);
}
Expand Down
4 changes: 2 additions & 2 deletions test/ChangeDB.IntegrationTest/DefaultSqlDumperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public async Task ShouldDumpSql(string xmlFile)

private void AssertTargetSqlStript(XElement targetNode, string sqlScriptFile)
{
var content = File.ReadAllText(sqlScriptFile).Trim();
var allSql = targetNode.Value.Trim();
var content = File.ReadAllText(sqlScriptFile).Trim().Replace("\r",string.Empty);
var allSql = targetNode.Value.Trim().Replace("\r",string.Empty);
content.Should().Be(allSql, "the dump scripts should be same");
}

Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="FluentAssertions" Version="6.4.0" />
<PackageReference Include="Bogus" Version="33.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand Down