本文整理汇总了C#中TryFuncUntilTimeOut.Try方法的典型用法代码示例。如果您正苦于以下问题:C# TryFuncUntilTimeOut.Try方法的具体用法?C# TryFuncUntilTimeOut.Try怎么用?C# TryFuncUntilTimeOut.Try使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TryFuncUntilTimeOut
的用法示例。
在下文中一共展示了TryFuncUntilTimeOut.Try方法的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: 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));
}
}
示例4: TryShouldReturnTrueIfNoTimeOut
public void TryShouldReturnTrueIfNoTimeOut()
{
// GIVEN
var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));
// WHEN
var result = timeOut.Try(() => true );
// THEN
Assert.That(result, Is.True);
}
示例5: 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");
}
示例6: 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);
}
示例7: 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");
}
示例8: Dispose
/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing">
/// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.
/// </param>
public void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!_disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
// Dispose managed resources.
if (_telnetSocket != null && _telnetSocket.Connected && (Process == null || !Process.HasExited))
{
try
{
WriteAndRead("{0}.home();", PromptName);
var windowCount = WriteAndReadAsInt("{0}.getWindows().length", PromptName);
Logger.LogDebug(string.Format("Closing window. {0} total windows found", windowCount));
SendCommand(string.Format("{0}.close();", WindowVariableName));
if (windowCount == 1)
{
Logger.LogDebug("No further windows remain open.");
CloseConnection();
CloseFireFoxProcess();
}
else
{
TryFuncUntilTimeOut waiter = new TryFuncUntilTimeOut(TimeSpan.FromMilliseconds(2000));
bool windowClosed = waiter.Try<bool>(() => { return WriteAndReadAsInt("{0}.getWindows().length", PromptName) == windowCount - 1; });
}
}
catch (IOException ex)
{
Logger.LogDebug("Error communicating with mozrepl server to initiate shut down, message: {0}", ex.Message);
}
}
}
}
_disposed = true;
Connected = false;
}
示例9: 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;
}
示例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: 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);
}
示例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: WaitUntilVisibleOrTimeOut
private static void WaitUntilVisibleOrTimeOut(Window window)
{
// Wait untill window is visible so all properties
// of the window class (like Style and StyleInHex)
// will return valid values.
var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut));
var success = tryActionUntilTimeOut.Try(() => window.Visible);
if (!success)
{
Logger.LogAction("Dialog with title '{0}' not visible after {1} seconds.", window.Title, Settings.WaitForCompleteTimeOut);
}
}
示例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: CreateProcess
internal static void CreateProcess(string arguments, bool waitForMainWindow)
{
var ffProcess = new Process {StartInfo = {FileName = PathToExe, Arguments = arguments}};
ffProcess.Start();
ffProcess.WaitForInputIdle(5000);
ffProcess.Refresh();
if (!waitForMainWindow) return;
var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut))
{
SleepTime = TimeSpan.FromMilliseconds(200)
};
var result = action.Try(() =>
{
ffProcess.Refresh();
if (!ffProcess.HasExited && ffProcess.MainWindowHandle != IntPtr.Zero)
{
Logger.LogAction("Waited for FireFox, main window handle found.");
return true;
}
return false;
});
if (!result)
{
Debug.WriteLine("Timer elapsed waiting for FireFox to start.");
}
}