You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

81 lines
2.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using Microsoft.Extensions.Options;
  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 CanResolveCapOptions()
  36. {
  37. var services = new ServiceCollection();
  38. services.AddCap(x => { });
  39. var builder = services.BuildServiceProvider();
  40. var capOptions = builder.GetService<IOptions<CapOptions>>().Value;
  41. Assert.NotNull(capOptions);
  42. }
  43. private class MyProducerService : ICapPublisher
  44. {
  45. public IServiceProvider ServiceProvider { get; }
  46. public AsyncLocal<ICapTransaction> Transaction { get; }
  47. public Task PublishAsync<T>(string name, T contentObj, string callbackName = null,
  48. CancellationToken cancellationToken = default(CancellationToken))
  49. {
  50. throw new NotImplementedException();
  51. }
  52. public Task PublishAsync<T>(string name, T contentObj, IDictionary<string, string> optionHeaders = null,
  53. CancellationToken cancellationToken = default)
  54. {
  55. throw new NotImplementedException();
  56. }
  57. public void Publish<T>(string name, T contentObj, string callbackName = null)
  58. {
  59. throw new NotImplementedException();
  60. }
  61. public void Publish<T>(string name, T contentObj, IDictionary<string, string> headers)
  62. {
  63. throw new NotImplementedException();
  64. }
  65. }
  66. }
  67. }