Esempio n. 1
0
        public void Raises_DiagnosticGenerated_On_Exception()
        {
            var mocks   = new Mocks();
            var handler = new DistributedMessageHandler(
                mocks.Client.Object);

            mocks.Diagnostic.Setup(m => m.Debug(It.IsAny <string>()));

            var conn = new Mock <IMessageConnection>();

            conn.Setup(m => m.WriteAsync(It.IsAny <IOutgoingMessage>(), It.IsAny <CancellationToken?>()))
            .Throws(new Exception());

            var msg = new MessageBuilder()
                      .WriteCode(MessageCode.Distributed.Ping)
                      .Build();

            var diagnostics = new List <DiagnosticEventArgs>();

            handler.DiagnosticGenerated += (_, e) => diagnostics.Add(e);
            handler.HandleMessageRead(conn.Object, msg);

            diagnostics = diagnostics
                          .Where(d => d.Level == DiagnosticLevel.Warning)
                          .Where(d => d.Message.IndexOf("Error handling distributed message", StringComparison.InvariantCultureIgnoreCase) > -1)
                          .ToList();

            Assert.Single(diagnostics);
        }
Esempio n. 2
0
        public void Raises_DiagnosticGenerated_On_SearchResponseResolver_Exception(string username, int token, string query)
        {
            var mocks   = new Mocks();
            var handler = new DistributedMessageHandler(
                mocks.Client.Object);

            mocks.Client.Setup(m => m.Options)
            .Returns(new SoulseekClientOptions(searchResponseResolver: (a, b, c) => { throw new Exception(); }));

            mocks.Diagnostic.Setup(m => m.Debug(It.IsAny <string>()));

            var conn = new Mock <IMessageConnection>();

            var message = new DistributedSearchRequest(username, token, query).ToByteArray();

            var diagnostics = new List <DiagnosticEventArgs>();

            handler.DiagnosticGenerated += (_, e) => diagnostics.Add(e);
            handler.HandleMessageRead(conn.Object, message);

            diagnostics = diagnostics
                          .Where(d => d.Level == DiagnosticLevel.Warning)
                          .Where(d => d.Message.IndexOf("Error resolving search response", StringComparison.InvariantCultureIgnoreCase) > -1)
                          .ToList();

            Assert.Single(diagnostics);
        }