public void AddOrUpdateVariable_should_not_update_variable_when_already_set_and_in_different_environments() { // given var sessionVariables = new CapturedVariableProvider(_variableContainer, _prodEnvironment, new VariableEncryptorStub()); var variable1 = new Variable("nano", "leaf", _prodEnvironment); var variable2 = new Variable("nano", "leaf2", _devEnvironment); // when sessionVariables.AddOrUpdateVariable(variable1); sessionVariables.AddOrUpdateVariable(variable2); // then Assert.That(sessionVariables.GetVariableValue("nano"), Is.EqualTo("leaf")); }
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 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 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 should_replace_variables_in_selector() { // given string html = "<html></html>"; var variable1 = new Variable("variable1", "1-value", "development"); var variable2 = new Variable("variable2", "2-value", "development"); _variableProvider.AddOrUpdateVariable(variable1); _variableProvider.AddOrUpdateVariable(variable2); AngleSharpMatcher matcher = CreateAngleSharpMatcher(); var assertion = new Assertion(); assertion.Value = "#{variable1} .{variable2}"; // when matcher.Match(assertion, html); // then Assert.That(assertion.TransformedValue, Is.EqualTo("#1-value .2-value")); }
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)); }