You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MySqlStorageTest.cs 2.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Xunit;
  2. using Dapper;
  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. [Fact]
  28. public void DatabaseTable_Published_IsExists()
  29. {
  30. var tableName = "cap.published";
  31. using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString))
  32. {
  33. var sql = $"SELECT TABLE_NAME FROM `TABLES` WHERE TABLE_SCHEMA='{_dbName}' AND TABLE_NAME = '{tableName}'";
  34. var result = connection.QueryFirstOrDefault<string>(sql);
  35. Assert.NotNull(result);
  36. Assert.Equal(tableName, result);
  37. }
  38. }
  39. [Fact]
  40. public void DatabaseTable_Queue_IsExists()
  41. {
  42. var tableName = "cap.queue";
  43. using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString))
  44. {
  45. var sql = $"SELECT TABLE_NAME FROM `TABLES` WHERE TABLE_SCHEMA='{_dbName}' AND TABLE_NAME = '{tableName}'";
  46. var result = connection.QueryFirstOrDefault<string>(sql);
  47. Assert.NotNull(result);
  48. Assert.Equal(tableName, result);
  49. }
  50. }
  51. [Fact]
  52. public void DatabaseTable_Received_IsExists()
  53. {
  54. var tableName = "cap.received";
  55. using (var connection = ConnectionUtil.CreateConnection(_masterDbConnectionString))
  56. {
  57. var sql = $"SELECT TABLE_NAME FROM `TABLES` WHERE TABLE_SCHEMA='{_dbName}' AND TABLE_NAME = '{tableName}'";
  58. var result = connection.QueryFirstOrDefault<string>(sql);
  59. Assert.NotNull(result);
  60. Assert.Equal(tableName, result);
  61. }
  62. }
  63. }
  64. }