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.
 
 
 

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