public async Task Handle_WithBehaviorsが設定されていない場合は何も実行されない() { var list = new List <string>(); var factory = new ServiceFactory(type => { return(Activator.CreateInstance(type, list)); }); var perReq = new PerRequestBehavior <Req2, Res>(factory); await perReq.Handle(new Req2(), new CancellationToken(), () => Task.FromResult(new Res())); list.Count.Should().Be(0); }
public async Task Handle_WithBehaviorAttributeに設定されているBehaviorが実行される() { var list = new List <string>(); var factory = new ServiceFactory(type => { return(Activator.CreateInstance(type, list)); }); var perReq = new PerRequestBehavior <Req1, Res>(factory); await perReq.Handle(new Req1(), new CancellationToken(), () => Task.FromResult(new Res())); list.Count.Should().Be(6); list[0].Should().Be(TestBehaviorMessages.StartMessage3); list[1].Should().Be(TestBehaviorMessages.StartMessage1); list[2].Should().Be(TestBehaviorMessages.StartMessage2); list[3].Should().Be(TestBehaviorMessages.EndMessage2); list[4].Should().Be(TestBehaviorMessages.EndMessage1); list[5].Should().Be(TestBehaviorMessages.EndMessage3); }
public async Task Handle_ServiceFactoryからインスタンスが返されないBehaviorはスキップされる() { var list = new List <string>(); var factory = new ServiceFactory(type => { if (type == typeof(TestBehavior1 <Req1, Res>)) { return(null); } return(Activator.CreateInstance(type, list)); }); var perReq = new PerRequestBehavior <Req1, Res>(factory); await perReq.Handle(new Req1(), new CancellationToken(), () => Task.FromResult(new Res())); list.Count.Should().Be(4); list[0].Should().Be(TestBehaviorMessages.StartMessage3); list[1].Should().Be(TestBehaviorMessages.StartMessage2); list[2].Should().Be(TestBehaviorMessages.EndMessage2); list[3].Should().Be(TestBehaviorMessages.EndMessage3); }