public void Configure(BehaviorGraph graph) { var visitor = new BehaviorVisitor(_reasonToVisit); _configureAction(visitor); graph.VisitBehaviors(visitor); }
public void Activate(IEnumerable<IPackageInfo> packages, IPackageLog log) { var postActionsFinder = new BehaviorVisitor(_graph.Observer, "Looking for valid POST actions."); postActionsFinder.Filters.Add(x => x.Route != null); postActionsFinder.Filters.Add(x => x.Route.AllowedHttpMethods.Contains("POST")); postActionsFinder.Filters.Add(x => x.FirstCall() != null); postActionsFinder.Filters.Add(x => x.FirstCall().HasOutput); postActionsFinder.Filters.Add(x => x.FirstCall().HasInput); postActionsFinder.Actions += x => { var postAction = x.FirstCall(); var handlerActions = _graph.ActionsForHandler(postAction.HandlerType); var getAction = handlerActions .Where(h => h.ParentChain().Route != null) .Where(h => h.ParentChain().Route.AllowedHttpMethods.Contains("GET")) .Where(h => h.HasInput).Where(h => h.HasOutput) .FirstOrDefault(h => x.InputType().IsAssignableFrom(h.OutputType())); if (getAction == null) { return; } log.Trace("Linking validation descriptor for {0} against {1}.", postAction, getAction); _provider.Register(postAction, getAction.InputType()); }; _graph.VisitBehaviors(postActionsFinder); }
public void other_actions_should_not_be_wrapped() { var visitor = new BehaviorVisitor(new NulloConfigurationObserver(), ""); visitor.Filters += chain => chain.ContainsCall(call => call.Method.Name != "SomeAction"); visitor.Actions += chain => chain.Top.ShouldBeOfType<ActionCall>(); _graph.VisitBehaviors(visitor); }
public void SetUp() { visitor = new BehaviorVisitor(); chain = new BehaviorChain(); processor = MockRepository.GenerateMock<BehaviorProcessor>(); visitor.Actions += x => processor.Got(x); }
public void other_actions_should_not_be_wrapped() { var visitor = new BehaviorVisitor(""); visitor.Filters += chain => chain.Calls.Any(call => call.Method.Name != "SomeAction"); visitor.Actions += chain => chain.Top.Next.ShouldBeOfType<ActionCall>(); _graph.VisitBehaviors(visitor); }
public void should_add_new_behavior_node_to_graph() { _graph.Behaviors.ShouldHaveCount(2); var visitor = new BehaviorVisitor(new NulloConfigurationObserver(), ""); visitor.Filters += chain => !chain.Calls.Any(call => call.InputType() == typeof (InputModel)); visitor.Actions += chain => chain.Top.ShouldBeNull(); _graph.VisitBehaviors(visitor); }
public void other_actions_should_not_be_wrapped() { var visitor = new BehaviorVisitor(new NulloConfigurationObserver(), ""); visitor.Filters += chain => chain.Calls.Any(call => call.Method.Name != "SomeAction"); visitor.Filters += chain => chain.Calls.Any(call => call.HandlerType != typeof (AssetWriter)); visitor.Actions += chain => chain.Top.Next.ShouldBeOfType<ActionCall>(); _graph.VisitBehaviors(visitor); }
public void should_add_new_behavior_node_to_graph() { _graph.Behaviors.Count().ShouldEqual(2); var visitor = new BehaviorVisitor(""); visitor.Filters += chain => !chain.Calls.Any(call => call.InputType() == typeof (InputModel)); visitor.Filters += chain => !chain.Any(x => x is OutputCachingNode); visitor.Actions += chain => chain.Top.ShouldBeNull(); _graph.VisitBehaviors(visitor); }
public void SetUp() { visitor = new BehaviorVisitor("reasontovisit"); chain = new BehaviorChain(); call = ActionCall.For<TestController>(c => c.SomeAction(null)); chain.AddToEnd(call); processor = MockRepository.GenerateMock<BehaviorProcessor>(); visitor.Actions += x => processor.Got(x); }
public void other_actions_should_not_be_enriched() { var visitor = new BehaviorVisitor(new NulloConfigurationObserver(), ""); visitor.Filters += chain => chain.Calls.Any(call => call.Method.Name != "SomeAction"); visitor.Actions += chain => { chain.Top.ShouldBeOfType<ActionCall>(); chain.Top.Next.ShouldBeOfType<ConnegOutputNode>(); }; _graph.VisitBehaviors(visitor); }
public void someaction_call_should_be_wrapped() { var visitor = new BehaviorVisitor(new NulloConfigurationObserver(), ""); visitor.Filters += chain => chain.ContainsCall(call => call.Method.Name == "SomeAction"); visitor.Actions += chain => { var wrapper = chain.Top.ShouldBeOfType<Wrapper>(); wrapper.BehaviorType.ShouldEqual(typeof (FakeUnitOfWorkBehavior)); wrapper.Next.ShouldBeOfType<ActionCall>(); }; _graph.VisitBehaviors(visitor); }
public void all_behaviors_chains_should_start_with_the_declared_behavior() { BehaviorGraph graph = registry.BuildGraph(); graph.BehaviorChainCount.ShouldEqual(3); var visitor = new BehaviorVisitor(new NulloConfigurationObserver(), ""); visitor.Actions += chain => { var wrapper = chain.Top.ShouldBeOfType<Wrapper>(); wrapper.BehaviorType.ShouldEqual(typeof (FakeUnitOfWorkBehavior)); wrapper.Next.ShouldBeOfType<ActionCall>(); }; graph.VisitBehaviors(visitor); }
public void all_behaviors_chains_should_start_with_the_declared_behavior() { var graph = BehaviorGraph.BuildFrom(registry); graph.Behaviors.Count().ShouldEqual(3); var visitor = new BehaviorVisitor(""); visitor.Actions += chain => { // Don't bother with the asset node if (chain.Any(x => x is OutputCachingNode)) return; // Input node is first var wrapper = chain.Top.Next.ShouldBeOfType<Wrapper>(); wrapper.BehaviorType.ShouldEqual(typeof (FakeUnitOfWorkBehavior)); wrapper.Next.ShouldBeOfType<ActionCall>(); }; graph.VisitBehaviors(visitor); }
public void Configure(BehaviorGraph graph) { var visitor = new BehaviorVisitor(graph.Observer, _reasonToVisit); _configureAction(visitor); graph.VisitBehaviors(visitor); }