public void ReplacePlainTextVariablesIn_should_replace_all_variables() { // Arrange var sessionVariables = new SessionVariables(); sessionVariables.AddOrUpdateVariable("nano", "leaf"); sessionVariables.AddOrUpdateVariable("two", "ten"); string template = "{nano} {dummy} {two}"; string expectedText = "leaf {dummy} ten"; // Act string actualText = sessionVariables.ReplacePlainTextVariablesIn(template); // Assert Assert.That(actualText, Is.EqualTo(expectedText)); }
internal TestCaseResult RunCase(Case testCase, SessionVariables variables, VerificationsMatcher verificationMatcher) { var testResult = new TestCaseResult(); testResult.TestCase = testCase; try { string resolvedUrl = variables.ReplacePlainTextVariablesIn(testCase.Url); testResult.ActualUrl = resolvedUrl; HttpResponse response = _httpClient.ExecuteRequest(testCase.Method, resolvedUrl, testCase.PostType, testCase.PostBody, testCase.Headers); testResult.ResponseTime = response.ResponseTime; testResult.HttpResponse = response; if (response.StatusCode == testCase.VerifyResponseCode) { testResult.ResponseCodeSuccess = true; string content = response.ToString(); // Put the parseresponse regex values in the current variable set Dictionary<string, string> parsedVariables = ParseResponseMatcher.MatchParseResponses(testCase.ParseResponses, content); variables.AddOrUpdateVariables(parsedVariables); // Verify positives testResult.VerifyPositiveResults = verificationMatcher.MatchPositive(testCase.VerifyPositives, content); // Verify Negatives testResult.VerifyNegativeResults = verificationMatcher.MatchNegative(testCase.VerifyNegatives, content); } else { testResult.ResponseCodeSuccess = false; } if (testResult.Success == false) { testResult.Message = testCase.ErrorMessage; } if (ShouldLogRequest(testResult, testCase)) { _httpClient.LogLastRequest(); } if (ShouldLogResponse(testResult, testCase)) { _httpClient.LogLastResponse(); } _resultWriter.Write(testResult); if (testCase.Sleep > 0) Thread.Sleep(testCase.Sleep * 1000); } catch (Exception ex) { testResult.ResponseCodeSuccess = false; testResult.ExceptionMessage = ex.Message; } return testResult; }