public void UrlMatchFilterMatchSuccessTest() { #region Test Setup var fakeScenario = scenarioFaker.Generate(); var faker = new Faker(); var input = new { Scenarios = new List <Scenario>() { fakeScenario }, Path = fakeScenario.RequestMatchRules.UrlRules.FirstOrDefault().RuleValue.Value }; #endregion var Target = new UrlMatchFilter <ProcessMessagePort>(new AssertFactory(), new RuleMatcher()); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Path = input.Path }; var Actual = Target.Process(port).URLMatchResults .Where(x => x.Match.Equals(MatchResultType.Success)).Select(x => x.ScenarioId).ToList(); var Expected = fakeScenario.Id; Assert.Contains(Expected, Actual); }
public void UrlMatchFilterMatchAcceptAllSuccessTest() { #region Test Setup var fakeScenario = scenarioFaker.Generate(); fakeScenario.RequestMatchRules.UrlRules = fakeScenario.RequestMatchRules.UrlRules.Select(r => { r.Type = ComparerType.ACCEPTALL; return(r); }).ToList(); var faker = new Faker(); var input = new { Scenarios = new List <Scenario>() { fakeScenario }, Path = faker.Random.AlphaNumeric(TestUtils.GetRandomStringLength()) }; #endregion var Target = new UrlMatchFilter <ProcessMessagePort>(new AssertFactory(), new RuleMatcher()); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Path = input.Path }; var Actual = Target.Process(port).URLMatchResults .Where(x => x.Match.Equals(MatchResultType.Success)).Select(x => x.ScenarioId).ToList(); var Expected = fakeScenario.Id; Assert.Contains(Expected, Actual); }
public void HeaderMatchRulesKeysAreEqualValuesAreDifferentFailure() { var fakeScenario = scenarioFaker.Generate(); var headers = fakeScenario.RequestMatchRules.HeaderRules.Select(x => new KeyValuePair <string, string>(x.RuleValue.Key, x.RuleValue.Value + "-unique")); var input = new { Scenarios = new List <Scenario>() { fakeScenario }, Headers = headers }; var Target = new HeaderMatchFilter <ProcessMessagePort>(assertFactory, ruleMatcher); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Headers = input.Headers }; var Actual = Target.Process(port).HeaderMatchResults.Where(x => x.Match == MatchResultType.Fail).Select(x => x.ScenarioId).ToList(); var Expected = fakeScenario.Id; Assert.Contains(Expected, Actual); }
public void UrlMatchFilterNoMatchTest() { #region Test Setup var fakeScenario = scenarioFaker.Generate(); var faker = new Faker(); var input = new { Scenarios = new List <Scenario>() { fakeScenario }, Path = faker.Random.AlphaNumeric(TestUtils.GetRandomStringLength()) }; #endregion var Target = new UrlMatchFilter <ProcessMessagePort>(assertFactory, ruleMatcher); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Path = input.Path }; var Actual = Target.Process(port) .URLMatchResults.Where(x => x.Match.Equals(MatchResultType.Success)).Select(x => x.ScenarioId).ToList(); Assert.Empty(Actual); }
public void HeaderMatchFilterInvalidPortTest() { #region Test Setup var fakeScenario = scenarioFaker.Generate(); var input = new { Scenarios = new List <Scenario>() { fakeScenario }, Faults = new List <string> { "fault" } }; #endregion var Target = new HeaderMatchFilter <ProcessMessagePort>(assertFactory, ruleMatcher); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Faults = input.Faults }; var Actual = Target.Process(port).HeaderMatchResults; Assert.Empty(Actual); }
public void HeaderMatchFilterMatchSuccessTest() { #region Test Setup var fakeScenario = scenarioFaker.Generate(); var headers = fakeScenario.RequestMatchRules.HeaderRules.Select(rules => rules.RuleValue); var input = new { Scenarios = new List <Scenario>() { fakeScenario }, Headers = headers }; #endregion var Target = new HeaderMatchFilter <ProcessMessagePort>(assertFactory, ruleMatcher); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Headers = input.Headers }; var Actual = Target.Process(port) .HeaderMatchResults.Where(x => x.Match.Equals(MatchResultType.Success)).Select(x => x.ScenarioId).ToList(); var Expected = fakeScenario.Id; Assert.Contains(Expected, Actual); }
public void HeaderMatchFilterNoMatchTest() { #region Test Setup var fakeScenario = scenarioFaker.Generate(); var input = new { Scenarios = new List <Scenario>() { fakeScenario }, Headers = fakeScenario.RequestMatchRules.HeaderRules.Select(x => new KeyValuePair <string, string>(x.RuleValue.Key, x.RuleValue.Value + "-unique")) }; #endregion var Target = new HeaderMatchFilter <ProcessMessagePort>(assertFactory, ruleMatcher); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Headers = input.Headers }; var Actual = Target.Process(port) .HeaderMatchResults.Where(x => x.Match.Equals(MatchResultType.Success)).Select(x => x.ScenarioId).ToList(); Assert.Empty(Actual); }
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); }
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); }
/// <inheritdoc /> public async Task <MockResponse> Push(MessageProcessorInput input, CancellationToken token) { var completionSource = new TaskCompletionSource <ProcessMessagePort>(); token.Register(() => cancellationTokenSource.Cancel()); if (input == null || input.ServerHttpRequest == null || input.ServerHttpRequest.Body == null || input.HeaderDictionary == null || input.QueryDictionary == null || input.Scenarios == null) { var error = "One or more of the Message Processor Inputs is null"; Log.Error("MockServerProcessor Error: {Error}", error); return(new MockResponse { Status = 400, Body = "Something went wrong" }); } var body = string.Empty; using (var reader = new StreamReader(input.ServerHttpRequest.Body)) { body = reader.ReadToEnd(); } Enum.TryParse(input.ServerHttpRequest.Method, true, out HttpMethod verb); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Path = input.ServerHttpRequest.Path, Verb = verb, Query = input.QueryDictionary, Headers = input.HeaderDictionary, Body = body }; var envelope = new SyncEnvelope(completionSource, port, token); this.startBlock.Post(envelope); port = await completionSource.Task; if (port == null) { var error = "Pipeline port cannot be null"; Log.Error("MockServerProcessor Error: {Error}", error); return(new MockResponse { Status = StatusCodes.Status500InternalServerError, Body = error, Headers = new Dictionary <string, string>() }); } return(port.IsFaulted || port.SelectedResponse == null ? new MockResponse() : port.SelectedResponse); }
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); }
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); }
public void HeaderMatchFilterNoScenarioTest() { #region Test Setup var input = new { Scenarios = new List <Scenario>(), Headers = new Dictionary <string, string>() }; #endregion var Target = new HeaderMatchFilter <ProcessMessagePort>(assertFactory, ruleMatcher); var port = new ProcessMessagePort() { Scenarios = input.Scenarios, Headers = input.Headers }; var Actual = Target.Process(port).HeaderMatchResults; Assert.Empty(Actual); }