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


C# TestDelegate类代码示例

本文整理汇总了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>
        }
开发者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


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