Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

83 lignes
2.4 KiB

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