Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SubscribeInvokerTest.cs 1.9 KiB

il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
il y a 5 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }