本文整理汇总了C#中TryFuncUntilTimeOut类的典型用法代码示例。如果您正苦于以下问题:C# TryFuncUntilTimeOut类的具体用法?C# TryFuncUntilTimeOut怎么用?C# TryFuncUntilTimeOut使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TryFuncUntilTimeOut类属于命名空间,在下文中一共展示了TryFuncUntilTimeOut类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldCreateTimeOutException
public void ShouldCreateTimeOutException()
{
// GIVEN
var timeoutsec = 1;
var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutsec))
{
ExceptionMessage = () => string.Format("returning false for {0} seconds", timeoutsec)
};
// WHEN
try
{
timeOut.Try(() => false);
}
catch(Exception e)
{
// THEN
Assert.That(e is Exceptions.TimeoutException, "Unexpected exception type: " + e.GetType());
Assert.That(e.Message, Is.EqualTo("Timeout while returning false for 1 seconds"), "Unexpected exception message");
Assert.That(e.InnerException, Is. Null, "Expected no InnerException");
return;
}
Assert.Fail("Expected TimeOutException");
}
示例2: WaitUntilHandled
public bool WaitUntilHandled(int timeoutAfterSeconds)
{
var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutAfterSeconds));
tryActionUntilTimeOut.Try(() => HasHandledDialog);
return HasHandledDialog;
}
示例3: TryFindIe
public IE TryFindIe(Constraint findBy, SimpleTimer timer)
{
var action = new TryFuncUntilTimeOut(timer)
{
SleepTime = TimeSpan.FromMilliseconds(500)
};
return action.Try(() => FindIEPartiallyInitialized(findBy));
}
示例4: WaitUntilExists
public void WaitUntilExists(int waitDurationInSeconds)
{
var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
tryActionUntilTimeOut.Try(() => Exists());
if (!Exists())
{
throw new WatiNException(string.Format("Dialog not available within {0} seconds.", waitDurationInSeconds));
}
}
示例5: TryShouldReturnFalseIfDidTimeOut
public void TryShouldReturnFalseIfDidTimeOut()
{
// GIVEN
var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));
// WHEN
var result = timeOut.Try(() => false );
// THEN
Assert.That(result, Is.False);
}
示例6: ShouldCallTheAction
public void ShouldCallTheAction()
{
// GIVEN
var actionCalled = false;
var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(2));
// WHEN
timeOut.Try(() => { actionCalled = true; return true; });
// THEN
Assert.That(actionCalled, Is.True, "action not called");
}
示例7: Find
public Browser Find(Constraint findBy, int timeout, bool waitForComplete)
{
Logger.LogAction("Busy finding FireFox matching constraint {0}", findBy);
var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout)) { SleepTime = TimeSpan.FromMilliseconds(500) };
var fireFox = action.Try(() => FindFireFox(findBy));
if (fireFox != null)
{
if (waitForComplete) fireFox.WaitForComplete();
return fireFox;
}
throw new BrowserNotFoundException("FireFox", findBy.ToString(), timeout);
}
示例8: ShouldNotAllowNullAsAction
public void ShouldNotAllowNullAsAction()
{
// Given
var timeout = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(30));
// When
try
{
timeout.Try<object>(null);
}
catch (Exception e)
{
Assert.That(e is ArgumentNullException, Is.True, "Action should be required");
Assert.That(e.Message, Text.Contains("func"), "Expected for argument 'func'");
return;
}
Assert.Fail("Expected an ArgumentNullException");
}
示例9: CloseFireFoxProcess
public void CloseFireFoxProcess()
{
//if (Process == null) return;
//Process.WaitForExit(5000);
//if (Process == null || Process.HasExited) return;
System.Diagnostics.Process firefoxProcess = FireFox.CurrentProcess;
if (firefoxProcess == null)
{
return;
}
firefoxProcess.WaitForExit(5000);
firefoxProcess = FireFox.CurrentProcess;
if (firefoxProcess == null)
{
return;
}
else if (firefoxProcess.HasExited)
{
TryFuncUntilTimeOut waiter = new TryFuncUntilTimeOut(TimeSpan.FromMilliseconds(5000));
bool procIsNull = waiter.Try<bool>(() => { firefoxProcess = FireFox.CurrentProcess; return firefoxProcess == null; });
if (procIsNull)
{
if (!waiter.DidTimeOut && firefoxProcess == null)
{
return;
}
}
}
Logger.LogDebug("Killing FireFox process");
UtilityClass.TryActionIgnoreException(() => Process.Kill());
}
示例10: ShouldSetInnerExcpetionWithLastException
public void ShouldSetInnerExcpetionWithLastException()
{
// GIVEN
var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1))
{
ExceptionMessage = () => "throwing exceptions"
};
// WHEN
try
{
timeOut.Try(() =>
{
var zero = 0;
return 1 / zero == 0;
});
}
catch(Exception e)
{
// THEN
Assert.That(e.InnerException, Is.Not.Null, "Expected an innerexception");
Assert.That(e.InnerException.GetType(), Is.EqualTo(typeof(DivideByZeroException)), "Expected DivideByZeroException");
return;
}
Assert.Fail("Expected TimeOutException");
}
示例11: SleepTimeShouldDefaultToSettingsSleepTime
public void SleepTimeShouldDefaultToSettingsSleepTime()
{
// GIVEN
Settings.SleepTime = 123;
// WHEN
var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));
// THEN
Assert.That(timeOut.SleepTime.TotalMilliseconds, Is.EqualTo(123), "Unexpected default timeout");
}
示例12: CreateIEPartiallyInitializedInNewProcess
private static IEBrowser CreateIEPartiallyInitializedInNewProcess()
{
var m_Proc = CreateIExploreInNewProcess();
var helper = new AttachToIeHelper();
var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.AttachToBrowserTimeOut))
{
SleepTime = TimeSpan.FromMilliseconds(500)
};
var ie = action.Try(() =>
{
m_Proc.Refresh();
var mainWindowHandle = m_Proc.MainWindowHandle;
return mainWindowHandle != IntPtr.Zero
? helper.FindIEPartiallyInitialized(new AttributeConstraint("hwnd", mainWindowHandle.ToString()))
: null;
});
if (ie != null) return ie._ieBrowser;
throw new BrowserNotFoundException("IE", "Timeout while waiting to attach to newly created instance of IE.", Settings.AttachToBrowserTimeOut);
}
示例13: FindHtmlDialog
private HtmlDialog FindHtmlDialog(Constraint findBy, int timeout)
{
Logger.LogAction("Busy finding HTMLDialog matching criteria: {0}", findBy);
var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
{
SleepTime = TimeSpan.FromMilliseconds(500)
};
var result = action.Try(() => HtmlDialogs.First(findBy));
if (result == null)
{
throw new HtmlDialogNotFoundException(findBy.ToString(), timeout);
}
return result;
}
示例14: WaitUntilDownloadCompleted
/// <summary>
/// Wait until the download progress window does not exist any more
/// </summary>
/// <param name="waitDurationInSeconds">duration in seconds to wait</param>
public void WaitUntilDownloadCompleted(int waitDurationInSeconds)
{
var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
tryActionUntilTimeOut.Try(() => !ExistsOrNull(DownloadProgressDialog));
if (ExistsOrNull(DownloadProgressDialog))
{
throw new WatiNException(string.Format("Still downloading after {0} seconds.", waitDurationInSeconds));
}
Logger.LogAction("Download complete at {0}", DateTime.Now.ToLongTimeString());
}
示例15: WaitUntilClosed
public virtual void WaitUntilClosed(int timeout)
{
var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
{
ExceptionMessage = () => string.Format("waiting {0} seconds for HtmlDialog to close.", timeout)
};
tryActionUntilTimeOut.Try(() => !Exists);
}