Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

110 rader
3.4 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Xunit;
  5. using System.Data;
  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(string name, string content)
  53. {
  54. throw new NotImplementedException();
  55. }
  56. public void Publish<T>(string name, T contentObj)
  57. {
  58. throw new NotImplementedException();
  59. }
  60. public void Publish(string name, string content, IDbConnection dbConnection, IDbTransaction dbTransaction = null)
  61. {
  62. throw new NotImplementedException();
  63. }
  64. public void Publish<T>(string name, T contentObj, IDbConnection dbConnection, IDbTransaction dbTransaction = null)
  65. {
  66. throw new NotImplementedException();
  67. }
  68. public Task PublishAsync(string topic, string content)
  69. {
  70. throw new NotImplementedException();
  71. }
  72. public Task PublishAsync<T>(string topic, T contentObj)
  73. {
  74. throw new NotImplementedException();
  75. }
  76. public Task PublishAsync(string topic, string content, IDbConnection dbConnection)
  77. {
  78. throw new NotImplementedException();
  79. }
  80. public Task PublishAsync(string topic, string content, IDbConnection dbConnection, IDbTransaction dbTransaction)
  81. {
  82. throw new NotImplementedException();
  83. }
  84. public Task PublishAsync<T>(string name, T contentObj, IDbConnection dbConnection, IDbTransaction dbTransaction = null)
  85. {
  86. throw new NotImplementedException();
  87. }
  88. }
  89. }
  90. }