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.
 
 
 

38 lines
1.5 KiB

  1. using System.Threading;
  2. using FluentAssertions;
  3. using Microsoft.Extensions.Logging.Abstractions;
  4. using MongoDB.Bson;
  5. using MongoDB.Driver;
  6. using Xunit;
  7. namespace DotNetCore.CAP.MongoDB.Test
  8. {
  9. public class MongoDBStorageTest
  10. {
  11. private readonly MongoClient _client;
  12. public MongoDBStorageTest()
  13. {
  14. _client = new MongoClient(ConnectionUtil.ConnectionString);
  15. }
  16. [Fact]
  17. public async void InitializeAsync_Test()
  18. {
  19. var options = new MongoDBOptions();
  20. var storage = new MongoDBStorage(new CapOptions(), options, _client, NullLogger<MongoDBStorage>.Instance);
  21. await storage.InitializeAsync(default(CancellationToken));
  22. var names = _client.ListDatabaseNames()?.ToList();
  23. names.Should().Contain(options.Database);
  24. var collections = _client.GetDatabase(options.Database).ListCollectionNames()?.ToList();
  25. collections.Should().Contain(options.PublishedCollection);
  26. collections.Should().Contain(options.ReceivedCollection);
  27. collections.Should().Contain("Counter");
  28. var collection = _client.GetDatabase(options.Database).GetCollection<BsonDocument>("Counter");
  29. collection.CountDocuments(new BsonDocument { { "_id", options.PublishedCollection } }).Should().Be(1);
  30. collection.CountDocuments(new BsonDocument { { "_id", options.ReceivedCollection } }).Should().Be(1);
  31. }
  32. }
  33. }