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.
 
 
 

88 line
2.8 KiB

  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 async Task 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 = await _storage.StoreMessageAsync("test.name", message);
  31. Assert.NotNull(mdMessage);
  32. }
  33. [Fact]
  34. public async Task 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 = await _storage.StoreReceivedMessageAsync("test.name", "test.group", message);
  43. Assert.NotNull(mdMessage);
  44. }
  45. [Fact]
  46. public async Task StoreReceivedExceptionMessageTest()
  47. {
  48. await _storage.StoreReceivedExceptionMessageAsync("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 = await _storage.StoreMessageAsync("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 = await _storage.StoreMessageAsync("test.name", message);
  72. await _storage.ChangeReceiveStateAsync(mdMessage, StatusName.Succeeded);
  73. }
  74. }
  75. }