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.
 
 
 

58 lines
1.9 KiB

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