No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

93 líneas
3.3 KiB

  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 SqlServerStorageConnection _storage;
  13. public SqlServerStorageConnectionTest()
  14. {
  15. var options = GetService<SqlServerOptions>();
  16. var capOptions = GetService<CapOptions>();
  17. _storage = new SqlServerStorageConnection(options, capOptions);
  18. }
  19. [Fact]
  20. public async Task GetPublishedMessageAsync_Test()
  21. {
  22. var sql = "INSERT INTO [Cap].[Published]([Name],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) OUTPUT INSERTED.Id VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
  23. var publishMessage = new CapPublishedMessage
  24. {
  25. Name = "SqlServerStorageConnectionTest",
  26. Content = "",
  27. StatusName = StatusName.Scheduled
  28. };
  29. var insertedId = default(int);
  30. using (var connection = ConnectionUtil.CreateConnection())
  31. {
  32. insertedId = connection.QueryFirst<int>(sql, publishMessage);
  33. }
  34. var message = await _storage.GetPublishedMessageAsync(insertedId);
  35. Assert.NotNull(message);
  36. Assert.Equal("SqlServerStorageConnectionTest", message.Name);
  37. Assert.Equal(StatusName.Scheduled, message.StatusName);
  38. }
  39. [Fact]
  40. public async Task StoreReceivedMessageAsync_Test()
  41. {
  42. var receivedMessage = new CapReceivedMessage
  43. {
  44. Name = "SqlServerStorageConnectionTest",
  45. Content = "",
  46. Group = "mygroup",
  47. StatusName = StatusName.Scheduled
  48. };
  49. Exception exception = null;
  50. try
  51. {
  52. await _storage.StoreReceivedMessageAsync(receivedMessage);
  53. }
  54. catch (Exception ex)
  55. {
  56. exception = ex;
  57. }
  58. Assert.Null(exception);
  59. }
  60. [Fact]
  61. public async Task GetReceivedMessageAsync_Test()
  62. {
  63. var sql = $@"
  64. INSERT INTO [Cap].[Received]([Name],[Group],[Content],[Retries],[Added],[ExpiresAt],[StatusName]) OUTPUT INSERTED.Id
  65. VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
  66. var receivedMessage = new CapReceivedMessage
  67. {
  68. Name = "SqlServerStorageConnectionTest",
  69. Content = "",
  70. Group = "mygroup",
  71. StatusName = StatusName.Scheduled
  72. };
  73. var insertedId = default(int);
  74. using (var connection = ConnectionUtil.CreateConnection())
  75. {
  76. insertedId = connection.QueryFirst<int>(sql, receivedMessage);
  77. }
  78. var message = await _storage.GetReceivedMessageAsync(insertedId);
  79. Assert.NotNull(message);
  80. Assert.Equal(StatusName.Scheduled, message.StatusName);
  81. Assert.Equal("SqlServerStorageConnectionTest", message.Name);
  82. Assert.Equal("mygroup", message.Group);
  83. }
  84. }
  85. }