comparison Implab.Test/UnitTest1.cs @ 256:c52691faaf21 v3

Removed obsolete App, ComponentContainer Extracted IAsyncComponent interface Working on RunnableComponent
author cin
date Wed, 11 Apr 2018 03:05:14 +0300
parents 34df34841225
children
comparison
equal deleted inserted replaced
255:b00441e04738 256:c52691faaf21
1 using System; 1 using System;
2 using System.Diagnostics; 2 using System.Diagnostics;
3 using System.Threading; 3 using System.Threading;
4 using Implab.Diagnostics; 4 using Implab.Diagnostics;
5 using System.Linq;
5 using Xunit; 6 using Xunit;
6 7
7 namespace Implab.Test { 8 namespace Implab.Test {
8 using System.Threading.Tasks; 9 using System.Threading.Tasks;
9 using static Trace<UnitTest1>; 10 using static Trace<UnitTest1>;
10 public class UnitTest1 { 11 public class UnitTest1 {
11 [Fact] 12 [Fact]
12 public async Task Test1() { 13 public async Task Test1() {
13 var listener = new SimpleTraceListener(Console.Out); 14 var listener = new SimpleTraceListener(Console.Out);
15 listener.TraceOutputOptions |= TraceOptions.ThreadId;
14 16
15 var source = TraceSource; 17 var source = TraceSource;
16 source.Switch.Level = SourceLevels.All; 18 source.Switch.Level = SourceLevels.All;
17 19
18 source.Listeners.Add(listener); 20 source.Listeners.Add(listener);
19 21
20 using (var op = LogicalOperation(nameof(Test1))) 22 using (LogicalOperation("Test1")){
21 using (LogicalOperation("InnerOperation")){
22 await Task.Yield(); 23 await Task.Yield();
23 Log("Inner"); 24 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
24 await Task.Yield(); 25 await AsyncDummy();
25 Log("source event"); 26 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
26 } 27 }
28 }
29
30 async Task AsyncDummy() {
31 using(LogicalOperation("OuterDummy"))
32 using(LogicalOperation("InnerDummy")) {
33 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
34 await Task.Delay(1);
35 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
36 }
37 Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
27 } 38 }
28 } 39 }
29 } 40 }