public void TracerRequestsTest(TraceLevel traceLevel, RequestInfo[] requests) { // Mock var path = @"x:\git\trace\trace.xml"; var traceLock = new OperationLockTests.MockOperationLock(); var tracer = new Tracer(path, traceLevel, traceLock); FileSystemHelpers.Instance = GetMockFileSystem(); // Test IntializeTraceFile(path); foreach (var request in requests) { Dictionary <string, string> attribs = new Dictionary <string, string> { { "url", request.Url }, { "statusCode", ((int)request.StatusCode).ToString() }, }; using (tracer.Step("Incoming Request", attribs)) { tracer.Trace("Outgoing response", attribs); } } XDocument document = ReadTraceFile(path); IEnumerable <RequestInfo> traces = document.Root.Elements().Select(e => new RequestInfo { Url = e.Attribute("url").Value }); // Assert Assert.Equal(requests.Where(r => r.Traced), traces, RequestInfoComparer.Instance); }
public void TracerMaxLogEntriesTest() { // Mock var path = @"x:\git\trace\trace.xml"; var traceLock = new OperationLockTests.MockOperationLock(); var threads = 5; var tasks = new List <Task>(threads); var total = 0; FileSystemHelpers.Instance = GetMockFileSystem(); // Test writing 5*50 traces which > 200 limits // also test concurrency and locking with multiple threads for (int i = 0; i < threads; i++) { tasks.Add(Task.Factory.StartNew(() => { var tracer = new Tracer(path, TraceLevel.Verbose, traceLock); for (int j = 0; j < 50; ++j) { tracer.Trace(Guid.NewGuid().ToString(), new Dictionary <string, string>()); Interlocked.Increment(ref total); } })); } Task.WaitAll(tasks.ToArray()); XDocument document = ReadTraceFile(path); // Assert Assert.True(total > Tracer.MaxLogEntries); Assert.Equal(Tracer.MaxLogEntries, document.Root.Elements().Count()); }