public void MatchVerifications_should_match_text_in_content() { // given var provider = new CapturedVariableProvider(_variableContainer, "", new VariableEncryptorStub()); var matcher = GetMatcher(provider); var verifications = new List <Assertion>(); verifications.Add(new Assertion("desc1", "content here", AssertionType.Positive, AssertionMethod.Regex)); verifications.Add(new Assertion("desc2", "bad regex", AssertionType.Positive, AssertionMethod.Regex)); string content = "<p>Some content here</p>"; // when List <Assertion> results = matcher.MatchVerifications(verifications, content); // then Assert.That(results.Count, Is.EqualTo(2)); Assert.That(results[0].Success, Is.True); Assert.That(results[0].Description, Is.EqualTo("desc1")); Assert.That(results[0].Value, Is.EqualTo("content here")); Assert.That(results[1].Success, Is.False); Assert.That(results[1].Description, Is.EqualTo("desc2")); Assert.That(results[1].Value, Is.EqualTo("bad regex")); }
public void MatchVerifications_should_replace_variables_in_value() { // given var provider = new CapturedVariableProvider(_variableContainer, "dev", new VariableEncryptorStub()); provider.AddOrUpdateVariable(new Variable("password", "tedx123", "dev")); var matcher = GetMatcher(provider); var verifications = new List <Assertion>(); verifications.Add(new Assertion("desc1", "({password})", AssertionType.Positive, AssertionMethod.Regex)); string content = "<p>The password is tedx123</p>"; // when List <Assertion> results = matcher.MatchVerifications(verifications, content); // then Assert.That(results.Count, Is.EqualTo(1)); Assert.That(results[0].Success, Is.True); Assert.That(results[0].Description, Is.EqualTo("desc1")); Assert.That(results[0].Value, Is.EqualTo("({password})")); Assert.That(results[0].TransformedValue, Is.EqualTo("(tedx123)")); }
public void Setup() { _variableContainerStub = new VariableContainerStub(); _variableProvider = new CapturedVariableProvider(_variableContainerStub, "development", new VariableEncryptorStub()); _assertionLogger = new AssertionLogger(new TestFileRunnerLogger()); }
public void AddOrUpdateVariable_should_not_set_variable_when_in_different_environments() { // given var sessionVariables = new CapturedVariableProvider(_variableContainer, _devEnvironment, new VariableEncryptorStub()); var variable = new Variable("nano", "leaf", _prodEnvironment); // when sessionVariables.AddOrUpdateVariable(variable); // then Assert.That(sessionVariables.GetVariableValue("nano"), Is.EqualTo(string.Empty)); }
public void AddOrUpdateVariable_should_set_variable() { // given var sessionVariables = new CapturedVariableProvider(_variableContainer, _devEnvironment, new VariableEncryptorStub()); var variable = new Variable("nano", "leaf", _devEnvironment); // whenS sessionVariables.AddOrUpdateVariable(variable); // then Assert.That(sessionVariables.GetVariableValue("nano"), Is.EqualTo("leaf")); }
public void matchvariables_should_not_concatenate_multiple_matches_into_variable_value() { // given var parseResponses = new List <CapturedVariable>() { new CapturedVariable("var1", @"(\d+)"), }; string content = "<html>The number 3 and the number 4 combined make 7</html>"; // when List <Variable> variables = CapturedVariableProvider.MatchVariables(parseResponses, content, new TestFileRunnerLogger()); // then Assert.That(variables.ValueByName("var1"), Is.EqualTo("3")); }
public void ReplaceVariablesIn_should_replace_all_variables_and_escape_regex_characters_in_values() { // given var sessionVariables = new CapturedVariableProvider(_variableContainer, _devEnvironment, new VariableEncryptorStub()); sessionVariables.AddOrUpdateVariable(new Variable("nano", "$var leaf", _devEnvironment)); sessionVariables.AddOrUpdateVariable(new Variable("two", "(.*?) [a-z] ^perlmagic", _devEnvironment)); string template = "{nano} {dummy} {two}"; string expectedText = @"\$var\ leaf {dummy} \(\.\*\?\)\ \[a-z]\ \^perlmagic"; // when string actualText = sessionVariables.ReplaceVariablesIn(template); // then Assert.That(actualText, Is.EqualTo(expectedText)); }
public void ReplacePlainTextVariablesIn_should_replace_all_variables() { // given var sessionVariables = new CapturedVariableProvider(_variableContainer, _devEnvironment, new VariableEncryptorStub()); sessionVariables.AddOrUpdateVariable(new Variable("nano", "leaf", _devEnvironment)); sessionVariables.AddOrUpdateVariable(new Variable("two", "ten", _devEnvironment)); string template = "{nano} {dummy} {two}"; string expectedText = "leaf {dummy} ten"; // when string actualText = sessionVariables.ReplacePlainTextVariablesIn(template); // then Assert.That(actualText, Is.EqualTo(expectedText)); }
public void AddOrUpdateVariables_should_set_variable() { // given var sessionVariables = new CapturedVariableProvider(_variableContainer, _devEnvironment, new VariableEncryptorStub()); // when sessionVariables.AddOrUpdateVariables(new List <Variable>() { new Variable("nano", "leaf", _devEnvironment), new Variable("light", "bulb", _devEnvironment) }); // then Assert.That(sessionVariables.GetVariableValue("nano"), Is.EqualTo("leaf")); Assert.That(sessionVariables.GetVariableValue("light"), Is.EqualTo("bulb")); }
public void matchvariables_should_set_value_to_empty_string_when_regex_is_invalid() { // given var parseResponses = new List <CapturedVariable>() { new CapturedVariable("var1", @"(\d+)"), new CapturedVariable("var2", @"(() this is a bad regex?("), }; string content = "<html>123 abc</html>"; // when List <Variable> variables = CapturedVariableProvider.MatchVariables(parseResponses, content, new TestFileRunnerLoggerMock()); // then Assert.That(variables.Count, Is.EqualTo(2)); Assert.That(variables.ValueByName("var1"), Is.EqualTo("123")); Assert.That(variables.ValueByName("var2"), Is.EqualTo("")); }
public void matchvariables_should_match_regex_groups_and_set_variable_names_and_values_to_matched_items() { // given var parseResponses = new List <CapturedVariable>() { new CapturedVariable("var1", @"(\d+)"), new CapturedVariable("varFoo", "(<html.+?>)") }; string content = "<html class='bootstrap'><p>Tap tap tap 123</p></html>"; // when List <Variable> variables = CapturedVariableProvider.MatchVariables(parseResponses, content, new TestFileRunnerLoggerMock()); // then Assert.That(variables.Count, Is.EqualTo(2)); Assert.That(variables.ValueByName("var1"), Is.EqualTo("123")); Assert.That(variables.ValueByName("varFoo"), Is.EqualTo("<html class='bootstrap'>")); }
public void MatchVerifications_invalid_regex_should_set_success_to_false() { // given var provider = new CapturedVariableProvider(_variableContainer, "", new VariableEncryptorStub()); var matcher = GetMatcher(provider); var verifications = new List <Assertion>(); verifications.Add(new Assertion("dodgy regex", "((*)", AssertionType.Positive, AssertionMethod.Regex)); string content = "<p>Some content here</p>"; // when List <Assertion> results = matcher.MatchVerifications(verifications, content); // then Assert.That(results.Count, Is.EqualTo(1)); Assert.That(results[0].Success, Is.False); }
public void MatchVerifications_should_return_veriftype_positives_in_list() { // given var provider = new CapturedVariableProvider(_variableContainer, "", new VariableEncryptorStub()); var matcher = GetMatcher(provider); var verifications = new List <Assertion>(); verifications.Add(new Assertion("p1", "a regex", AssertionType.Positive, AssertionMethod.Regex)); verifications.Add(new Assertion("p2", "another regex", AssertionType.Positive, AssertionMethod.Regex)); verifications.Add(new Assertion("n1", "one more regex", AssertionType.Negative, AssertionMethod.Regex)); string content = "<p>whatever</p>"; // when List <Assertion> results = matcher.MatchVerifications(verifications, content); // then Assert.That(results.Count, Is.EqualTo(3)); }
public void AddOrUpdateVariables_should_not_update_variable_when_setting_as_default_and_has_existing_variable_set_against_a_specific_environment() { // given var sessionVariables = new CapturedVariableProvider(_variableContainer, _devEnvironment, new VariableEncryptorStub()); // when sessionVariables.AddOrUpdateVariables(new List <Variable>() { new Variable("nano", "leaf", _devEnvironment), new Variable("light", "bulb", _devEnvironment), }); sessionVariables.AddOrUpdateVariables(new List <Variable>() { new Variable("nano", "leaf2", string.Empty), new Variable("light", "bulb2", string.Empty) }); // then Assert.That(sessionVariables.GetVariableValue("nano"), Is.EqualTo("leaf")); Assert.That(sessionVariables.GetVariableValue("light"), Is.EqualTo("bulb")); }
public void ReplaceVariablesIn_should_call_decrypt() { // given string variableValue = "leaf"; var mock = new Mock <IVariableEncryptor>(); mock.Setup(x => x.Decrypt(It.IsAny <string>())) .Returns(variableValue) .Verifiable("decrypt not called"); var sessionVariables = new CapturedVariableProvider(_variableContainer, _devEnvironment, mock.Object); sessionVariables.AddOrUpdateVariable(new Variable("nano", variableValue, _devEnvironment)); string template = "{nano}"; // when sessionVariables.ReplaceVariablesIn(template); // then mock.Verify(x => x.Decrypt(variableValue)); }
private AssertionsMatcher GetMatcher(CapturedVariableProvider provider) { ITestFileRunnerLogger logger = new Mock <ITestFileRunnerLogger>().Object; return(new AssertionsMatcher(provider, logger)); }