本文整理汇总了C#中TestDelegate类的典型用法代码示例。如果您正苦于以下问题:C# TestDelegate类的具体用法?C# TestDelegate怎么用?C# TestDelegate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestDelegate类属于命名空间,在下文中一共展示了TestDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Original delegate syntax required
// initialization with a named method.
TestDelegate testDelA = new TestDelegate(M);
// C# 2.0: A delegate can be initialized with
// inline code, called an "anonymous method." This
// method takes a string as an input parameter.
TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); };
// C# 3.0. A delegate can be initialized with
// a lambda expression. The lambda also takes a string
// as an input parameter (x). The type of x is inferred by the compiler.
TestDelegate testDelC = (x) => { Console.WriteLine(x); };
// Invoke the delegates.
testDelA("Hello. My name is M and I write lines.");
testDelB("That's nothing. I'm anonymous and ");
testDelC("I'm a famous author.");
// Initialize delegate with named method, anonymous method and lamba expression.
TestDelegate testDel = new TestDelegate(M);
testDel += delegate(string s) { Console.WriteLine(s); };
testDel += (x) => { Console.WriteLine(x); };
// Invoke the delegate.
testDel("Delegate with multiple initialisations.");
Console.ReadLine(); //wait for <ENTER>
}
示例2: addChildToThingThrowsException
public void addChildToThingThrowsException()
{
Thing thing = new Thing("lantern");
var testDel = new TestDelegate(() => thing.AddChild(new Thing("fork")));
Assert.That(testDel, Throws.TypeOf<NoChildrenForThingsException>());
}
示例3: TestArduinoStateToggles
public void TestArduinoStateToggles()
{
ArduinoCommsBase motorArduino = new MotorControllerArduino(mLogger);
TestDelegate connectDel = new TestDelegate(delegate() { motorArduino.StartArduinoComms(); });
Assert.AreEqual(motorArduino.ArduinoState, ProsthesisCore.Telemetry.ProsthesisTelemetry.DeviceState.Uninitialized);
Assert.DoesNotThrow(connectDel);
Assert.DoesNotThrow(delegate() { motorArduino.ToggleArduinoState(false); });
//Wait 100ms for the message to cycle
System.Threading.Thread.Sleep(100);
Assert.AreEqual(motorArduino.ArduinoState, ProsthesisCore.Telemetry.ProsthesisTelemetry.DeviceState.Disabled);
Assert.DoesNotThrow(delegate() { motorArduino.ToggleArduinoState(true); });
//Wait 100ms for the message to cycle
System.Threading.Thread.Sleep(100);
Assert.AreEqual(motorArduino.ArduinoState, ProsthesisCore.Telemetry.ProsthesisTelemetry.DeviceState.Active);
Assert.IsTrue(motorArduino.IsConnected);
Assert.DoesNotThrow(delegate() { motorArduino.StopArduinoComms(true); });
Assert.IsFalse(motorArduino.IsConnected);
Assert.AreEqual(motorArduino.ArduinoState, ProsthesisCore.Telemetry.ProsthesisTelemetry.DeviceState.Disconnected);
}
示例4: Main
static void Main(string[] args)
{
// Original delegate syntax required
// initialization with a named method.
TestDelegate testDelA = new TestDelegate(M);
// C# 2.0: A delegate can be initialized with
// inline code, called an "anonymous method." This
// method takes a string as an input parameter.
TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); };
// C# 3.0. A delegate can be initialized with
// a lambda expression. The lambda also takes a string
// as an input parameter (x). The type of x is inferred by the compiler.
TestDelegate testDelC = (x) => { Console.WriteLine(x); };
// Invoke the delegates.
testDelA("Hello. My name is M and I write lines.");
testDelB("That's nothing. I'm anonymous and ");
testDelC("I'm a famous author.");
// Keep console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
示例5: 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;
}
}
示例6: CatchArgumentOutOfRangeException
public static ArgumentOutOfRangeException CatchArgumentOutOfRangeException(TestDelegate code, string paramName, string exceptionMessage, params object[] args)
{
var exception = Assert.Catch<ArgumentOutOfRangeException>(code);
Assert.AreEqual(paramName, exception.ParamName);
Assert.AreEqual(GetMessage(paramName, exceptionMessage, args), exception.Message);
return exception;
}
示例7: func
public void func()
{
TestDelegate d1 = new TestDelegate(CallBackOne);
d1 += new TestDelegate(CallBackTwo);
cout(d1.Target);
d1.BeginInvoke(null, null);
}
示例8: Repricing_InvalidTickets_ExceptionThrown
public void Repricing_InvalidTickets_ExceptionThrown()
{
var order = new Order();
var callDelegate = new TestDelegate(() => _pricingManager.RepricingAsync(order).Wait());
Assert.Throws<AggregateException>(callDelegate);
Assert.Throws<AggregateException>(callDelegate).InnerExceptions.Any(exception => exception is TicketNotValidException);
}
示例9: GetParameters
public void GetParameters()
{
StringWriter sw = new StringWriter();
string name = "MyName";
Delegate hello = new TestDelegate(this.Hello);
TestCase tc = new TestCase(name, hello, sw);
ArrayAssert.AreEqual(new Object[] { sw }, tc.GetParameters());
}
示例10: GetTest
public void GetTest()
{
StringWriter sw = new StringWriter();
string name = "MyName";
Delegate hello = new TestDelegate(this.Hello);
TestCase tc = new TestCase(name, hello, sw);
Assert.AreEqual(hello.Method, tc.TestDelegate.Method);
}
示例11: When_User_Id_Is_Not_Provided_It_Must_Throws_Exception
public void When_User_Id_Is_Not_Provided_It_Must_Throws_Exception()
{
TestDelegate createUserWithNullableId = new TestDelegate(() => { new User(null); });
TestDelegate createUserWithEmptyId = new TestDelegate(() => { new User(String.Empty); });
Assert.Throws<ArgumentNullException>(createUserWithNullableId, "User ID cannot be null.");
Assert.Throws<ArgumentException>(createUserWithEmptyId, "User ID cannot be empty.");
}
示例12: Start
void Start()
{
//use default when not be set value in Awake
if (testDelegate == null)
testDelegate = nullTestDelegate;
if (setByfunction == null)
setByfunction = nullTestDelegate;
}
示例13: when_balance_below_0_trader_should_go_bankrupt
public void when_balance_below_0_trader_should_go_bankrupt()
{
_trader.SetBalance(0);
var methodUnderTest = new TestDelegate(_trader.CheckBankrupt);
Assert.Throws<ApplicationException>(methodUnderTest);
}
示例14: GetConfigurationBeforeLoadingConfigurationMethods
public void GetConfigurationBeforeLoadingConfigurationMethods()
{
// Arrange
// Action
var testCase = new TestDelegate(() => Configure.Get<IMyTestConfiguration>());
// Assert
Assert.Throws(typeof(ConfigurationEnvironmentNotInitializedException), testCase);
}
示例15: ObjectWithBothMaleAndNeutralAttributesThrows
public void ObjectWithBothMaleAndNeutralAttributesThrows()
{
var parser = new Parser();
var testDel = new TestDelegate(() => parser.Parse("Jason [mp]"));
Assert.That(testDel, Throws.TypeOf<PersonCannotBeTwoGenders>());
}