25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.6 KiB

  1. using Dapper;
  2. using Xunit;
  3. namespace DotNetCore.CAP.MySql.Test
  4. {
  5. [Collection("MySql")]
  6. public class MySqlStorageTest : DatabaseTestHost
  7. {
  8. private readonly string _dbName;
  9. private readonly string _masterDbConnectionString;
  10. public MySqlStorageTest()
  11. {
  12. _dbName = ConnectionUtil.GetDatabaseName();
  13. _masterDbConnectionString = ConnectionUtil.GetMasterConnectionString();
  14. }
  15. [Fact]
  16. public void Database_IsExists()
  17. {
  18. using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString))
  19. {
  20. var databaseName = ConnectionUtil.GetDatabaseName();
  21. var sql = $@"SELECT SCHEMA_NAME FROM SCHEMATA WHERE SCHEMA_NAME = '{databaseName}'";
  22. var result = connection.QueryFirstOrDefault<string>(sql);
  23. Assert.NotNull(result);
  24. Assert.True(databaseName.Equals(result, System.StringComparison.CurrentCultureIgnoreCase));
  25. }
  26. }
  27. [Theory]
  28. [InlineData("cap.published")]
  29. [InlineData("cap.received")]
  30. public void DatabaseTable_IsExists(string tableName)
  31. {
  32. using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString))
  33. {
  34. var sql = $"SELECT TABLE_NAME FROM `TABLES` WHERE TABLE_SCHEMA='{_dbName}' AND TABLE_NAME = '{tableName}'";
  35. var result = connection.QueryFirstOrDefault<string>(sql);
  36. Assert.NotNull(result);
  37. Assert.Equal(tableName, result);
  38. }
  39. }
  40. }
  41. }