No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

168 líneas
5.1 KiB

  1. using System;
  2. using System.Data;
  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 void Publish<T>(string name, T contentObj, string callbackName = null)
  99. {
  100. throw new NotImplementedException();
  101. }
  102. public void Publish<T>(string name, T contentObj, IDbTransaction dbTransaction, string callbackName = null)
  103. {
  104. throw new NotImplementedException();
  105. }
  106. public Task PublishAsync(string topic, string content)
  107. {
  108. throw new NotImplementedException();
  109. }
  110. public Task PublishAsync<T>(string topic, T contentObj)
  111. {
  112. throw new NotImplementedException();
  113. }
  114. public Task PublishAsync(string topic, string content, IDbConnection dbConnection)
  115. {
  116. throw new NotImplementedException();
  117. }
  118. public Task PublishAsync(string topic, string content, IDbConnection dbConnection, IDbTransaction dbTransaction)
  119. {
  120. throw new NotImplementedException();
  121. }
  122. public Task PublishAsync<T>(string name, T contentObj, IDbConnection dbConnection, IDbTransaction dbTransaction = null)
  123. {
  124. throw new NotImplementedException();
  125. }
  126. public Task PublishAsync<T>(string name, T contentObj, string callbackName = null)
  127. {
  128. throw new NotImplementedException();
  129. }
  130. public Task PublishAsync<T>(string name, T contentObj, IDbTransaction dbTransaction, string callbackName = null)
  131. {
  132. throw new NotImplementedException();
  133. }
  134. }
  135. }
  136. }