Пример #1
0
        public void TestLogSynchronizationContextThroughWrites()
        {
            using (var ctx = new TestSingleThreadSynchronizationContext()) {
                int offset;

                using (var mon = new ChainedProgressMonitor(ctx)) {
                    // These call once into Write.
                    mon.Log.Write("a");
                    Assert.AreEqual(1, ctx.CallCount);

                    mon.Log.Write('a');
                    Assert.AreEqual(2, ctx.CallCount);

                    mon.Log.Write(new [] { 'a' }, 0, 1);
                    Assert.AreEqual(3, ctx.CallCount);

                    offset = 3;

                    // This calls twice into Write in newer versions of the BCL,
                    //  and once in older versions.
                    mon.Log.WriteLine("a");
                    Assert.IsTrue(ctx.CallCount - offset <= 2, "WriteLine should produce 1-2 calls");
                    offset = ctx.CallCount;

                    // These 2 call twice into Write.
                    mon.Log.WriteLine('a');
                    Assert.AreEqual(2, ctx.CallCount - offset);
                    offset = ctx.CallCount;

                    mon.Log.WriteLine(new [] { 'a' }, 0, 1);
                    Assert.AreEqual(2, ctx.CallCount - offset);
                    offset = ctx.CallCount;

                    // Flush performs one call
                    mon.Log.Flush();
                    Assert.AreEqual(1, ctx.CallCount - offset);
                    offset = ctx.CallCount;
                }

                // Once for completed, once for Dispose.
                Assert.AreEqual(2, ctx.CallCount - offset);
            }
        }
Пример #2
0
        public void TestLogSynchronizationContextThroughWrites()
        {
            using (var ctx = new TestSingleThreadSynchronizationContext()) {
                using (var mon = new ChainedProgressMonitor(ctx)) {
                    // These call once into Write.
                    mon.Log.Write("a");
                    mon.Log.Write('a');
                    mon.Log.Write(new [] { 'a' }, 0, 1);
                    mon.Log.WriteLine("a");

                    // These 2 call twice into Write.
                    mon.Log.WriteLine('a');
                    mon.Log.WriteLine(new [] { 'a' }, 0, 1);

                    Assert.AreEqual(8, ctx.CallCount);

                    mon.Log.Flush();
                    Assert.AreEqual(9, ctx.CallCount);
                }
                // Once for completed, Dispose needs API break to be done on the right context.
                Assert.AreEqual(10, ctx.CallCount);
            }
        }