本文整理汇总了C#中TestDelegate类的典型用法代码示例。如果您正苦于以下问题:C# TestDelegate类的具体用法?C# TestDelegate怎么用?C# TestDelegate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestDelegate类属于命名空间,在下文中一共展示了TestDelegate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>
}
开发者ID:AdriVanHoudt,项目名称:School,代码行数:31,代码来源:AnonymousFunctionsProgram.cs
示例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>());
}
开发者ID:JasonLautzenheiser,项目名称:Trizbort-Object-Parser,代码行数:7,代码来源:ThingTests.cs
示例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);
}
开发者ID:gjorban,项目名称:ProsthesisPi,代码行数:26,代码来源:ArduinoTests.cs
示例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();
}
开发者ID:terryjintry,项目名称:OLSource1,代码行数:25,代码来源:anonymous-functions--csharp-programming-guide-_1.cs
示例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;
}
}
开发者ID:klimenkor,项目名称:googleads-dotnet-lib,代码行数:38,代码来源:ExampleTestsBase.cs
示例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;
}
开发者ID:Corniel,项目名称:Qowaiv,代码行数:7,代码来源:ExceptionAssert.cs
示例7: func
public void func()
{
TestDelegate d1 = new TestDelegate(CallBackOne);
d1 += new TestDelegate(CallBackTwo);
cout(d1.Target);
d1.BeginInvoke(null, null);
}
开发者ID:ppatoria,项目名称:SoftwareDevelopment,代码行数:7,代码来源:DelegateTest.cs
示例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);
}
开发者ID:apankrushin,项目名称:PricingManager,代码行数:8,代码来源:PricingManagerTest.cs
示例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());
}
开发者ID:BackupTheBerlios,项目名称:mbunit-svn,代码行数:8,代码来源:TestCaseTest.cs
示例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);
}
开发者ID:BackupTheBerlios,项目名称:mbunit-svn,代码行数:8,代码来源:TestCaseTest.cs
示例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.");
}
开发者ID:bernardobrezende,项目名称:NSquare,代码行数:8,代码来源:UserTests.cs
示例12: Start
void Start()
{
//use default when not be set value in Awake
if (testDelegate == null)
testDelegate = nullTestDelegate;
if (setByfunction == null)
setByfunction = nullTestDelegate;
}
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:8,代码来源:zzSignalSlotExample.cs
示例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);
}
开发者ID:ITfanatic,项目名称:IT7302_Assignment3_Monopoly,代码行数:8,代码来源:TraderTests.cs
示例14: GetConfigurationBeforeLoadingConfigurationMethods
public void GetConfigurationBeforeLoadingConfigurationMethods()
{
// Arrange
// Action
var testCase = new TestDelegate(() => Configure.Get<IMyTestConfiguration>());
// Assert
Assert.Throws(typeof(ConfigurationEnvironmentNotInitializedException), testCase);
}
开发者ID:TheSoftweyrGroup,项目名称:Softweyr.Configuration,代码行数:9,代码来源:ConfigurationCoreTests.cs
示例15: ObjectWithBothMaleAndNeutralAttributesThrows
public void ObjectWithBothMaleAndNeutralAttributesThrows()
{
var parser = new Parser();
var testDel = new TestDelegate(() => parser.Parse("Jason [mp]"));
Assert.That(testDel, Throws.TypeOf<PersonCannotBeTwoGenders>());
}
开发者ID:JasonLautzenheiser,项目名称:Trizbort-Object-Parser,代码行数:9,代码来源:ParserAttributeTests.cs
示例16: Invoke
public void Invoke()
{
StringWriter sw = new StringWriter();
string name = "MyName";
Delegate hello = new TestDelegate(this.Hello);
TestCase tc = new TestCase(name, hello, sw);
tc.Invoke(this,new ArrayList());
Assert.AreEqual("hello", sw.ToString());
}
开发者ID:BackupTheBerlios,项目名称:mbunit-svn,代码行数:9,代码来源:TestCaseTest.cs
示例17: Execute
public static void Execute() {
TestDelegate d1 = new TestDelegate(Dowork);
TestDelegate d2 = delegate(string s) { Console.WriteLine(s); };
TestDelegate d3 = (x) => { Console.WriteLine(x); };
d1("Hello World");
d2("Hello World2");
d3("Hello World3");
TestLambda((x) => { Console.WriteLine(x); });
}
开发者ID:HK-Zhang,项目名称:Grains,代码行数:9,代码来源:LambdaDemo.cs
示例18: Argument
public static void Argument(TestDelegate code, string message, string paramName)
{
var constraint =
Throws.ArgumentException
.With.Message.StartsWith(message)
.And
.With.Property("ParamName").EqualTo(paramName);
Assert.That(code, constraint);
}
开发者ID:mergut,项目名称:FakeSystemWeb,代码行数:10,代码来源:ExceptionAssert.cs
示例19: ValidateRequiredParameters
/// <summary>
/// Validates whether an ArgumentNullException is called whenever a required
/// property in targetObject is null, and testDelegate is invoked.
/// </summary>
/// <param name="targetObject">The target object.</param>
/// <param name="propertyNames">The property names to be checked for null
/// values.</param>
/// <param name="testDelegate">The test delegate.</param>
public static void ValidateRequiredParameters(object targetObject, string[] propertyNames,
TestDelegate testDelegate) {
foreach (string propertyName in propertyNames) {
PropertyInfo propInfo = targetObject.GetType().GetProperty(propertyName);
object oldValue = propInfo.GetValue(targetObject, null);
propInfo.SetValue(targetObject, null, null);
Assert.Throws<ArgumentNullException>(testDelegate);
propInfo.SetValue(targetObject, oldValue, null);
}
}
开发者ID:Zweitze,项目名称:googleads-adwords-dotnet-lib,代码行数:18,代码来源:TestUtils.cs
示例20: AssertMethodFailsWithSerializableException
static void AssertMethodFailsWithSerializableException(TestDelegate intentionallyFailingMethod)
{
var original = Assert.Catch<Exception>(intentionallyFailingMethod);
var formatter = new BinaryFormatter();
var ms = new MemoryStream();
formatter.Serialize(ms, original);
object deserialized = formatter.Deserialize(new MemoryStream(ms.ToArray()));
Assert.AreEqual(original.ToString(), deserialized.ToString());
}
开发者ID:markijbema,项目名称:ExpressionToCode,代码行数:11,代码来源:ExceptionsSerialization.cs
注:本文中的TestDelegate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论