public void Wrapped()
        {
            MockMessageBroker  broker = new MockMessageBroker();
            MockExecutionTimer timer  = new MockExecutionTimer();

            MemoryTraceWriter innerWriter = new MemoryTraceWriter();

            GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer, innerWriter);

            writer.Trace(TraceLevel.Verbose, "Random text", null);
            writer.Trace(TraceLevel.Error, "More random text", null);
            Assert.AreEqual(2, writer.TraceMessages.Count);

            Assert.AreEqual(2, innerWriter.GetTraceMessages().Count());

            Assert.AreEqual("Verbose Random text", innerWriter.GetTraceMessages().ElementAt(0).Substring(24));
            Assert.AreEqual("Error More random text", innerWriter.GetTraceMessages().ElementAt(1).Substring(24));

            innerWriter.LevelFilter = TraceLevel.Warning;
            writer.Trace(TraceLevel.Verbose, "Random text", null);
            writer.Trace(TraceLevel.Warning, "More random text", null);
            writer.Trace(TraceLevel.Error, "More random text", null);
            Assert.AreEqual(4, innerWriter.GetTraceMessages().Count());

            Assert.AreEqual(TraceLevel.Verbose, writer.LevelFilter);
        }
        public void Unknown()
        {
            MockMessageBroker  broker = new MockMessageBroker();
            MockExecutionTimer timer  = new MockExecutionTimer();

            GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer);

            writer.Trace(TraceLevel.Verbose, "Random text", null);
            writer.Trace(TraceLevel.Verbose, "More random text", null);
            Assert.AreEqual(2, writer.TraceMessages.Count);

            IList <JsonTraceMessage> messages = broker.Messages.OfType <JsonTraceMessage>().ToList();

            Assert.AreEqual(2, messages.Count);

            Assert.AreEqual(JsonAction.Unknown, messages[0].Action);
            Assert.AreEqual(null, messages[0].Type);
            Assert.AreEqual(null, messages[0].Duration);
            Assert.AreEqual("Random text", messages[0].Message);

            Assert.AreEqual(JsonAction.Unknown, messages[1].Action);
            Assert.AreEqual(null, messages[1].Type);
            Assert.AreEqual(TimeSpan.FromSeconds(1), messages[1].Duration);
            Assert.AreEqual("More random text", messages[1].Message);

            IList <JsonTimelineMessage> timelineMessages = broker.Messages.OfType <JsonTimelineMessage>().ToList();

            Assert.AreEqual(1, timelineMessages.Count);
            Assert.AreEqual("Unknown", timelineMessages[0].EventName);
        }
        public void TimerStrategyReturnNull()
        {
            MockMessageBroker broker = new MockMessageBroker();

            GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => null);

            writer.Trace(TraceLevel.Verbose, "Started serializing System.Int32.", null);
            writer.Trace(TraceLevel.Verbose, "Serialized JSON:" + Environment.NewLine + new JArray(1, 2, 3), null);
            Assert.AreEqual(0, writer.TraceMessages.Count);

            IList <JsonTraceMessage> messages = broker.Messages.OfType <JsonTraceMessage>().ToList();

            Assert.AreEqual(1, messages.Count);

            Assert.AreEqual(JsonAction.Serialize, messages[0].Action);
            Assert.AreEqual("Int32", messages[0].Type);
            Assert.AreEqual(null, messages[0].Duration);
            Assert.AreEqual(@"[
  1,
  2,
  3
]", messages[0].JsonText);

            IList <JsonTimelineMessage> timelineMessages = broker.Messages.OfType <JsonTimelineMessage>().ToList();

            Assert.AreEqual(1, timelineMessages.Count);
            Assert.AreEqual("Serialize - Int32", timelineMessages[0].EventName);
            Assert.AreEqual(TimeSpan.Zero, timelineMessages[0].Duration);
        }
        public void DeserializeToLinqToJson()
        {
            MockMessageBroker  broker = new MockMessageBroker();
            MockExecutionTimer timer  = new MockExecutionTimer();

            GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer);

            writer.Trace(TraceLevel.Verbose, @"Deserialized JSON:
[1,2,3]", null);

            Assert.AreEqual(1, writer.TraceMessages.Count);

            IList <JsonTraceMessage> messages = broker.Messages.OfType <JsonTraceMessage>().ToList();

            Assert.AreEqual(1, messages.Count);

            Assert.AreEqual(JsonAction.Deserialize, messages[0].Action);
            Assert.AreEqual(null, messages[0].Type);
            Assert.AreEqual(TimeSpan.FromSeconds(1), messages[0].Duration);
            Assert.AreEqual(null, messages[0].Message);
            Assert.AreEqual(@"[1,2,3]", messages[0].JsonText);

            IList <JsonTimelineMessage> timelineMessages = broker.Messages.OfType <JsonTimelineMessage>().ToList();

            Assert.AreEqual(1, timelineMessages.Count);
            Assert.AreEqual("Deserialize", timelineMessages[0].EventName);
        }
    public void Unknown()
    {
      MockMessageBroker broker = new MockMessageBroker();
      MockExecutionTimer timer = new MockExecutionTimer();

      GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer);
      writer.Trace(TraceLevel.Verbose, "Random text", null);
      writer.Trace(TraceLevel.Verbose, "More random text", null);
      Assert.AreEqual(2, writer.TraceMessages.Count);

      IList<JsonTraceMessage> messages = broker.Messages.OfType<JsonTraceMessage>().ToList();
      Assert.AreEqual(2, messages.Count);

      Assert.AreEqual(JsonAction.Unknown, messages[0].Action);
      Assert.AreEqual(null, messages[0].Type);
      Assert.AreEqual(null, messages[0].Duration);
      Assert.AreEqual("Random text", messages[0].Message);

      Assert.AreEqual(JsonAction.Unknown, messages[1].Action);
      Assert.AreEqual(null, messages[1].Type);
      Assert.AreEqual(TimeSpan.FromSeconds(1), messages[1].Duration);
      Assert.AreEqual("More random text", messages[1].Message);

      IList<JsonTimelineMessage> timelineMessages = broker.Messages.OfType<JsonTimelineMessage>().ToList();
      Assert.AreEqual(1, timelineMessages.Count);
      Assert.AreEqual("Unknown", timelineMessages[0].EventName);
    }
    public void Wrapped()
    {
      MockMessageBroker broker = new MockMessageBroker();
      MockExecutionTimer timer = new MockExecutionTimer();

      MemoryTraceWriter innerWriter = new MemoryTraceWriter();

      GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer, innerWriter);
      writer.Trace(TraceLevel.Verbose, "Random text", null);
      writer.Trace(TraceLevel.Error, "More random text", null);
      Assert.AreEqual(2, writer.TraceMessages.Count);

      Assert.AreEqual(2, innerWriter.GetTraceMessages().Count());

      Assert.AreEqual("Verbose Random text", innerWriter.GetTraceMessages().ElementAt(0).Substring(24));
      Assert.AreEqual("Error More random text", innerWriter.GetTraceMessages().ElementAt(1).Substring(24));

      innerWriter.LevelFilter = TraceLevel.Warning;
      writer.Trace(TraceLevel.Verbose, "Random text", null);
      writer.Trace(TraceLevel.Warning, "More random text", null);
      writer.Trace(TraceLevel.Error, "More random text", null);
      Assert.AreEqual(4, innerWriter.GetTraceMessages().Count());

      Assert.AreEqual(TraceLevel.Verbose, writer.LevelFilter);
    }
        public void Serialize()
        {
            MockMessageBroker  broker = new MockMessageBroker();
            MockExecutionTimer timer  = new MockExecutionTimer();

            GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer);

            writer.Trace(TraceLevel.Verbose, "Started serializing System.Int32.", null);
            writer.Trace(TraceLevel.Verbose, "Something something dark side.", null);
            Exception exception = null;

            try
            {
                exception = new Exception("Test exception.");
                throw exception;
            }
            catch (Exception ex)
            {
                writer.Trace(TraceLevel.Verbose, "Error!", ex);
            }
            Assert.AreEqual(3, writer.TraceMessages.Count);

            writer.Trace(TraceLevel.Verbose, "Serialized JSON:" + Environment.NewLine + new JArray(1, 2, 3), null);
            Assert.AreEqual(0, writer.TraceMessages.Count);

            IList <JsonTraceMessage> messages = broker.Messages.OfType <JsonTraceMessage>().ToList();

            Assert.AreEqual(3, messages.Count);

            Assert.AreEqual(JsonAction.Serialize, messages[0].Action);
            Assert.AreEqual("Int32", messages[0].Type);
            Assert.AreEqual(null, messages[0].Duration);
            Assert.AreEqual("Started serializing System.Int32.", messages[0].Message);

            Assert.AreEqual(JsonAction.Serialize, messages[1].Action);
            Assert.AreEqual("Int32", messages[1].Type);
            Assert.AreEqual(null, messages[1].Duration);
            Assert.AreEqual("Something something dark side.", messages[1].Message);

            Assert.AreEqual(JsonAction.Serialize, messages[2].Action);
            Assert.AreEqual("Int32", messages[2].Type);
            Assert.AreEqual(TimeSpan.FromSeconds(1), messages[2].Duration);
            Assert.AreEqual("Error!", messages[2].Message);
            Assert.AreEqual(exception, messages[2].Exception);
            Assert.AreEqual(@"[
  1,
  2,
  3
]", messages[2].JsonText);

            IList <JsonTimelineMessage> timelineMessages = broker.Messages.OfType <JsonTimelineMessage>().ToList();

            Assert.AreEqual(1, timelineMessages.Count);
            Assert.AreEqual("Serialize - Int32", timelineMessages[0].EventName);
            Assert.AreEqual(TimeSpan.FromSeconds(1), timelineMessages[0].Duration);
        }
    public void Serialize()
    {
      MockMessageBroker broker = new MockMessageBroker();
      MockExecutionTimer timer = new MockExecutionTimer();

      GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer);
      writer.Trace(TraceLevel.Verbose, "Started serializing System.Int32.", null);
      writer.Trace(TraceLevel.Verbose, "Something something dark side.", null);
      Exception exception = null;
      try
      {
        exception = new Exception("Test exception.");
        throw exception;
      }
      catch (Exception ex)
      {
        writer.Trace(TraceLevel.Verbose, "Error!", ex);
      }
      Assert.AreEqual(3, writer.TraceMessages.Count);

      writer.Trace(TraceLevel.Verbose, "Serialized JSON:" + Environment.NewLine + new JArray(1, 2, 3), null);
      Assert.AreEqual(0, writer.TraceMessages.Count);

      IList<JsonTraceMessage> messages = broker.Messages.OfType<JsonTraceMessage>().ToList();
      Assert.AreEqual(3, messages.Count);

      Assert.AreEqual(JsonAction.Serialize, messages[0].Action);
      Assert.AreEqual("Int32", messages[0].Type);
      Assert.AreEqual(null, messages[0].Duration);
      Assert.AreEqual("Started serializing System.Int32.", messages[0].Message);

      Assert.AreEqual(JsonAction.Serialize, messages[1].Action);
      Assert.AreEqual("Int32", messages[1].Type);
      Assert.AreEqual(null, messages[1].Duration);
      Assert.AreEqual("Something something dark side.", messages[1].Message);

      Assert.AreEqual(JsonAction.Serialize, messages[2].Action);
      Assert.AreEqual("Int32", messages[2].Type);
      Assert.AreEqual(TimeSpan.FromSeconds(1), messages[2].Duration);
      Assert.AreEqual("Error!", messages[2].Message);
      Assert.AreEqual(exception, messages[2].Exception);
      Assert.AreEqual(@"[
  1,
  2,
  3
]", messages[2].JsonText);

      IList<JsonTimelineMessage> timelineMessages = broker.Messages.OfType<JsonTimelineMessage>().ToList();
      Assert.AreEqual(1, timelineMessages.Count);
      Assert.AreEqual("Serialize - Int32", timelineMessages[0].EventName);
      Assert.AreEqual(TimeSpan.FromSeconds(1), timelineMessages[0].Duration);
    }
    public void DeserializeToLinqToJson()
    {
      MockMessageBroker broker = new MockMessageBroker();
      MockExecutionTimer timer = new MockExecutionTimer();

      GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => timer);
      writer.Trace(TraceLevel.Verbose, @"Deserialized JSON:
[1,2,3]", null);

      Assert.AreEqual(1, writer.TraceMessages.Count);

      IList<JsonTraceMessage> messages = broker.Messages.OfType<JsonTraceMessage>().ToList();
      Assert.AreEqual(1, messages.Count);

      Assert.AreEqual(JsonAction.Deserialize, messages[0].Action);
      Assert.AreEqual(null, messages[0].Type);
      Assert.AreEqual(TimeSpan.FromSeconds(1), messages[0].Duration);
      Assert.AreEqual(null, messages[0].Message);
      Assert.AreEqual(@"[1,2,3]", messages[0].JsonText);

      IList<JsonTimelineMessage> timelineMessages = broker.Messages.OfType<JsonTimelineMessage>().ToList();
      Assert.AreEqual(1, timelineMessages.Count);
      Assert.AreEqual("Deserialize", timelineMessages[0].EventName);
    }
    public void TimerStrategyReturnNull()
    {
      MockMessageBroker broker = new MockMessageBroker();

      GlimpseTraceWriter writer = new GlimpseTraceWriter(broker, () => null);
      writer.Trace(TraceLevel.Verbose, "Started serializing System.Int32.", null);
      writer.Trace(TraceLevel.Verbose, "Serialized JSON:" + Environment.NewLine + new JArray(1, 2, 3), null);
      Assert.AreEqual(0, writer.TraceMessages.Count);

      IList<JsonTraceMessage> messages = broker.Messages.OfType<JsonTraceMessage>().ToList();
      Assert.AreEqual(1, messages.Count);

      Assert.AreEqual(JsonAction.Serialize, messages[0].Action);
      Assert.AreEqual("Int32", messages[0].Type);
      Assert.AreEqual(null, messages[0].Duration);
      Assert.AreEqual(@"[
  1,
  2,
  3
]", messages[0].JsonText);

      IList<JsonTimelineMessage> timelineMessages = broker.Messages.OfType<JsonTimelineMessage>().ToList();
      Assert.AreEqual(1, timelineMessages.Count);
      Assert.AreEqual("Serialize - Int32", timelineMessages[0].EventName);
      Assert.AreEqual(TimeSpan.Zero, timelineMessages[0].Duration);
    }