public void VerifyExecuteWithOneConditionalValue()
		{
			var text = "http://%1/$1";
			var pattern = new Pattern("/([a-z]+)/index.aspx", RegexOptions.IgnoreCase | RegexOptions.Singleline);
			var target = new DefaultRuleAction(pattern, text);

			var condTest = new DefaultConditionTestValue("%{HTTP_HOST}");
			var condPattern = new Pattern(".*", RegexOptions.IgnoreCase | RegexOptions.Singleline);
			var cond = MockCond(condPattern, condTest, null);

			Uri url = new Uri("http://www.managedfusion.com/success/index.aspx");
			var httpContext = HttpHelpers.MockHttpContext(url);
			httpContext.Request.SetServerVariables(new Dictionary<string, string> { 
				{ "HTTP_HOST", "www.managedfusion.com" } 
			});
			var rule = MockRule(new List<ICondition> { cond }, target, null);

			RuleContext context = CreateRuleContext(url, httpContext, rule);
			target.Execute(context);

			Uri result = context.SubstitutedUrl;
			Uri expected = new Uri("http://www.managedfusion.com/success");

			Assert.AreEqual(expected, result);
		}
		public void VerifyExecuteWithOneConditionalValue()
		{
			var text = "http://%1/$1";
			var pattern = new Pattern("/([a-z]+)/index.aspx", RegexOptions.IgnoreCase | RegexOptions.Singleline);
			var target = new DefaultOutputRuleAction(pattern, text);

			var condTest = new DefaultConditionTestValue("%{HTTP_HOST}");
			var condPattern = new Pattern(".*", RegexOptions.IgnoreCase | RegexOptions.Singleline);
			var cond = MockCond(condPattern, condTest, null);

			var httpContext = HttpHelpers.MockHttpContext(new Uri("http://www.managedfusion.com/success/index.aspx"));
			httpContext.Request.SetServerVariables(new Dictionary<string, string> { 
				{ "HTTP_HOST", "www.managedfusion.com" } 
			});
			string content = CreateHtmlContent(@"<a href=""/success/index.aspx"" target=""_blank"">Link</a>");
			var rule = MockRule(new List<ICondition> { cond }, target, null);

			RuleContext context = CreateOutputRuleContext(content.ToByteArray(), httpContext, rule);
			target.Execute(context);

			string result = context.SubstitutedContent.GetString();
			string expected = CreateHtmlContent(@"<a href=""http://www.managedfusion.com/success"" target=""_blank"">Link</a>");

			Assert.AreEqual(expected, result);
		}
		/// <summary>
		/// Gets the condition.
		/// </summary>
		/// <param name="conditionElement">The condition element.</param>
		/// <param name="matchAll">if set to <see langword="true"/> [match all].</param>
		/// <returns></returns>
		private ICondition GetCondition(XmlNode conditionElement, LogicalGrouping logicalGrouping)
		{
			string input = "-";
			MatchType matchType = MatchType.Pattern; // from schema definition
			string pattern = "(.*)";
			bool ignoreCase = true; // from schema definition
			bool negate = false; // from schema definition

			if (conditionElement.Attributes["input"] != null)
				input = conditionElement.Attributes["input"].Value;

			if (conditionElement.Attributes["matchType"] != null)
			{
				try { matchType = (MatchType)Enum.Parse(typeof(MatchType), conditionElement.Attributes["matchType"].Value, true); }
				catch (Exception exc) { Manager.Log("Condition: " + exc.Message, "Error"); }
			}

			if (conditionElement.Attributes["pattern"] != null)
				pattern = conditionElement.Attributes["pattern"].Value;

			if (conditionElement.Attributes["ignoreCase"] != null)
				ignoreCase = XmlConvert.ToBoolean(conditionElement.Attributes["ignoreCase"].Value);

			if (conditionElement.Attributes["negate"] != null)
				negate = XmlConvert.ToBoolean(conditionElement.Attributes["negate"].Value);

			RegexOptions conditionOptions = Manager.RuleOptions;
			IConditionFlagProcessor conditionFlags = new ConditionFlagProcessor();

			if (ignoreCase)
			{
				conditionFlags.Add(new CF.NoCaseFlag());
				conditionOptions |= RegexOptions.IgnoreCase;
			}

			if (logicalGrouping == LogicalGrouping.MatchAny)
				conditionFlags.Add(new CF.OrNextFlag());

			ICondition condition = null;

			// create the condition
			switch (matchType)
			{
				case MatchType.IsFile: condition = new IsFileCondition(); break;
				case MatchType.IsDirectory: condition = new IsDirectoryCondition(); break;
				case MatchType.Pattern: condition = new DefaultCondition(); break;
			}

			Pattern compiledPattern = new Pattern(pattern, negate, conditionOptions);
			var conditionTest = new DefaultConditionTestValue(input);

			// initialize condition
			condition.Init(compiledPattern, conditionTest, conditionFlags);

			return condition;
		}