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.

MySqlStorageConnectionTest.cs 2.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP.Internal;
  4. using DotNetCore.CAP.Messages;
  5. using DotNetCore.CAP.Persistence;
  6. using Microsoft.Extensions.Options;
  7. using Xunit;
  8. namespace DotNetCore.CAP.MySql.Test
  9. {
  10. [Collection("MySql")]
  11. public class MySqlStorageConnectionTest : DatabaseTestHost
  12. {
  13. private readonly MySqlDataStorage _storage;
  14. public MySqlStorageConnectionTest()
  15. {
  16. var options = GetService<IOptions<MySqlOptions>>();
  17. var capOptions = GetService<IOptions<CapOptions>>();
  18. var initializer = GetService<IStorageInitializer>();
  19. _storage = new MySqlDataStorage(options, capOptions, initializer);
  20. }
  21. [Fact]
  22. public void StorageMessageTest()
  23. {
  24. var msgId = SnowflakeId.Default().NextId().ToString();
  25. var header = new Dictionary<string, string>()
  26. {
  27. [Headers.MessageId] = msgId
  28. };
  29. var message = new Message(header, null);
  30. var mdMessage = _storage.StoreMessage("test.name", message);
  31. Assert.NotNull(mdMessage);
  32. }
  33. [Fact]
  34. public void StoreReceivedMessageTest()
  35. {
  36. var msgId = SnowflakeId.Default().NextId().ToString();
  37. var header = new Dictionary<string, string>()
  38. {
  39. [Headers.MessageId] = msgId
  40. };
  41. var message = new Message(header, null);
  42. var mdMessage = _storage.StoreReceivedMessage("test.name", "test.group", message);
  43. Assert.NotNull(mdMessage);
  44. }
  45. [Fact]
  46. public void StoreReceivedExceptionMessageTest()
  47. {
  48. _storage.StoreReceivedExceptionMessage("test.name", "test.group", "");
  49. }
  50. [Fact]
  51. public async Task ChangePublishStateTest()
  52. {
  53. var msgId = SnowflakeId.Default().NextId().ToString();
  54. var header = new Dictionary<string, string>()
  55. {
  56. [Headers.MessageId] = msgId
  57. };
  58. var message = new Message(header, null);
  59. var mdMessage = _storage.StoreMessage("test.name", message);
  60. await _storage.ChangePublishStateAsync(mdMessage, StatusName.Succeeded);
  61. }
  62. [Fact]
  63. public async Task ChangeReceiveStateTest()
  64. {
  65. var msgId = SnowflakeId.Default().NextId().ToString();
  66. var header = new Dictionary<string, string>()
  67. {
  68. [Headers.MessageId] = msgId
  69. };
  70. var message = new Message(header, null);
  71. var mdMessage = _storage.StoreMessage("test.name", message);
  72. await _storage.ChangeReceiveStateAsync(mdMessage, StatusName.Succeeded);
  73. }
  74. }
  75. }