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.

SubscribeInvokerTest.cs 1.8 KiB

5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Threading.Tasks;
  5. using DotNetCore.CAP.Internal;
  6. using DotNetCore.CAP.Messages;
  7. using Microsoft.Extensions.DependencyInjection;
  8. using Xunit;
  9. namespace DotNetCore.CAP.Test
  10. {
  11. public class SubscribeInvokerTest
  12. {
  13. private readonly IServiceProvider _serviceProvider;
  14. public SubscribeInvokerTest()
  15. {
  16. var serviceCollection = new ServiceCollection();
  17. serviceCollection.AddLogging();
  18. serviceCollection.AddSingleton<ISubscribeInvoker, SubscribeInvoker>();
  19. _serviceProvider = serviceCollection.BuildServiceProvider();
  20. }
  21. private ISubscribeInvoker SubscribeInvoker => _serviceProvider.GetService<ISubscribeInvoker>();
  22. [Fact]
  23. public async Task InvokeTest()
  24. {
  25. var descriptor = new ConsumerExecutorDescriptor()
  26. {
  27. Attribute = new CandidatesTopic("fake.output.integer"),
  28. ServiceTypeInfo = typeof(FakeSubscriber).GetTypeInfo(),
  29. ImplTypeInfo = typeof(FakeSubscriber).GetTypeInfo(),
  30. MethodInfo = typeof(FakeSubscriber).GetMethod(nameof(FakeSubscriber.OutputIntegerSub)),
  31. Parameters = new List<ParameterDescriptor>()
  32. };
  33. var header = new Dictionary<string, string>();
  34. var message = new Message(header, null);
  35. var context = new ConsumerContext(descriptor, message);
  36. var ret = await SubscribeInvoker.InvokeAsync(context);
  37. Assert.Equal(int.MaxValue, ret.Result);
  38. }
  39. }
  40. public class FakeSubscriber : ICapSubscribe
  41. {
  42. [CapSubscribe("fake.output.integer")]
  43. public int OutputIntegerSub()
  44. {
  45. return int.MaxValue;
  46. }
  47. }
  48. }