|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Threading.Tasks;
- using DotNetCore.CAP.Internal;
- using DotNetCore.CAP.Messages;
- using Microsoft.Extensions.DependencyInjection;
- using Xunit;
-
- namespace DotNetCore.CAP.Test
- {
- public class SubscribeInvokerTest
- {
- private readonly IServiceProvider _serviceProvider;
-
- public SubscribeInvokerTest()
- {
- var serviceCollection = new ServiceCollection();
- serviceCollection.AddLogging();
- serviceCollection.AddSingleton<ISubscribeInvoker, SubscribeInvoker>();
- _serviceProvider = serviceCollection.BuildServiceProvider();
- }
-
- private ISubscribeInvoker SubscribeInvoker => _serviceProvider.GetService<ISubscribeInvoker>();
-
- [Fact]
- public async Task InvokeTest()
- {
- var descriptor = new ConsumerExecutorDescriptor()
- {
- Attribute = new CandidatesTopic("fake.output.integer"),
- ServiceTypeInfo = typeof(FakeSubscriber).GetTypeInfo(),
- ImplTypeInfo = typeof(FakeSubscriber).GetTypeInfo(),
- MethodInfo = typeof(FakeSubscriber).GetMethod(nameof(FakeSubscriber.OutputIntegerSub)),
- Parameters = new List<ParameterDescriptor>()
- };
-
- var header = new Dictionary<string, string>();
- var message = new Message(header, null);
- var context = new ConsumerContext(descriptor, message);
-
- var ret = await SubscribeInvoker.InvokeAsync(context);
- Assert.Equal(int.MaxValue, ret.Result);
- }
- }
-
- public class FakeSubscriber : ICapSubscribe
- {
- [CapSubscribe("fake.output.integer")]
- public int OutputIntegerSub()
- {
- return int.MaxValue;
- }
- }
- }
|