예제 #1
0
        public void should_use_using_statement_for_simplicity()
        {
            var tracer = new StringBuilder();

            using (var demoDisposable = new DisposableWithTracingDemoClass(tracer))
            {
                // blah, blah, ...
            }

            // change the variable value to fix the test.
            const string expectedTracingMessage = "constructor called.\r\ndispose called.\r\n";

            Assert.Equal(expectedTracingMessage, tracer.ToString());
        }
예제 #2
0
        public void should_use_using_statement_for_simplicity()
        {
            var tracerContent = "nothing";

            using (var demoDisposable = new DisposableWithTracingDemoClass())
            {
                tracerContent = demoDisposable.TracerContent();
            }

            // change the variable value to fix the test.
            const string expectedTracingMessage = "";

            Assert.Equal(expectedTracingMessage, tracerContent);
        }
예제 #3
0
        public void should_call_dispose_anyway_using_try_finally()
        {
            var tracer = new StringBuilder();
            DisposableWithTracingDemoClass demoDisposable = null;

            try
            {
                demoDisposable = new DisposableWithTracingDemoClass(tracer);
            }
            finally
            {
                demoDisposable?.Dispose();
            }

            // change variable value to fix test.
            const string expectedTracingMessage = "constructor called.\r\ndispose called.\r\n";

            Assert.Equal(expectedTracingMessage, tracer.ToString());
        }
예제 #4
0
        public void should_call_dispose_anyway_using_try_finally()
        {
            DisposableWithTracingDemoClass demoDisposable = null;

            try
            {
                demoDisposable = new DisposableWithTracingDemoClass();
            }
            finally
            {
                if (demoDisposable != null)
                {
                    demoDisposable.Dispose();
                }
            }

            // change variable value to fix test.
            const string expectedTracingMessage = "";

            Assert.Equal(expectedTracingMessage, demoDisposable.TracerContent());
        }
예제 #5
0
        public void should_call_dispose_anyway_using_try_finally()
        {
            var tracer = new StringBuilder();
            DisposableWithTracingDemoClass demoDisposable = null;

            try
            {
                demoDisposable = new DisposableWithTracingDemoClass(tracer);
            }
            finally
            {
                if (demoDisposable != null)
                {
                    demoDisposable.Dispose();
                }
            }

            // change variable value to fix test.
            string expectedTracingMessage = "constructor called." + Environment.NewLine + "dispose called." + Environment.NewLine;

            Assert.Equal(expectedTracingMessage, tracer.ToString());
        }