Represents a logger that logs message payloads according to the types passed to the constructor.
Inheritance: IS101Logger
Esempio n. 1
0
        public void MainTest()
        {
            using (var writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                AssertThrow <ArgumentNullException>(
                    () => new S101Logger(null, writer).Dispose(),
                    () => new S101Logger(GlowTypes.Instance, (TextWriter)null).Dispose(),
                    () => new S101Logger(GlowTypes.Instance, (XmlWriter)null).Dispose(),
                    () => new S101Logger((IEmberConverter)null, XmlWriter.Create(writer)).Dispose());

                using (var logger = new S101Logger(GlowTypes.Instance, writer))
                {
                    AssertThrow <ArgumentNullException>(
                        () => logger.LogData("Whatever", "Send", null, 0, 0),
                        () => logger.LogMessage(null, new S101Message(0x00, new KeepAliveRequest()), null),
                        () => logger.LogMessage("Send", null, null),
                        () => logger.LogException("Send", null));
                }
            }
        }
Esempio n. 2
0
        public void MainTest()
        {
            using (var writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                AssertThrow<ArgumentNullException>(
                    () => new S101Logger(null, writer).Dispose(),
                    () => new S101Logger(GlowTypes.Instance, (TextWriter)null).Dispose(),
                    () => new S101Logger(GlowTypes.Instance, (XmlWriter)null).Dispose(),
                    () => new S101Logger((IEmberConverter)null, XmlWriter.Create(writer)).Dispose());

                using (var logger = new S101Logger(GlowTypes.Instance, writer))
                {
                    AssertThrow<ArgumentNullException>(
                        () => logger.LogData("Whatever", "Send", null, 0, 0),
                        () => logger.LogMessage(null, new S101Message(0x00, new KeepAliveRequest()), null),
                        () => logger.LogMessage("Send", null, null),
                        () => logger.LogException("Send", null));
                }
            }
        }
        public void KeepAliveExceptionTest()
        {
            AsyncPump.Run(
                async() =>
            {
                var providerTask = WaitForConnectionAsync();
                int timeout      = this.Random.Next(4000, 8000);
                Console.WriteLine("Timeout: {0}", timeout);

                using (var consumer = new TcpClient("localhost", 8099))
                    using (var stream = consumer.GetStream())
                        using (var logger = new S101Logger(GlowTypes.Instance, Console.Out))
                            using (var consumerClient =
                                       new S101Client(consumer, stream.ReadAsync, stream.WriteAsync, logger, timeout, 8192))
                            {
                                (await providerTask).Ignore();
                                consumerClient.KeepAliveRequestSlot = (byte)this.Random.Next(byte.MaxValue + 1);
                                var source = new TaskCompletionSource <bool>();
                                consumerClient.ConnectionLost += (s, e) => OnConnectionLost(source, e);
                                var task = await Task.WhenAny(source.Task, Task.Delay(timeout + (timeout / 4)));
                                await AssertThrowAsync <S101Exception>(() => task);
                            }
            });
        }
Esempio n. 4
0
        public void KeepAliveExceptionTest()
        {
            AsyncPump.Run(
                async () =>
                {
                    var providerTask = WaitForConnectionAsync();
                    int timeout = this.Random.Next(4000, 8000);
                    Console.WriteLine("Timeout: {0}", timeout);

                    using (var consumer = new TcpClient("localhost", 8099))
                    using (var stream = consumer.GetStream())
                    using (var logger = new S101Logger(GlowTypes.Instance, Console.Out))
                    using (var consumerClient =
                        new S101Client(consumer, stream.ReadAsync, stream.WriteAsync, logger, timeout, 8192))
                    {
                        (await providerTask).Ignore();
                        consumerClient.KeepAliveRequestSlot = (byte)this.Random.Next(byte.MaxValue + 1);
                        var source = new TaskCompletionSource<bool>();
                        consumerClient.ConnectionLost += (s, e) => OnConnectionLost(source, e);
                        var task = await Task.WhenAny(source.Task, Task.Delay(timeout + (timeout / 4)));
                        await AssertThrowAsync<S101Exception>(() => task);
                    }
                });
        }