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

30 lines
958 B

  1. using System.Collections.Concurrent;
  2. using System.Threading.Tasks;
  3. using FluentAssertions;
  4. using Xunit;
  5. namespace DotNetCore.CAP.MongoDB.Test
  6. {
  7. [Collection("MongoDB")]
  8. public class MongoDBUtilTest : DatabaseTestHost
  9. {
  10. [Fact]
  11. public async void GetNextSequenceValueAsync_Test()
  12. {
  13. var id = await new MongoDBUtil().GetNextSequenceValueAsync(Database, MongoDBOptions.ReceivedCollection);
  14. id.Should().BeGreaterThan(0);
  15. }
  16. [Fact]
  17. public void GetNextSequenceValue_Concurrency_Test()
  18. {
  19. var dic = new ConcurrentDictionary<int, int>();
  20. Parallel.For(0, 30, (x) =>
  21. {
  22. var id = new MongoDBUtil().GetNextSequenceValue(Database, MongoDBOptions.ReceivedCollection);
  23. id.Should().BeGreaterThan(0);
  24. dic.TryAdd(id, x).Should().BeTrue(); //The id shouldn't be same.
  25. });
  26. }
  27. }
  28. }