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.
 
 
 

71 lines
2.0 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 collection = Database.GetCollection<CapPublishedMessage>(MongoDBOptions.PublishedCollection);
  18. collection.InsertMany(new[]
  19. {
  20. new CapPublishedMessage
  21. {
  22. Id = SnowflakeId.Default().NextId(),
  23. Added = DateTime.Now.AddHours(-1),
  24. StatusName = "Failed",
  25. Content = "abc"
  26. },
  27. new CapPublishedMessage
  28. {
  29. Id = SnowflakeId.Default().NextId(),
  30. Added = DateTime.Now,
  31. StatusName = "Failed",
  32. Content = "bbc"
  33. }
  34. });
  35. }
  36. [Fact]
  37. public void HourlyFailedJobs_Test()
  38. {
  39. var result = _api.HourlyFailedJobs(MessageType.Publish);
  40. result.Should().HaveCount(24);
  41. }
  42. [Fact]
  43. public void Messages_Test()
  44. {
  45. var messages =
  46. _api.Messages(new MessageQueryDto
  47. {
  48. MessageType = MessageType.Publish,
  49. StatusName = StatusName.Failed,
  50. Content = "b",
  51. CurrentPage = 1,
  52. PageSize = 1
  53. });
  54. messages.Should().HaveCount(1);
  55. messages.First().Content.Should().Contain("b");
  56. }
  57. [Fact]
  58. public void PublishedFailedCount_Test()
  59. {
  60. var count = _api.PublishedFailedCount();
  61. count.Should().BeGreaterThan(1);
  62. }
  63. }
  64. }