Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

136 rindas
4.0 KiB

  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using DotNetCore.CAP.Abstractions;
  5. using DotNetCore.CAP.Models;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Xunit;
  8. namespace DotNetCore.CAP.Test
  9. {
  10. public class CapBuilderTest
  11. {
  12. [Fact]
  13. public void CanCreateInstanceAndGetService()
  14. {
  15. var services = new ServiceCollection();
  16. services.AddSingleton<ICapPublisher, MyProducerService>();
  17. var builder = new CapBuilder(services);
  18. Assert.NotNull(builder);
  19. var count = builder.Services.Count;
  20. Assert.Equal(1, count);
  21. var provider = services.BuildServiceProvider();
  22. var capPublisher = provider.GetService<ICapPublisher>();
  23. Assert.NotNull(capPublisher);
  24. }
  25. [Fact]
  26. public void CanAddCapService()
  27. {
  28. var services = new ServiceCollection();
  29. services.AddCap(x => { });
  30. var builder = services.BuildServiceProvider();
  31. var markService = builder.GetService<CapMarkerService>();
  32. Assert.NotNull(markService);
  33. }
  34. [Fact]
  35. public void CanOverridePublishService()
  36. {
  37. var services = new ServiceCollection();
  38. services.AddCap(x => { }).AddProducerService<MyProducerService>();
  39. var thingy = services.BuildServiceProvider()
  40. .GetRequiredService<ICapPublisher>() as MyProducerService;
  41. Assert.NotNull(thingy);
  42. }
  43. [Fact]
  44. public void CanOverrideContentSerialize()
  45. {
  46. var services = new ServiceCollection();
  47. services.AddCap(x => { }).AddContentSerializer<MyContentSerializer>();
  48. var thingy = services.BuildServiceProvider()
  49. .GetRequiredService<IContentSerializer>() as MyContentSerializer;
  50. Assert.NotNull(thingy);
  51. }
  52. [Fact]
  53. public void CanOverrideMessagePack()
  54. {
  55. var services = new ServiceCollection();
  56. services.AddCap(x => { }).AddMessagePacker<MyMessagePacker>();
  57. var thingy = services.BuildServiceProvider()
  58. .GetRequiredService<IMessagePacker>() as MyMessagePacker;
  59. Assert.NotNull(thingy);
  60. }
  61. [Fact]
  62. public void CanResolveCapOptions()
  63. {
  64. var services = new ServiceCollection();
  65. services.AddCap(x => { });
  66. var builder = services.BuildServiceProvider();
  67. var capOptions = builder.GetService<CapOptions>();
  68. Assert.NotNull(capOptions);
  69. }
  70. private class MyMessagePacker : IMessagePacker
  71. {
  72. public string Pack(CapMessage obj)
  73. {
  74. throw new NotImplementedException();
  75. }
  76. public CapMessage UnPack(string packingMessage)
  77. {
  78. throw new NotImplementedException();
  79. }
  80. }
  81. private class MyContentSerializer : IContentSerializer
  82. {
  83. public T DeSerialize<T>(string content)
  84. {
  85. throw new NotImplementedException();
  86. }
  87. public object DeSerialize(string content, Type type)
  88. {
  89. throw new NotImplementedException();
  90. }
  91. public string Serialize<T>(T obj)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. }
  96. private class MyProducerService : ICapPublisher
  97. {
  98. public ICapTransaction Transaction { get; }
  99. public Task PublishAsync<T>(string name, T contentObj, string callbackName = null,
  100. CancellationToken cancellationToken = default(CancellationToken))
  101. {
  102. throw new NotImplementedException();
  103. }
  104. public void Publish<T>(string name, T contentObj, string callbackName = null)
  105. {
  106. throw new NotImplementedException();
  107. }
  108. }
  109. }
  110. }