Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

CAP.BuilderTest.cs 3.5 KiB

7 anni fa
7 anni fa
7 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Data;
  3. using System.Threading.Tasks;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Xunit;
  6. namespace DotNetCore.CAP.Test
  7. {
  8. public class CapBuilderTest
  9. {
  10. [Fact]
  11. public void CanCreateInstanceAndGetService()
  12. {
  13. var services = new ServiceCollection();
  14. services.AddSingleton<ICapPublisher, MyProducerService>();
  15. var builder = new CapBuilder(services);
  16. Assert.NotNull(builder);
  17. var count = builder.Services.Count;
  18. Assert.Equal(1, count);
  19. var provider = services.BuildServiceProvider();
  20. var capPublisher = provider.GetService<ICapPublisher>();
  21. Assert.NotNull(capPublisher);
  22. }
  23. [Fact]
  24. public void CanAddCapService()
  25. {
  26. var services = new ServiceCollection();
  27. services.AddCap(x => { });
  28. var builder = services.BuildServiceProvider();
  29. var markService = builder.GetService<CapMarkerService>();
  30. Assert.NotNull(markService);
  31. }
  32. [Fact]
  33. public void CanOverridePublishService()
  34. {
  35. var services = new ServiceCollection();
  36. services.AddCap(x => { }).AddProducerService<MyProducerService>();
  37. var thingy = services.BuildServiceProvider()
  38. .GetRequiredService<ICapPublisher>() as MyProducerService;
  39. Assert.NotNull(thingy);
  40. }
  41. [Fact]
  42. public void CanResolveCapOptions()
  43. {
  44. var services = new ServiceCollection();
  45. services.AddCap(x => { });
  46. var builder = services.BuildServiceProvider();
  47. var capOptions = builder.GetService<CapOptions>();
  48. Assert.NotNull(capOptions);
  49. }
  50. private class MyProducerService : ICapPublisher
  51. {
  52. public void Publish<T>(string name, T contentObj, string callbackName = null)
  53. {
  54. throw new NotImplementedException();
  55. }
  56. public void Publish<T>(string name, T contentObj, IDbConnection dbConnection, string callbackName = null, IDbTransaction dbTransaction = null)
  57. {
  58. throw new NotImplementedException();
  59. }
  60. public Task PublishAsync(string topic, string content)
  61. {
  62. throw new NotImplementedException();
  63. }
  64. public Task PublishAsync<T>(string topic, T contentObj)
  65. {
  66. throw new NotImplementedException();
  67. }
  68. public Task PublishAsync(string topic, string content, IDbConnection dbConnection)
  69. {
  70. throw new NotImplementedException();
  71. }
  72. public Task PublishAsync(string topic, string content, IDbConnection dbConnection, IDbTransaction dbTransaction)
  73. {
  74. throw new NotImplementedException();
  75. }
  76. public Task PublishAsync<T>(string name, T contentObj, IDbConnection dbConnection, IDbTransaction dbTransaction = null)
  77. {
  78. throw new NotImplementedException();
  79. }
  80. public Task PublishAsync<T>(string name, T contentObj, string callbackName = null)
  81. {
  82. throw new NotImplementedException();
  83. }
  84. public Task PublishAsync<T>(string name, T contentObj, IDbConnection dbConnection, string callbackName = null, IDbTransaction dbTransaction = null)
  85. {
  86. throw new NotImplementedException();
  87. }
  88. }
  89. }
  90. }