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.

SqlServerStorageConnectionTest.cs 3.2 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
7 years ago
7 years ago
7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Threading.Tasks;
  3. using Dapper;
  4. using DotNetCore.CAP.Infrastructure;
  5. using DotNetCore.CAP.Models;
  6. using Xunit;
  7. namespace DotNetCore.CAP.SqlServer.Test
  8. {
  9. [Collection("sqlserver")]
  10. public class SqlServerStorageConnectionTest : DatabaseTestHost
  11. {
  12. private readonly SqlServerStorageConnection _storage;
  13. public SqlServerStorageConnectionTest()
  14. {
  15. _storage = new SqlServerStorageConnection(SqlSeverOptions, CapOptions);
  16. }
  17. [Fact]
  18. public async Task GetPublishedMessageAsync_Test()
  19. {
  20. var sql = "INSERT INTO [Cap].[Published]([Id],[Name],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) VALUES(@Id,@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
  21. var insertedId = SnowflakeId.Default().NextId();
  22. var publishMessage = new CapPublishedMessage
  23. {
  24. Id= insertedId,
  25. Name = "SqlServerStorageConnectionTest",
  26. Content = "",
  27. StatusName = StatusName.Scheduled
  28. };
  29. using (var connection = ConnectionUtil.CreateConnection())
  30. {
  31. await connection.ExecuteAsync(sql, publishMessage);
  32. }
  33. var message = await _storage.GetPublishedMessageAsync(insertedId);
  34. Assert.NotNull(message);
  35. Assert.Equal("SqlServerStorageConnectionTest", message.Name);
  36. Assert.Equal(StatusName.Scheduled, message.StatusName);
  37. }
  38. [Fact]
  39. public void StoreReceivedMessageAsync_Test()
  40. {
  41. var receivedMessage = new CapReceivedMessage
  42. {
  43. Name = "SqlServerStorageConnectionTest",
  44. Content = "",
  45. Group = "mygroup",
  46. StatusName = StatusName.Scheduled
  47. };
  48. Exception exception = null;
  49. try
  50. {
  51. _storage.StoreReceivedMessage(receivedMessage);
  52. }
  53. catch (Exception ex)
  54. {
  55. exception = ex;
  56. }
  57. Assert.Null(exception);
  58. }
  59. [Fact]
  60. public async Task GetReceivedMessageAsync_Test()
  61. {
  62. var sql = @"INSERT INTO [Cap].[Received]([Id],[Name],[Group],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) VALUES(@Id,@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
  63. var insertedId = SnowflakeId.Default().NextId();
  64. var receivedMessage = new CapReceivedMessage
  65. {
  66. Id= insertedId,
  67. Name = "SqlServerStorageConnectionTest",
  68. Content = "",
  69. Group = "mygroup",
  70. StatusName = StatusName.Scheduled
  71. };
  72. using (var connection = ConnectionUtil.CreateConnection())
  73. {
  74. await connection.ExecuteAsync(sql, receivedMessage);
  75. }
  76. var message = await _storage.GetReceivedMessageAsync(insertedId);
  77. Assert.NotNull(message);
  78. Assert.Equal(StatusName.Scheduled, message.StatusName);
  79. Assert.Equal("SqlServerStorageConnectionTest", message.Name);
  80. Assert.Equal("mygroup", message.Group);
  81. }
  82. }
  83. }