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

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