当前位置: 首页>>代码示例>>C#>>正文


C# TryFuncUntilTimeOut类代码示例

本文整理汇总了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");
        }
开发者ID:fschwiet,项目名称:watin_unbranched,代码行数:25,代码来源:TryActionUntilTimeOutTests.cs

示例2: WaitUntilHandled

        public bool WaitUntilHandled(int timeoutAfterSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutAfterSeconds));
            tryActionUntilTimeOut.Try(() => HasHandledDialog);

            return HasHandledDialog;
        }
开发者ID:exaphaser,项目名称:WatiN,代码行数:7,代码来源:WaitUntilHandledDialogHandler.cs

示例3: TryFindIe

        public IE TryFindIe(Constraint findBy, SimpleTimer timer)
        {
            var action = new TryFuncUntilTimeOut(timer)
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            return action.Try(() => FindIEPartiallyInitialized(findBy));
        }
开发者ID:modulexcite,项目名称:FluentSharp_Fork.WatiN,代码行数:9,代码来源:AttachToIeHelper.cs

示例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));
			}
		}
开发者ID:exaphaser,项目名称:WatiN,代码行数:10,代码来源:JavaDialogHandler.cs

示例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);
        }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:11,代码来源:TryActionUntilTimeOutTests.cs

示例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");
        }
开发者ID:fschwiet,项目名称:watin_unbranched,代码行数:12,代码来源:TryActionUntilTimeOutTests.cs

示例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);
        }
开发者ID:pusp,项目名称:o2platform,代码行数:15,代码来源:AttachToFireFoxHelper.cs

示例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");
 }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:18,代码来源:TryActionUntilTimeOutTests.cs

示例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());
        }
开发者ID:modulexcite,项目名称:FluentSharp_Fork.WatiN,代码行数:37,代码来源:FireFoxClientPort.cs

示例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");
        }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:27,代码来源:TryActionUntilTimeOutTests.cs

示例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");
        }
开发者ID:kevinswarner,项目名称:Hover_OLD,代码行数:11,代码来源:TryActionUntilTimeOutTests.cs

示例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);
		}
开发者ID:fschwiet,项目名称:WatiN-2.0.20.1089-net-2.0,代码行数:24,代码来源:IE.cs

示例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;
		}
开发者ID:fschwiet,项目名称:WatiN-2.0.20.1089-net-2.0,代码行数:18,代码来源:IE.cs

示例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());
        }
开发者ID:kumichou,项目名称:WatiN_FindByCssSelector,代码行数:16,代码来源:FileDownloadHandler.cs

示例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);
        }
开发者ID:exaphaser,项目名称:WatiN,代码行数:9,代码来源:HTMLDialog.cs


注:本文中的TryFuncUntilTimeOut类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。