Пример #1
0
 public void TestCallbackHandlers()
 {
     var tokenSource          = new CancellationTokenSource();
     var callbackHandlersDict = new ConcurrentDictionary <int, ICallbackHandler>();
     int inputToHandler       = 1;
     {
         // Test CallbackConnection using a ICallbackHandler that runs
         // normally without error.
         var callbackHandler = new TestCallbackHandler
         {
             Id = 1
         };
         callbackHandlersDict[callbackHandler.Id] = callbackHandler;
         TestCallbackConnection(
             callbackHandlersDict,
             callbackHandler,
             inputToHandler,
             tokenSource.Token);
         Assert.Single(callbackHandler.Inputs);
         Assert.Equal(
             callbackHandler.Apply(inputToHandler),
             callbackHandler.Inputs.First());
     }
     {
         // Test CallbackConnection using a ICallbackHandler that
         // throws an exception.
         var callbackHandler = new ThrowsExceptionHandler
         {
             Id = 2
         };
         callbackHandlersDict[callbackHandler.Id] = callbackHandler;
         TestCallbackConnection(
             callbackHandlersDict,
             callbackHandler,
             inputToHandler,
             tokenSource.Token);
         Assert.Empty(callbackHandler.Inputs);
     }
     {
         // Test CallbackConnection when cancellation has been requested for the token.
         tokenSource.Cancel();
         var callbackHandler = new TestCallbackHandler
         {
             Id = 3
         };
         callbackHandlersDict[callbackHandler.Id] = callbackHandler;
         TestCallbackConnection(
             callbackHandlersDict,
             callbackHandler,
             inputToHandler,
             tokenSource.Token);
         Assert.Empty(callbackHandler.Inputs);
     }
 }
        public async Task WhenHandlingAnything_ThenThrowsWellKnownException()
        {
            var handler = new ThrowsExceptionHandler();

            var body    = new byte[] { };
            var headers = new Dictionary <string, string>();
            var context = new ProcessingContext("", "", "");

            await AssertExt.ThrowsAsync <JustForTestingException>(
                () => handler.ExecuteAsync(context, body, headers)
                );
        }