本文整理汇总了C#中System.Threading.AutoResetEvent.WaitOrFail方法的典型用法代码示例。如果您正苦于以下问题:C# AutoResetEvent.WaitOrFail方法的具体用法?C# AutoResetEvent.WaitOrFail怎么用?C# AutoResetEvent.WaitOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.AutoResetEvent
的用法示例。
在下文中一共展示了AutoResetEvent.WaitOrFail方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsyncProxy_OnBeforeInvoke_ArgumentsSetCorrectly
public async Task AsyncProxy_OnBeforeInvoke_ArgumentsSetCorrectly()
{
var service = Substitute.For<ITestService>();
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndAsyncProxy(c =>
{
OnInvokeHandler handler = (sender, args) =>
{
Assert.AreEqual(false, args.IsRetry, "IsRetry is not set correctly");
Assert.AreEqual(0, args.RetryCounter, "RetryCounter is not set correctly");
Assert.AreEqual(typeof(ITestService), args.ServiceType, "ServiceType is not set correctly");
resetEvent.Set();
};
c.OnBeforeInvoke += handler;
});
await proxy.CallAsync(m => m.VoidMethod("test"));
resetEvent.WaitOrFail("OnBeforeInvoke hasn't been called");;
}
示例2: Proxy_OnAfterInvoke_ReturnValue_ForValueTypeMethods_IsSetCorrectly
public void Proxy_OnAfterInvoke_ReturnValue_ForValueTypeMethods_IsSetCorrectly()
{
var service = Substitute.For<ITestService>();
service
.IntMethod()
.Returns(1337);
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndProxy(c =>
{
OnInvokeHandler handler = (sender, args) =>
{
Assert.IsTrue(args.InvokeInfo.MethodHasReturnValue, "InvokeInfo.MethodHasReturnValue is not set correctly");
Assert.AreEqual(1337, args.InvokeInfo.ReturnValue, "InvokeInfo.ReturnValue is not set correctly");
resetEvent.Set();
};
c.OnAfterInvoke += handler;
});
proxy.IntMethod();
resetEvent.WaitOrFail("OnAfterInvoke not fired");
}
示例3: Proxy_OnAfterInvoke_ReturnValue_ThrowsForVoidMethods
public void Proxy_OnAfterInvoke_ReturnValue_ThrowsForVoidMethods()
{
var service = Substitute.For<ITestService>();
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndProxy(c =>
{
OnInvokeHandler handler = (sender, args) =>
{
Assert.IsFalse(args.InvokeInfo.MethodHasReturnValue, "InvokeInfo.MethodHasReturnValue is not set correctly");
Assert.Throws<InvalidOperationException>(delegate { var x = args.InvokeInfo.ReturnValue; }, "InvokeInfo.ReturnValue did not throw!");
resetEvent.Set();
};
c.OnAfterInvoke += handler;
});
proxy.VoidMethod("test");
resetEvent.WaitOrFail("OnAfterInvoke not fired");
}
示例4: Proxy_OnAfterInvoke_ArgumentsSetCorrectly
public void Proxy_OnAfterInvoke_ArgumentsSetCorrectly()
{
var service = Substitute.For<ITestService>();
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndProxy(c =>
{
OnInvokeHandler handler = (object sender, OnInvokeHandlerArguments args) =>
{
Assert.AreEqual(false, args.IsRetry, "IsRetry is not set correctly");
Assert.AreEqual(0, args.RetryCounter, "RetryCounter is not set correctly");
Assert.AreEqual(typeof(ITestService), args.ServiceType, "ServiceType is not set correctly");
resetEvent.Set();
};
c.OnAfterInvoke += handler;
});
proxy.VoidMethod("test");
resetEvent.WaitOrFail("OnBeforeInvoke not fired");
}
示例5: Proxy_OnAfterInvoke_InvokeInfo_SetCorrectly
public void Proxy_OnAfterInvoke_InvokeInfo_SetCorrectly()
{
var service = Substitute.For<ITestService>();
Request request = new Request { RequestMessage = "message" };
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndProxy(c =>
{
OnInvokeHandler handler = (sender, args) =>
{
Assert.AreEqual("TestMethodComplexMulti", args.InvokeInfo.MethodName, "InvokeInfo.MethodName is not set correctly");
// parameters
Assert.AreEqual(2, args.InvokeInfo.Parameters.Length, "InvokeInfo.Parameters length is incorrect");
Assert.AreEqual("test", args.InvokeInfo.Parameters[0], "InvokeInfo.Parameters[0] is not set correctly");
Assert.AreEqual(request, args.InvokeInfo.Parameters[1], "InvokeInfo.Parameters[1] is not set correctly");
resetEvent.Set();
};
c.OnAfterInvoke += handler;
});
proxy.TestMethodComplexMulti("test", request);
resetEvent.WaitOrFail("OnAfterInvoke not fired");
}
示例6: Proxy_OnBeforeInvoke_InvokeInfo_IsSet
public void Proxy_OnBeforeInvoke_InvokeInfo_IsSet()
{
var service = Substitute.For<ITestService>();
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndProxy(c =>
{
OnInvokeHandler handler = (sender, args) =>
{
Assert.IsNotNull(args.InvokeInfo, "InvokeInfo is null when it should be set");
resetEvent.Set();
};
c.OnBeforeInvoke += handler;
});
proxy.TestMethod("test");
resetEvent.WaitOrFail("OnBeforeInvoke not fired");
}
示例7: Proxy_OnBeforeInvoke_InvokeInfo_SetCorrectly_IntParameter
public void Proxy_OnBeforeInvoke_InvokeInfo_SetCorrectly_IntParameter()
{
var service = Substitute.For<ITestService>();
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndProxy(c =>
{
OnInvokeHandler handler = (sender, args) =>
{
Assert.AreEqual("VoidMethodIntParameter", args.InvokeInfo.MethodName, "InvokeInfo.MethodName is not set correctly");
Assert.AreEqual(1, args.InvokeInfo.Parameters.Length, "InvokeInfo.Parameters length is incorrect");
Assert.AreEqual(1337, args.InvokeInfo.Parameters[0], "InvokeInfo.Parameters[0] is not set correctly");
resetEvent.Set();
};
c.OnBeforeInvoke += handler;
});
proxy.VoidMethodIntParameter(1337);
resetEvent.WaitOrFail("OnBeforeInvoke not fired");
}
示例8: AsyncProxy_OnException_IsFired
public void AsyncProxy_OnException_IsFired()
{
var service = Substitute.For<ITestService>();
service
.When(m => m.VoidMethod("test"))
.Throw(new FaultException());
bool hasFired = false;
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndAsyncProxy(c =>
{
c.OnException += (sender, args) =>
{
hasFired = true;
resetEvent.Set();
};
});
Assert.ThrowsAsync<FaultException>(
() => proxy.CallAsync(m => m.VoidMethod("test")));
resetEvent.WaitOrFail("OnException not fired");
Assert.IsTrue(hasFired);
}
示例9: Async_HandleResponse_ActionWithoutPredicate_CanInspectResponse_WithoutReturning
public async Task Async_HandleResponse_ActionWithoutPredicate_CanInspectResponse_WithoutReturning()
{
var resetEvent = new AutoResetEvent(false);
var service = Substitute.For<ITestService>();
const string expectedInput = "test";
service
.TestMethod(expectedInput)
.Returns(m => m.Arg<string>());
var proxy = service.StartHostAndAsyncProxy(c =>
{
c.HandleResponse<string>(handler: r =>
{
Assert.That(r, Is.EqualTo(expectedInput));
resetEvent.Set();
});
});
var response = await proxy.CallAsync(m => m.TestMethod(expectedInput));
Assert.That(response, Is.EqualTo(expectedInput));
resetEvent.WaitOrFail("Callback not fired");
}
示例10: Proxy_OnException_InformationSetCorrectly
public void Proxy_OnException_InformationSetCorrectly()
{
var service = Substitute.For<ITestService>();
service
.When(m => m.VoidMethod("test"))
.Throw(new FaultException());
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndProxy(c =>
{
c.OnException += (sender, args) =>
{
Assert.IsInstanceOf<FaultException>(args.Exception, "Exception");
Assert.AreEqual("VoidMethod", args.InvokeInfo.MethodName, "InvokeInfo.MethodName");
Assert.AreEqual(typeof(ITestService), args.ServiceType, "ServiceType");
resetEvent.Set();
};
});
Assert.Catch<FaultException>(() => proxy.VoidMethod("test"));
resetEvent.WaitOrFail("OnException not fired");
}
示例11: AsyncProxy_OnCallSuccess_IsFired
public async Task AsyncProxy_OnCallSuccess_IsFired()
{
var service = Substitute.For<ITestService>();
service
.TestMethod("test")
.Returns("OK")
.AndDoes(_ => Thread.Sleep(500));
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndAsyncProxy(c =>
{
c.OnCallSuccess += (invoker, args) =>
{
Assert.That(args.InvokeInfo.MethodName, Is.EqualTo("TestMethodAsync"));
Assert.That(args.InvokeInfo.ReturnValue, Is.EqualTo("OK"));
Assert.That(args.CallDuration, Is.GreaterThan(TimeSpan.MinValue));
resetEvent.Set();
};
});
await proxy.CallAsync(m => m.TestMethod("test"));
resetEvent.WaitOrFail("OnCallSuccess was not triggered");
}
示例12: AsyncProxy_OnCallBegin_IsFired
public async Task AsyncProxy_OnCallBegin_IsFired()
{
var service = Substitute.For<ITestService>();
service
.TestMethod("test")
.Returns("OK");
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndAsyncProxy(c =>
{
c.OnCallBegin += (invoker, args) =>
{
Assert.That(args.InvokeInfo.MethodName, Is.EqualTo("TestMethodAsync"));
resetEvent.Set();
};
});
await proxy.CallAsync(m => m.TestMethod("test"));
resetEvent.WaitOrFail("OnCallBegin was not triggered");
}
示例13: AsyncProxy_OnAfterInvoke_InvokeInfo_IsSet
public async Task AsyncProxy_OnAfterInvoke_InvokeInfo_IsSet()
{
var service = Substitute.For<ITestService>();
var resetEvent = new AutoResetEvent(false);
var proxy = service.StartHostAndAsyncProxy(c =>
{
OnInvokeHandler handler = (sender, args) =>
{
Assert.IsNotNull(args.InvokeInfo, "InvokeInfo is null when it should be set");
resetEvent.Set();
};
c.OnAfterInvoke += handler;
});
await proxy.CallAsync(m => m.TestMethod("test"));
resetEvent.WaitOrFail("OnAfterInvoke not called");
}
示例14: AsyncProxy_OnBeforeInvoke_IfRetry_FiredManyTimes
public async Task AsyncProxy_OnBeforeInvoke_IfRetry_FiredManyTimes()
{
var resetEvent = new AutoResetEvent(false);
// set up a service method that throws first two times, and completes on the third time
var service = Substitute.For<ITestService>();
int mockFireCount = 0;
service
.When(m => m.VoidMethod(Arg.Any<string>()))
.Do(_ =>
{
// fail on first two calls, return on subsequent calls
mockFireCount++;
if (mockFireCount < 3)
throw new Exception();
});
int fireCount = 0;
var proxy = service.StartHostAndAsyncProxy(c =>
{
c.MaximumRetries(10);
c.RetryOnException<FaultException>();
c.RetryOnException<FaultException<ExceptionDetail>>();
OnInvokeHandler handler = (sender, args) =>
{
fireCount++;
Assert.AreEqual(fireCount > 1, args.IsRetry, "IsRetry is not set correctly");
Assert.AreEqual(fireCount - 1, args.RetryCounter, "RetryCounter is not set correctly");
Assert.AreEqual(typeof(ITestService), args.ServiceType, "ServiceType is not set correctly");
if (fireCount >= 2)
resetEvent.Set();
};
c.OnBeforeInvoke += handler;
});
await proxy.CallAsync(m => m.VoidMethod("test"));
resetEvent.WaitOrFail("OnBeforeInvoke probably not called");
Assert.AreEqual(3, fireCount, "Not called three times!");
}