public async Task T_SendAsync_Filterが設定されている場合は順番に実行される() { var services = new ServiceCollection(); services.AddMediatR(typeof(ServicePing).Assembly); var check = new FilterExecutionCheck(); services.AddSingleton(check); var handlerCheck = new ExecuteCheck(); services.AddTransient(_ => handlerCheck); var provider = services.BuildServiceProvider(); var serviceFactory = provider.GetService<ServiceFactory>(); var registry = new ServiceRegistry(); registry.Add(typeof(ServicePing), typeof(Filter1), typeof(Filter2)); var client = new DefaultMediatorClient(registry, new ListenerRegistry(), serviceFactory!, new InternalScopedServiceFactoryFactory(serviceFactory!), new TestLogger()); var pong = await client.SendAsync<Pong>("/ping", new ServicePing() { Value = "Ping" }); pong!.Value.Should().Be("Ping Pong"); check.Checks.Should().HaveCount(2); check.Checks[0].Should().Be("1"); check.Checks[1].Should().Be("2"); }
public async Task GeneralExecutionTest() { bool executed = false; void Nothing() { } Task NothingAsync() => Task.CompletedTask; void Execute() => executed = true; Task ExecuteAsync() { executed = true; return(Task.CompletedTask); } int[] choice = { Normal, Async }; IEnumerable <IEnumerable <int> > options = choice.Select(x => new[] { x }); ProgressOptions progressOptions = ops => Generator.GenerateOptions(ops, choice); ProgressSequence progressSequence = (gwts, option, _, isLast) => { switch (option) { case Normal: gwts = isLast ? gwts.SelectMany(x => Generator.GenerateCalls(x, Execute)) : gwts.SelectMany(x => Generator.GenerateCalls(x, Nothing)); break; case Async: gwts = isLast ? gwts.SelectMany(x => Generator.GenerateCalls(x, ExecuteAsync)) : gwts.SelectMany(x => Generator.GenerateCalls(x, NothingAsync)); break; } return(gwts); }; ExecuteCheck executeCheck = async seq => { executed = false; var cont = seq(); if (cont is IAsyncContinuation asyncCont) { await asyncCont; } executed.Should().BeTrue(); }; await Test(options, progressOptions, progressSequence, executeCheck); }
public async Task SendAsync_Mediatorが実行されるが結果は捨てられる() { var services = new ServiceCollection(); services.AddMediatR(typeof(ServicePing).Assembly); var check = new ExecuteCheck(); services.AddTransient(_ => check); var provider = services.BuildServiceProvider(); var serviceFactory = provider.GetService<ServiceFactory>()!; var registry = new ServiceRegistry(); registry.Add(typeof(ServicePing)); var client = new DefaultMediatorClient(registry, new ListenerRegistry(), serviceFactory!, new InternalScopedServiceFactoryFactory(serviceFactory!), new TestLogger()); await client.SendAsync("/ping", new ServicePing() { Value = "Ping" }); check.Executed.Should().BeTrue(); }
public async Task T_SendAsync_戻り値がUnitの場合はnullで返される() { var services = new ServiceCollection(); services.AddMediatR(typeof(ServicePing).Assembly); var check = new ExecuteCheck(); services.AddTransient(_ => check); var provider = services.BuildServiceProvider(); var serviceFactory = provider.GetService<ServiceFactory>(); var registry = new ServiceRegistry(); registry.Add(typeof(VoidServicePing)); var client = new DefaultMediatorClient(registry, new ListenerRegistry(), serviceFactory!, new InternalScopedServiceFactoryFactory(serviceFactory!), new TestLogger()); var pong = await client.SendAsync<Pong>("/ping/void", new { Value = "Ping" }); pong.Should().BeNull(); check.Executed.Should().BeTrue(); }
public async Task T_SendAsync_引数と戻り値は変換可能_Jsonシリアライズデシリアライズに依存() { var services = new ServiceCollection(); services.AddMediatR(typeof(ServicePing).Assembly); var check = new ExecuteCheck(); services.AddTransient(_ => check); var provider = services.BuildServiceProvider(); var serviceFactory = provider.GetService<ServiceFactory>(); var registry = new ServiceRegistry(); registry.Add(typeof(ServicePing)); var client = new DefaultMediatorClient(registry, new ListenerRegistry(), serviceFactory!, new InternalScopedServiceFactoryFactory(serviceFactory!), new TestLogger()); var pong = await client.SendAsync<LocalPong>("/ping", new { Value = "Ping" }); pong!.Value.Should().Be("Ping Pong"); check.Executed.Should().BeTrue(); }
public async Task SequentialExecutionTest() { List <int> numbers = new List <int>(); Action DoCount(int x) => () => numbers.Add(x); AsyncAction DoCountAsync(int x) => () => { numbers.Add(x); return(Task.CompletedTask); }; var choice = new[] { Count, CountAsync }; var options = choice.Select(x => new[] { x }); ProgressOptions progressOptions = ops => Generator.GenerateOptions(ops, choice); ProgressSequence progressSequence = (gwts, option, i, _) => { switch (option) { case Count: gwts = gwts.SelectMany(x => Generator.GenerateCalls(x, DoCount(i))); break; case CountAsync: gwts = gwts.SelectMany(x => Generator.GenerateCalls(x, DoCountAsync(i))); break; } return(gwts); }; ExecuteCheck executeCheck = async seq => { numbers.Clear(); var cont = seq(); if (cont is IAsyncContinuation asyncCont) { await asyncCont; } numbers.Should().BeInAscendingOrder(); }; await Test(options, progressOptions, progressSequence, executeCheck); }
public ServiceNullPingHandler(ExecuteCheck check) { this.check = check; }
public VoidServicePingHandler(ExecuteCheck check) { this.check = check; }
private async Task TestSequence(Func <GivenWhenThen> start, int level, int[] option, ProgressSequence progress, ExecuteCheck executeCheck) { IEnumerable <Func <object> > gwts = new Func <object>[] { start }; for (int i = 0; i < level; i += 1) { gwts = progress(gwts, option[i], i, false); } gwts = progress(gwts, option[level], level, true); foreach (var e in gwts) { await executeCheck(e); } }
public async Task Test(IEnumerable <IEnumerable <int> > initialOptions, ProgressOptions progressOptions, ProgressSequence progressSequence, ExecuteCheck executeCheck) { var options = initialOptions; for (int level = 0; level < 7; level += 1) { var ops = options.Select(x => x.ToArray()).ToList(); foreach (var option in ops) { Func <GivenWhenThen> start = () => this; await TestSequence(start, level, option, progressSequence, executeCheck); } options = progressOptions(ops); } }