本文整理汇总了C#中TestDelegate.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# TestDelegate.Invoke方法的具体用法?C# TestDelegate.Invoke怎么用?C# TestDelegate.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestDelegate
的用法示例。
在下文中一共展示了TestDelegate.Invoke方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunMockedExample
/// <summary>
/// Runs a code example in mocked mode.
/// </summary>
/// <param name="mockData">The mock data for mocking SOAP request and
/// responses for API calls.</param>
/// <param name="exampleDelegate">The delegate that initializes and runs the
/// code example.</param>
/// <param name="callback">The callback to be called before mocked responses
/// are sent. You could use this callback to verify if the request was
/// serialized correctly.</param>
/// <remarks>This method is not thread safe, but since NUnit can run tests
/// only in a single threaded mode, thread safety is not a requirement.
/// </remarks>
protected void RunMockedExample(ExamplesMockData mockData, TestDelegate exampleDelegate,
WebRequestInterceptor.OnBeforeSendResponse callback) {
TextWriter oldWriter = Console.Out;
try {
awapiInterceptor.Intercept = true;
awapiInterceptor.LoadMessages(mockData.MockMessages,
delegate(Uri requestUri, WebHeaderCollection headers, String body) {
VerifyHttpHeaders(headers);
VerifySoapHeaders(requestUri, body);
callback(requestUri, headers, body);
}
);
StringWriter newWriter = new StringWriter();
Console.SetOut(newWriter);
exampleDelegate.Invoke();
Assert.AreEqual(newWriter.ToString().Trim(), mockData.ExpectedOutput.Trim());
} finally {
Console.SetOut(oldWriter);
awapiInterceptor.Intercept = false;
}
}
示例2: MeasureMethod
//Delegate method, object[] args=null)
//duplicates NUnit declaration
public static long MeasureMethod(TestDelegate method, int times_to_execute=100)
{
// Uses the second Core or Processor for the Test:
Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(2);
// Prevents "Normal" processes from interrupting Threads:
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
// Prevents "Normal" Threads from interrupting this thread
Thread.CurrentThread.Priority = ThreadPriority.Highest;
Stopwatch stopwatch = new Stopwatch();
WarmUp(stopwatch);
stopwatch.Reset();
stopwatch.Start();
for (int i = 0; i < times_to_execute; i++)
{
method.Invoke();
}
stopwatch.Stop();
long time = stopwatch.ElapsedTicks;
return time;
}
示例3: RunExample
/// <summary>
/// Runs a code example.
/// </summary>
/// <param name="exampleDelegate">The delegate that initializes and runs the
/// code example.</param>
protected void RunExample(TestDelegate exampleDelegate) {
Thread.Sleep(3000);
StringWriter writer = new StringWriter();
Assert.DoesNotThrow(delegate() {
TextWriter oldWriter = Console.Out;
Console.SetOut(writer);
exampleDelegate.Invoke();
Console.SetOut(oldWriter);
Console.WriteLine(writer.ToString());
});
}
示例4: RunMockedExample
/// <summary>
/// Runs a code example in mocked mode.
/// </summary>
/// <param name="mockData">The mock data for mocking SOAP request and
/// responses for API calls.</param>
/// <param name="exampleDelegate">The delegate that initializes and runs the
/// code example.</param>
/// <param name="callback">The callback to be called before mocked responses
/// are sent. You could use this callback to verify if the request was
/// serialized correctly.</param>
/// <remarks>This method is not thread safe, but since NUnit can run tests
/// only in a single threaded mode, thread safety is not a requirement.
/// </remarks>
protected void RunMockedExample(ExamplesMockData mockData, TestDelegate exampleDelegate,
WebRequestInterceptor.OnBeforeSendResponse callback)
{
TextWriter oldWriter = Console.Out;
try {
clientLoginInterceptor.Intercept = true;
clientLoginInterceptor.RaiseException = false;
awapiInterceptor.Intercept = true;
AuthToken.Cache.Clear();
awapiInterceptor.LoadMessages(mockData.MockMessages,
delegate(Uri requestUri, WebHeaderCollection headers, String body) {
VerifySoapHeaders(requestUri, body);
callback(requestUri, headers, body);
}
);
StringWriter newWriter = new StringWriter();
Console.SetOut(newWriter);
AdWordsAppConfig config = (user.Config as AdWordsAppConfig);
exampleDelegate.Invoke();
Assert.AreEqual(newWriter.ToString().Trim(), mockData.ExpectedOutput.Trim());
} finally {
Console.SetOut(oldWriter);
clientLoginInterceptor.Intercept = false;
awapiInterceptor.Intercept = false;
}
}
示例5: testDel
/// <summary>
/// Used to test implicit conversions from SMFunction to Delegate
/// (Usage: testDel(function() { print("this is a test!"); }));
/// </summary>
/// <param name="delegate"></param>
public static void testDel(TestDelegate @delegate)
{
@delegate.Invoke();
}