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.
 
 
 

72 lines
2.1 KiB

  1. using System;
  2. using System.Linq;
  3. using DotNetCore.CAP.Dashboard.Monitoring;
  4. using DotNetCore.CAP.Infrastructure;
  5. using DotNetCore.CAP.Models;
  6. using FluentAssertions;
  7. using Xunit;
  8. namespace DotNetCore.CAP.MongoDB.Test
  9. {
  10. [Collection("MongoDB")]
  11. public class MongoDBMonitoringApiTest : DatabaseTestHost
  12. {
  13. private readonly MongoDBMonitoringApi _api;
  14. public MongoDBMonitoringApiTest()
  15. {
  16. _api = new MongoDBMonitoringApi(MongoClient, MongoDBOptions);
  17. var helper = new MongoDBUtil();
  18. var collection = Database.GetCollection<CapPublishedMessage>(MongoDBOptions.PublishedCollection);
  19. collection.InsertMany(new[]
  20. {
  21. new CapPublishedMessage
  22. {
  23. Id = helper.GetNextSequenceValue(Database,MongoDBOptions.PublishedCollection),
  24. Added = DateTime.Now.AddHours(-1),
  25. StatusName = "Failed",
  26. Content = "abc"
  27. },
  28. new CapPublishedMessage
  29. {
  30. Id = helper.GetNextSequenceValue(Database,MongoDBOptions.PublishedCollection),
  31. Added = DateTime.Now,
  32. StatusName = "Failed",
  33. Content = "bbc"
  34. }
  35. });
  36. }
  37. [Fact]
  38. public void HourlyFailedJobs_Test()
  39. {
  40. var result = _api.HourlyFailedJobs(MessageType.Publish);
  41. result.Should().HaveCount(24);
  42. }
  43. [Fact]
  44. public void Messages_Test()
  45. {
  46. var messages =
  47. _api.Messages(new MessageQueryDto
  48. {
  49. MessageType = MessageType.Publish,
  50. StatusName = StatusName.Failed,
  51. Content = "b",
  52. CurrentPage = 1,
  53. PageSize = 1
  54. });
  55. messages.Should().HaveCount(1);
  56. messages.First().Content.Should().Contain("b");
  57. }
  58. [Fact]
  59. public void PublishedFailedCount_Test()
  60. {
  61. var count = _api.PublishedFailedCount();
  62. count.Should().BeGreaterThan(1);
  63. }
  64. }
  65. }