GetTraceMessages() публичный Метод

Returns an enumeration of the most recent trace messages.
public GetTraceMessages ( ) : IEnumerable
Результат IEnumerable
    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);
    }
Пример #2
0
        public void Example()
        {
            #region Usage
            string json = @"{
              'FullName': 'Dan Deleted',
              'Deleted': true,
              'DeletedDate': '2013-01-20T00:00:00'
            }";

            MemoryTraceWriter traceWriter = new MemoryTraceWriter();

            Account account = JsonConvert.DeserializeObject<Account>(json, new JsonSerializerSettings
            {
                TraceWriter = traceWriter
            });

            Console.WriteLine(traceWriter.ToString());
            // 2013-01-21T01:36:24.422 Info Started deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'FullName', line 2, position 20.
            // 2013-01-21T01:36:24.442 Verbose Could not find member 'DeletedDate' on Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path 'DeletedDate', line 4, position 23.
            // 2013-01-21T01:36:24.447 Info Finished deserializing Newtonsoft.Json.Tests.Documentation.Examples.TraceWriter+Account. Path '', line 5, position 8.
            // 2013-01-21T01:36:24.450 Verbose Deserialized JSON: 
            // {
            //   "FullName": "Dan Deleted",
            //   "Deleted": true,
            //   "DeletedDate": "2013-01-20T00:00:00"
            // }
            #endregion

            Assert.AreEqual(4, traceWriter.GetTraceMessages().Count());
        }
Пример #3
0
        public void MemoryTraceWriterLimitTest()
        {
            MemoryTraceWriter traceWriter = new MemoryTraceWriter();

            for (int i = 0; i < 1005; i++)
            {
                traceWriter.Trace(TraceLevel.Verbose, (i + 1).ToString(CultureInfo.InvariantCulture), null);
            }

            IList<string> traceMessages = traceWriter.GetTraceMessages().ToList();

            Assert.AreEqual(1000, traceMessages.Count);

            Assert.IsTrue(traceMessages.First().EndsWith(" 6"));
            Assert.IsTrue(traceMessages.Last().EndsWith(" 1005"));
        }
        public void ShouldDeserialize_False()
        {
            string json = @"{'HasName':false,'Name':'Name!'}";

            MemoryTraceWriter traceWriter = new MemoryTraceWriter();
            ShouldDeserializeTestClass c = JsonConvert.DeserializeObject<ShouldDeserializeTestClass>(json, new JsonSerializerSettings
            {
                ContractResolver = ShouldDeserializeContractResolver.Instance,
                TraceWriter = traceWriter
            });

            Assert.AreEqual(1, c.ExtensionData.Count);
            Assert.AreEqual("Name!", (string)c.ExtensionData["Name"]);
            Assert.AreEqual(false, c.HasName);
            Assert.AreEqual(null, c.Name);

            Assert.IsTrue(traceWriter.GetTraceMessages().Any(m => m.EndsWith("Verbose ShouldDeserialize result for property 'Name' on Newtonsoft.Json.Tests.Serialization.ShouldDeserializeTestClass: False. Path 'Name'.")));
        }
Пример #5
0
 private JobLogEntry ParseEntry(string line)
 {
     var writer = new MemoryTraceWriter();
     var old = _serializerSettings.TraceWriter;
     _serializerSettings.TraceWriter = writer;
     var result = JsonConvert.DeserializeObject<JobLogEntry>(line.Trim(), _serializerSettings);
     _serializerSettings.TraceWriter = old;
     foreach (var message in writer.GetTraceMessages())
     {
         Console.WriteLine(message);
     }
     return result;
 }