view Implab.Test/UnitTest1.cs @ 257:440801d88019 v3

working on runnable components
author cin
date Fri, 13 Apr 2018 00:43:10 +0300
parents c52691faaf21
children
line wrap: on
line source

using System;
using System.Diagnostics;
using System.Threading;
using Implab.Diagnostics;
using System.Linq;
using Xunit;

namespace Implab.Test {
    using System.Threading.Tasks;
    using static Trace<UnitTest1>;
    public class UnitTest1 {
        [Fact]
        public async Task Test1() {
            var listener = new SimpleTraceListener(Console.Out);
            listener.TraceOutputOptions |= TraceOptions.ThreadId;

            var source = TraceSource;
            source.Switch.Level = SourceLevels.All;

            source.Listeners.Add(listener);

            using (LogicalOperation("Test1")){
                await Task.Yield();
                Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
                await AsyncDummy();
                Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
            }
        }

        async Task AsyncDummy() {
            using(LogicalOperation("OuterDummy"))
            using(LogicalOperation("InnerDummy")) {
                Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
                await Task.Delay(1);
                Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
            }
            Log(String.Join(", ", Trace.CorrelationManager.LogicalOperationStack.Cast<object>().Select(x => x.ToString())));
        }
    }
}