public async Task TestMultipleThreads()
        {
            // This validates a bug where writing from multiple threads throws an exception.
            TestTraceWriter trace   = new TestTraceWriter(TraceLevel.Verbose);
            TextWriter      adapter = TextWriterTraceAdapter.Synchronized(trace);

            // Start Tasks to write
            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 1000; i++)
            {
                tasks.Add(adapter.WriteLineAsync(string.Empty));
            }

            await Task.WhenAll(tasks);

            Assert.Equal(1000, trace.Traces.Count);
        }
        public async Task TestMultipleThreads()
        {
            // This validates a bug where writing from multiple threads throws an exception.
            List <TraceEvent> traces = new List <TraceEvent>();

            _mockTraceWriter
            .Setup(p => p.Trace(It.IsAny <TraceEvent>()))
            .Callback <TraceEvent>((e) => traces.Add(e));

            TextWriter adapter = TextWriterTraceAdapter.Synchronized(_mockTraceWriter.Object);

            // Start Tasks to write
            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 1000; i++)
            {
                tasks.Add(adapter.WriteLineAsync(string.Empty));
            }

            await Task.WhenAll(tasks);

            Assert.Equal(1000, traces.Count);
        }
 public TextWriterTraceAdapterTests()
 {
     _mockTraceWriter = new Mock <TraceWriter>(MockBehavior.Strict, TraceLevel.Verbose);
     _adapter         = TextWriterTraceAdapter.Synchronized(_mockTraceWriter.Object);
 }