本文整理汇总了C#中System.Linq.Expressions.Expression.ToExpressionString方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.ToExpressionString方法的具体用法?C# Expression.ToExpressionString怎么用?C# Expression.ToExpressionString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.ToExpressionString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AlertNotText
public void AlertNotText(Expression<Func<string, bool>> matchFunc)
{
var compiledFunc = matchFunc.Compile();
this.commandProvider.AlertText((alertText) =>
{
if (compiledFunc(alertText))
{
// because the browser blocks, we dismiss the alert when a failure happens so we can cleanly shutdown.
this.commandProvider.AlertClick(Alert.Cancel);
this.ReportError("Expected alert text not to match expression [{0}] but it did.", matchFunc.ToExpressionString());
}
});
}
示例2: WaitUntil
public void WaitUntil(Expression<Func<bool>> conditionFunc, TimeSpan timeout)
{
this.Act(() =>
{
DateTime dateTimeTimeout = DateTime.Now.Add(timeout);
bool isFuncValid = false;
var compiledFunc = conditionFunc.Compile();
while (DateTime.Now < dateTimeTimeout)
{
if (compiledFunc() == true)
{
isFuncValid = true;
break;
}
System.Threading.Thread.Sleep(Settings.DefaultWaitUntilThreadSleep);
}
// If func is still not valid, assume we've hit the timeout.
if (isFuncValid == false)
{
throw new FluentException("Conditional wait passed the timeout [{0}ms] for expression [{1}].", timeout.TotalMilliseconds, conditionFunc.ToExpressionString());
}
});
}
示例3: WaitUntil
public void WaitUntil(Expression<Action> conditionAction, TimeSpan timeout)
{
this.Act(CommandType.Wait, () =>
{
DateTime dateTimeTimeout = DateTime.Now.Add(timeout);
bool threwException = false;
var compiledAction = conditionAction.Compile();
FluentException lastFluentException = null;
while (DateTime.Now < dateTimeTimeout)
{
try
{
threwException = false;
compiledAction();
}
catch (FluentException ex)
{
threwException = true;
lastFluentException = ex;
}
catch (Exception ex)
{
throw new FluentException("An unexpected exception was thrown inside WaitUntil(Action). See InnerException for details.", ex);
}
if (!threwException)
{
break;
}
System.Threading.Thread.Sleep(this.Settings.WaitUntilInterval);
}
// If an exception was thrown the last loop, assume we hit the timeout
if (threwException == true)
{
throw new FluentException("Conditional wait passed the timeout [{0}ms] for expression [{1}]. See InnerException for details of the last FluentException thrown.", lastFluentException, timeout.TotalMilliseconds, conditionAction.ToExpressionString());
}
});
}
示例4: False
public void False(Expression<Func<bool>> matchFunc)
{
this.commandProvider.Act(() =>
{
var compiledFunc = matchFunc.Compile();
if (compiledFunc())
{
throw new FluentExpectFailedException("Expected expression [{0}] to return false.", matchFunc.ToExpressionString());
}
});
}
示例5: Value
public void Value(Func<IElement> element, Expression<Func<string, bool>> matchFunc)
{
this.commandProvider.Act(() =>
{
var compiledFunc = matchFunc.Compile();
var unwrappedElement = element();
if (unwrappedElement.IsText)
{
if (!compiledFunc(unwrappedElement.Value))
{
throw new FluentExpectFailedException("Expected TextElement value to match expression [{0}] but it was actually [{1}].", matchFunc.ToExpressionString(), unwrappedElement.Value);
}
}
else if (unwrappedElement.IsSelect)
{
if (unwrappedElement.IsMultipleSelect)
{
var foundMatch = false;
foreach (var optionValue in unwrappedElement.SelectedOptionValues)
{
if (compiledFunc(optionValue))
{
foundMatch = true;
break;
}
}
if (!foundMatch)
{
throw new FluentExpectFailedException("Expected SelectElement selected options to have at least one option with value matching expression[{0}]. Selected option values include [{1}]", matchFunc.ToExpressionString(), string.Join(",", unwrappedElement.SelectedOptionTextCollection));
}
}
else
{
if (!compiledFunc(unwrappedElement.Text))
{
throw new FluentExpectFailedException("Expected SelectElement selected option value to match expression [{0}] but it was actually [{1}].", matchFunc.ToExpressionString(), unwrappedElement.Value);
}
}
}
else
{
if (!compiledFunc(unwrappedElement.Value))
{
throw new FluentExpectFailedException("Expected element value to match expression [{0}] but it was actually [{1}].", matchFunc.ToExpressionString(), unwrappedElement.Value);
}
}
});
}
示例6: Url
public void Url(Expression<Func<Uri, bool>> urlExpression)
{
this.commandProvider.Act(() =>
{
var compiledExpr = urlExpression.Compile();
if (compiledExpr(this.commandProvider.Url) != true)
{
throw new FluentExpectFailedException("Expected expression [{0}] to return true.", urlExpression.ToExpressionString());
}
});
}
示例7: NotText
public void NotText(ElementProxy element, Expression<Func<string, bool>> matchFunc)
{
this.commandProvider.Act(commandType, () =>
{
var compiledFunc = matchFunc.Compile();
var result = elementHasText(element, (elText) => compiledFunc(elText));
if (result.HasText)
{
if (element.Element.IsMultipleSelect)
{
this.ReportError("Expected SelectElement [{0}] selected options to have no options with text matching expression [{1}]. Selected option text values include [{2}]", result.Selector, matchFunc.ToExpressionString(), string.Join(",", element.Element.SelectedOptionTextCollection));
}
else if (element.Element.IsSelect)
{
this.ReportError("Expected SelectElement [{0}] selected option text not to match expression [{1}] but it did.", result.Selector, matchFunc.ToExpressionString());
}
else
{
this.ReportError("Expected {0} [{1}] text not to match expression [{2}] but it did.", result.ElementType, result.Selector, matchFunc.ToExpressionString());
}
}
});
}
示例8: Text
public void Text(string selector, Expression<Func<string, bool>> matchFunc)
{
this.commandProvider.Act(() =>
{
var compiledFunc = matchFunc.Compile();
var unwrappedElement = this.commandProvider.Find(selector)();
if (unwrappedElement.IsText)
{
if (!compiledFunc(unwrappedElement.Text))
{
throw new FluentExpectFailedException("Expected TextElement [{0}] text to match expression [{1}] but it was actually [{2}].", selector, matchFunc.ToExpressionString(), unwrappedElement.Text);
}
}
else if (unwrappedElement.IsSelect)
{
if (unwrappedElement.IsMultipleSelect)
{
var foundMatch = false;
foreach (var optionText in unwrappedElement.SelectedOptionTextCollection)
{
if (compiledFunc(optionText))
{
foundMatch = true;
break;
}
}
if (!foundMatch)
{
throw new FluentExpectFailedException("Expected SelectElement [{0}] selected options to have at least one option with text matching expression[{1}]. Selected option text values include [{2}]", selector, matchFunc.ToExpressionString(), string.Join(",", unwrappedElement.SelectedOptionTextCollection));
}
}
else
{
if (!compiledFunc(unwrappedElement.Text))
{
throw new FluentExpectFailedException("Expected SelectElement [{0}] selected option text to match expression [{1}] but it was actually [{2}].", selector, matchFunc.ToExpressionString(), unwrappedElement.Text);
}
}
}
else
{
if (!compiledFunc(unwrappedElement.Text))
{
throw new FluentExpectFailedException("Expected DOM Element [{0}] text to match expression [{1}] but it was actually [{2}].", selector, matchFunc.ToExpressionString(), unwrappedElement.Text);
}
}
});
}
示例9: SetValues
public void SetValues(Expression<Func<string, bool>> optionMatchingExpression, SelectMode selectMode)
{
IEnumerable<Automation.Core.Option> options = null;
var compiledFunc = optionMatchingExpression.Compile();
if (selectMode == SelectMode.Text)
{
options = _element.Options.Where(x => compiledFunc(x.Text));
}
else if (selectMode == SelectMode.Value)
{
options = _element.Options.Where(x => compiledFunc(x.Value));
}
if (options != null)
{
foreach (var option in options)
{
option.Select();
}
if (options.Count() == 0)
{
if (selectMode == SelectMode.Value)
throw new SelectException("Selection failed. No option values matched expression [{0}] on element.", optionMatchingExpression.ToExpressionString());
else if (selectMode == SelectMode.Text)
throw new SelectException("Selection failed. No option text matched expression [{0}] on element.", optionMatchingExpression.ToExpressionString());
else if (selectMode == SelectMode.Index)
throw new SelectException("Selection failed. No options matched collection of indices provided.");
}
this.OnChange();
}
}
示例10: Value
public void Value(ElementProxy element, Expression<Func<string, bool>> matchFunc)
{
this.commandProvider.Act(commandType, () =>
{
var compiledFunc = matchFunc.Compile();
var result = elementHasValue(element, (elValue) => compiledFunc(elValue));
if (!result.HasValue)
{
if (element.Element.IsMultipleSelect)
{
this.ReportError("Expected SelectElement [{0}] selected options to have at least one option with value matching expression [{1}]. Selected option values include [{2}]", result.Selector, matchFunc.ToExpressionString(), string.Join(",", element.Element.SelectedOptionValues));
}
else if (element.Element.IsSelect)
{
this.ReportError("Expected SelectElement [{0}] selected option value to match expression [{1}] but it was actually [{2}].", result.Selector, matchFunc.ToExpressionString(), result.ActualValue);
}
else
{
this.ReportError("Expected {0} [{1}] value to match expression [{2}] but it was actually [{3}].", result.ElementType, result.Selector, matchFunc.ToExpressionString(), result.ActualValue);
}
}
});
}
示例11: Url
public void Url(Expression<Func<Uri, bool>> urlExpression)
{
this.commandProvider.Act(commandType, () =>
{
if (urlExpression.Compile()(this.commandProvider.Url) != true)
{
this.ReportError("Expected expression [{0}] to return true. URL was [{1}].", urlExpression.ToExpressionString(), this.commandProvider.Url.ToString());
}
});
}
示例12: True
public void True(Expression<Func<bool>> matchFunc)
{
this.commandProvider.Act(commandType, () =>
{
var compiledFunc = matchFunc.Compile();
if (!compiledFunc())
{
this.ReportError("Expected expression [{0}] to return true.", matchFunc.ToExpressionString());
}
});
}
示例13: Throws
public void Throws(Expression<Action> matchAction)
{
this.commandProvider.Act(commandType, () =>
{
if (!throwsException(matchAction))
{
this.ReportError("Expected expression [{0}] to throw an exception.", matchAction.ToExpressionString());
}
});
}
示例14: Throws
public void Throws(Expression<Action> matchAction)
{
this.commandProvider.Act(() =>
{
bool threwException = false;
var compiledAction = matchAction.Compile();
try
{
compiledAction();
}
catch (FluentExpectFailedException)
{
threwException = true;
}
if (!threwException)
{
throw new FluentExpectFailedException("Expected expression [{0}] to throw an exception.", matchAction.ToExpressionString());
}
});
}
示例15: Url
/// <summary>
/// Expects page URL matches expression.
/// </summary>
/// <param name="valueExpression">The value expression.</param>
public virtual void Url(Expression<Func<Uri, bool>> valueExpression)
{
var _compiledFunc = valueExpression.Compile();
if (!_compiledFunc(Provider.GetUri()))
{
Provider.TakeAssertExceptionScreenshot();
throw new AssertException("URL Assertion failed. Expected URL to match expression [{0}]. Actual URL is [{1}].", valueExpression.ToExpressionString(), Provider.GetUri());
}
}