Ejemplo n.º 1
0
        public void ResponseSelectFilterSuccessSingleResponseTest()
        {
            #region TestSetup
            var Scenarios   = fakerScenario.Generate(10);
            var ScenarioIds = Scenarios.Select(s => s.Id).ToList();

            var random = new Random(42);
            var SelectedScenarioIndex = random.Next(Scenarios.Count);
            #endregion

            List <MatchResult> rules = new List <MatchResult>();
            rules.AddRange(ScenarioIds.Select(scenario => new MatchResult(MatchResultType.Success, scenario, false)));

            var port = new ProcessMessagePort()
            {
                Scenarios          = Scenarios,
                HeaderMatchResults = rules,
                QueryMatchResults  = ScenarioIds.Take(SelectedScenarioIndex).Select(scenario => new MatchResult(MatchResultType.Success, scenario, false)).ToList(),
                BodyMatchResults   = ScenarioIds.Take(SelectedScenarioIndex + 1).Select(scenario => new MatchResult(MatchResultType.Success, scenario, false)).ToList(),
            };

            var Target = new ResponseSelectorFilter <ProcessMessagePort>(new TemplateContext());

            var Actual   = Target.Process(port).SelectedResponse;
            var Expected = Scenarios[0].Response;
            Assert.Equal(Expected, Actual);
        }
Ejemplo n.º 2
0
        public void ResponseSelectFilterSuccessMultipleResponseTest()
        {
            #region TestSetup
            var Scenarios = fakerScenario.Generate(10);

            var random = new Random(42);

            var SelectedScenariosRange      = random.Next(2, Scenarios.Count);
            var SelectedScenariosStartIndex = random.Next(Scenarios.Count - SelectedScenariosRange);
            var SelectedScenarios           = Scenarios.Skip(SelectedScenariosStartIndex).Take(SelectedScenariosRange).ToList();
            var SelectedScenarioIndex       = random.Next(Scenarios.Count);

            var PossibleResponses = SelectedScenarios.Select(s => s.Response);
            #endregion

            var port = new ProcessMessagePort()
            {
                Scenarios          = Scenarios,
                HeaderMatchResults = Scenarios.Select(scenario => new MatchResult(MatchResultType.Success, scenario.Id, false)).ToList(),
                QueryMatchResults  = Scenarios.Skip(SelectedScenarioIndex).Select(scenario => new MatchResult(MatchResultType.Success, scenario.Id, false)).ToList(),
                BodyMatchResults   = Scenarios.Take(SelectedScenarioIndex + 1).Select(scenario => new MatchResult(MatchResultType.Success, scenario.Id, false)).ToList(),
            };

            var Target = new ResponseSelectorFilter <ProcessMessagePort>(new TemplateContext());

            var Actual = Target.Process(port).SelectedResponse;
            Assert.Contains(Actual, PossibleResponses);
        }
Ejemplo n.º 3
0
        public void ResponseSelectorFilterFaultedTest()
        {
            var port = new ProcessMessagePort()
            {
                Faults = new List <string> {
                    "fault"
                }
            };

            var Target = new ResponseSelectorFilter <ProcessMessagePort>(new TemplateContext());

            var Actual = Target.Process(port).SelectedResponse;

            Assert.Null(Actual);
        }
Ejemplo n.º 4
0
        public void ResponseSelectorFilterNoResponseFoundTest()
        {
            #region TestSetup
            var Scenarios = new List <Scenario>();
            #endregion

            var port = new ProcessMessagePort()
            {
                Scenarios = Scenarios,
            };

            var Target = new ResponseSelectorFilter <ProcessMessagePort>(new TemplateContext());

            var Actual   = Target.Process(port).SelectedResponse;
            var Expected = new MockResponse();

            Assert.Equal(Expected, Actual);
        }
Ejemplo n.º 5
0
 public MockServerProcessor(
     PathValidationFilter <ProcessMessagePort> pathValidationFilter,
     QueryMatchFilter <ProcessMessagePort> queryMatchFilter,
     EndpointMatchFilter <ProcessMessagePort> endpointMatchFilter,
     BodyMatchFilter <ProcessMessagePort> bodyMatchFilter,
     HeaderMatchFilter <ProcessMessagePort> headerMatchFilter,
     UrlMatchFilter <ProcessMessagePort> urlMatchFilter,
     ResponseSelectorFilter <ProcessMessagePort> responseSelectorFilter,
     PolicyFilter <ProcessMessagePort> policyFilter
     )
 {
     this.pathValidationFilter   = pathValidationFilter;
     this.queryMatchFilter       = queryMatchFilter;
     this.endpointMatchFilter    = endpointMatchFilter;
     this.bodyMatchFilter        = bodyMatchFilter;
     this.blockFactory           = new SyncBlockFactory(this.cancellationTokenSource);
     this.headerMatchFilter      = headerMatchFilter;
     this.urlMatchFilter         = urlMatchFilter;
     this.responseSelectorFilter = responseSelectorFilter;
     this.policyFilter           = policyFilter;
 }