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.
 
 
 

67 lines
2.3 KiB

  1. using System.Threading;
  2. using DotNetCore.CAP.Infrastructure;
  3. using DotNetCore.CAP.Models;
  4. using FluentAssertions;
  5. using Microsoft.Extensions.Logging.Abstractions;
  6. using MongoDB.Driver;
  7. using Xunit;
  8. using Xunit.Priority;
  9. namespace DotNetCore.CAP.MongoDB.Test
  10. {
  11. [TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
  12. public class MongoDBStorageConnectionTest
  13. {
  14. private MongoClient _client;
  15. private MongoDBOptions _options;
  16. private MongoDBStorage _storage;
  17. private IStorageConnection _connection;
  18. public MongoDBStorageConnectionTest()
  19. {
  20. _client = new MongoClient(ConnectionUtil.ConnectionString);
  21. _options = new MongoDBOptions();
  22. _storage = new MongoDBStorage(new CapOptions(), _options, _client, NullLogger<MongoDBStorage>.Instance);
  23. _connection = _storage.GetConnection();
  24. }
  25. [Fact, Priority(1)]
  26. public async void StoreReceivedMessageAsync_TestAsync()
  27. {
  28. await _storage.InitializeAsync(default(CancellationToken));
  29. var id = await
  30. _connection.StoreReceivedMessageAsync(new CapReceivedMessage(new MessageContext
  31. {
  32. Group = "test",
  33. Name = "test",
  34. Content = "test-content"
  35. }));
  36. id.Should().BeGreaterThan(0);
  37. }
  38. [Fact, Priority(2)]
  39. public void ChangeReceivedState_Test()
  40. {
  41. var collection = _client.GetDatabase(_options.Database).GetCollection<CapReceivedMessage>(_options.ReceivedCollection);
  42. var msg = collection.Find(x => true).FirstOrDefault();
  43. _connection.ChangeReceivedState(msg.Id, StatusName.Scheduled).Should().BeTrue();
  44. collection.Find(x => x.Id == msg.Id).FirstOrDefault()?.StatusName.Should().Be(StatusName.Scheduled);
  45. }
  46. [Fact, Priority(3)]
  47. public async void GetReceivedMessagesOfNeedRetry_TestAsync()
  48. {
  49. var msgs = await _connection.GetReceivedMessagesOfNeedRetry();
  50. msgs.Should().HaveCountGreaterThan(0);
  51. }
  52. [Fact, Priority(4)]
  53. public void GetReceivedMessageAsync_Test()
  54. {
  55. var msg = _connection.GetReceivedMessageAsync(1);
  56. msg.Should().NotBeNull();
  57. }
  58. }
  59. }