Example #1
0
        public void Fault_RaisedOnIdleTimeout()
        {
            var connection = new Mock <IConnection>();

            using (var faultedEvent = new ManualResetEventSlim(initialState: false))
                using (var plugin = new Plugin(
                           filePath: @"C:\a\b\c.d",
                           connection: connection.Object,
                           process: Mock.Of <IPluginProcess>(),
                           isOwnProcess: false,
                           idleTimeout: Timeout.InfiniteTimeSpan))
                {
                    FaultedPluginEventArgs args = null;

                    plugin.Faulted += (object sender, FaultedPluginEventArgs e) =>
                    {
                        args = e;

                        faultedEvent.Set();
                    };

                    var protocolErrorArgs = new ProtocolErrorEventArgs(new ProtocolException("test"));

                    connection.Raise(x => x.Faulted += null, protocolErrorArgs);

                    faultedEvent.Wait();

                    Assert.NotNull(args);
                    Assert.Same(plugin, args.Plugin);
                    Assert.Same(protocolErrorArgs.Exception, args.Exception);
                }
        }
Example #2
0
        public void Faulted_RaisedForDeserializationError()
        {
            var json = "{\"RequestId\":\"a\",\"Type\":\"Response\",\"Method\":\"None\",\"Payload\":\"{\\\"d\\\":\\\"e\\\"}\"}\r\n";

            using (var faultedEvent = new ManualResetEventSlim(initialState: false))
                using (var reader = new StringReader(json))
                    using (var receiver = new StandardInputReceiver(reader))
                    {
                        ProtocolErrorEventArgs args = null;

                        receiver.Faulted += (object sender, ProtocolErrorEventArgs e) =>
                        {
                            args = e;

                            faultedEvent.Set();
                        };

                        receiver.Connect();

                        faultedEvent.Wait();

                        Assert.NotNull(args);
                        Assert.IsType <ProtocolException>(args.Exception);
                    }
        }
        public void Constructor_InitializesExceptionProperty()
        {
            var exception = new DivideByZeroException();
            var args      = new ProtocolErrorEventArgs(exception);

            Assert.Same(exception, args.Exception);
        }
        public void Faulted_RaisedForInvalidMessage(string json)
        {
            var process = new Mock <IPluginProcess>();

            process.Setup(x => x.BeginReadLine())
            .Callback(() => process.Raise(x => x.LineRead += null, new LineReadEventArgs(json)));

            using (var faultedEvent = new ManualResetEventSlim(initialState: false))
                using (var receiver = new StandardOutputReceiver(process.Object))
                {
                    ProtocolErrorEventArgs args = null;

                    receiver.Faulted += (object sender, ProtocolErrorEventArgs e) =>
                    {
                        args = e;

                        faultedEvent.Set();
                    };

                    receiver.Connect();

                    faultedEvent.Wait();

                    Assert.NotNull(args);
                    Assert.IsType <ProtocolException>(args.Exception);
                }
        }
Example #5
0
        public void Faulted_RaisedForParseError()
        {
            var invalidJson = "text\r\n";

            using (var faultedEvent = new ManualResetEventSlim(initialState: false))
                using (var reader = new StringReader(invalidJson))
                    using (var receiver = new StandardInputReceiver(reader))
                    {
                        ProtocolErrorEventArgs args = null;

                        receiver.Faulted += (object sender, ProtocolErrorEventArgs e) =>
                        {
                            args = e;

                            faultedEvent.Set();
                        };

                        receiver.Connect();

                        faultedEvent.Wait();

                        Assert.NotNull(args);
                        Assert.IsType <ProtocolException>(args.Exception);
                    }
        }
        public void Faulted_RaisedForDeserializationError()
        {
            var json = "{\"RequestId\":\"a\",\"Type\":\"Response\",\"Method\":\"None\",\"Payload\":\"{\\\"d\\\":\\\"e\\\"}\"}\r\n";

            var process = new Mock <IPluginProcess>();

            process.Setup(x => x.BeginReadLine())
            .Callback(() => process.Raise(x => x.LineRead += null, new LineReadEventArgs(json)));

            using (var faultedEvent = new ManualResetEventSlim(initialState: false))
                using (var receiver = new StandardOutputReceiver(process.Object))
                {
                    ProtocolErrorEventArgs args = null;

                    receiver.Faulted += (object sender, ProtocolErrorEventArgs e) =>
                    {
                        args = e;

                        faultedEvent.Set();
                    };

                    receiver.Connect();

                    faultedEvent.Wait();

                    Assert.NotNull(args);
                    Assert.NotNull(args.Exception);
                    Assert.IsType <ProtocolException>(args.Exception);
                    Assert.Null(args.Message);
                }
        }
Example #7
0
        public async Task Faulted_RaisedForProtocolError()
        {
            using (var test = new ConnectAsyncTest(ConnectionOptions.CreateDefault(), ConnectionOptions.CreateDefault()))
            {
                await Task.WhenAll(
                    test.RemoteToLocalConnection.ConnectAsync(test.CancellationToken),
                    test.LocalToRemoteConnection.ConnectAsync(test.CancellationToken));

                using (var faultedEvent = new ManualResetEventSlim(initialState: false))
                {
                    ProtocolErrorEventArgs args = null;

                    test.LocalToRemoteConnection.Faulted += (object sender, ProtocolErrorEventArgs e) =>
                    {
                        args = e;

                        faultedEvent.Set();
                    };

                    test.LocalToRemoteConnection.MessageDispatcher.RequestHandlers.TryAdd(
                        MessageMethod.Initialize,
                        new RequestHandler <InitializeResponse>(new InitializeResponse(MessageResponseCode.Success)));

                    var message = new Message(
                        requestId: "a",
                        type: MessageType.Response,
                        method: MessageMethod.Initialize);

                    await test.RemoteToLocalConnection.SendAsync(message, test.CancellationToken);

                    faultedEvent.Wait();

                    Assert.NotNull(args);
                    Assert.IsType <ProtocolException>(args.Exception);
                    Assert.NotNull(args.Message);
                    Assert.Equal(message.RequestId, args.Message.RequestId);
                    Assert.Equal(message.Type, args.Message.Type);
                    Assert.Equal(message.Method, args.Message.Method);
                }
            }
        }
 /// <summary>
 /// Event handler for Http2 session error.
 /// </summary>
 /// <param name="sender">The sender</param>
 /// <param name="e">Event data</param>
 private static void OnSessionError(object sender, ProtocolErrorEventArgs e)
 {
     Http2Logger.LogError("Session error: " + e.Exeption.Message);
     if (session.State == ProtocolSessionState.Closed)
     {
         // server closed on error
         if (appScriptMode)
         {
             // abort execution with error code
             Environment.Exit(1);
         }
     }
 }
 private void session_OnError(object sender, ProtocolErrorEventArgs e)
 {
     Console.WriteLine(e.Exeption.Message);
 }
Example #10
0
 static void onErrMsg(ProtocolErrorEventArgs msg)
 {
     System.Console.WriteLine("msg={0} pos={2} data={1}", msg.Msg, ByteArrayToString(msg.Data, msg.DataLen), msg.ErrorPos);
 }
Example #11
0
 private void session_OnError(object sender, ProtocolErrorEventArgs e)
 {
     Console.WriteLine(e.Exeption.Message);
 }
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="ProtocolUSB5E4DNoHeadCrc" />.
 /// </summary>
 public ProtocolUSB5E4DNoHeadCrc()
 {
     _package = new ProtocolMsgEventArgs(MaxFrameLen);
     _errorFrame = new ProtocolErrorEventArgs(MaxFrameLen);
     Reset();
 }
Example #13
0
 /// <summary>
 /// Обертка события: возникновение ошибки протокола в декодере
 /// </summary>
 /// <param name="e">Класс описывающий ошибку протокола</param>
 protected virtual void OnProtocolError(ProtocolErrorEventArgs e)
 {
     if (this.GotProtocolError != null)
     {
         this.GotProtocolError(e);
     }
 }
 /// <summary>
 /// Создаем декодер
 /// </summary>
 public ProtocolUSB7C6E()
 {
     _tmpMsg = new ProtocolMsgEventArgs(DECODER_MAX_DATA_LEN);
         _tmpErrMsg = new ProtocolErrorEventArgs(70000);        // FIXIT: убрать константу
         Reset();
 }