Esempio n. 1
0
        public void Test03()
        {
            string msg1, msg2;
            string name;
            string fileName = string.Format("{0}_5.txt", this.GetType().Name);

            CommonUtilities.DeleteFile(fileName);

            try
            {
                FileStream   stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                StreamWriter writer = new StreamWriter(stream);
                name = "AnyName";

                _delimitedListener = new DelimitedListTraceListener(writer, name);
                Assert.True(_delimitedListener.Delimiter == ";");
                Assert.True(_delimitedListener.Name == name);
                Assert.True(_delimitedListener.Writer == writer);

                msg1 = "Msg1";
                _delimitedListener.WriteLine(msg1);
                _delimitedListener.Delimiter = ",";
                msg2 = "Msg2";
                _delimitedListener.WriteLine(msg2);
                _delimitedListener.Flush();
                _delimitedListener.Dispose();

                name = "";
                _delimitedListener.Name = name;
                Assert.True(_delimitedListener.Name == name);

                Assert.True(_delimitedListener.Delimiter == ",");
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg2));
            }
            finally
            {
                CommonUtilities.DeleteFile(fileName);
            }
        }
Esempio n. 2
0
        public void AttributeDelimiter_IgnoredAfterDelimiterSet_Test(string delimiter, TraceFilter filter, TraceEventCache eventCache, string source, TraceEventType eventType, int id, object[] data)
        {
            string newDelimiter = "||";

            using (var target = GetListener())
            {
                target.Filter             = filter;
                target.TraceOutputOptions = TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.DateTime | TraceOptions.Timestamp | TraceOptions.LogicalOperationStack | TraceOptions.Callstack;

                // Setting target.Delimiter here should initialize the delimiter
                // so that future delimiter attributes aren't used.
                target.Delimiter = delimiter;

                target.Attributes.Add("delimiter", newDelimiter);
                target.TraceData(eventCache, source, eventType, id, data);
                Assert.Equal(delimiter, target.Delimiter);
            }

            string expected = CommonUtilities.ExpectedTraceDataOutput(delimiter, filter, eventCache, source, eventType, id, data);

            Assert.Equal(expected, File.Exists(_fileName) ? File.ReadAllText(_fileName) : "");
        }
Esempio n. 3
0
        public void Test04()
        {
            string msg1, msg2, msg3;
            string fileName = string.Format("{0}_7.txt", this.GetType().Name);

            try
            {
                CommonUtilities.DeleteFile(fileName);

                FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);

                _delimitedListener = new DelimitedListTraceListener(stream);
                Assert.True(_delimitedListener.Delimiter == ";");
                Assert.True(_delimitedListener.Name == "");

                msg1 = "Msg1";
                _delimitedListener.WriteLine(msg1);
                _delimitedListener.Delimiter = ",";
                msg2 = "Msg2";
                _delimitedListener.WriteLine(msg2);

                _delimitedListener.Delimiter = ",,,,";
                msg3 = "Msg3";
                _delimitedListener.WriteLine(msg3);
                Assert.True(_delimitedListener.Delimiter == ",,,,");

                _delimitedListener.Flush();
                _delimitedListener.Dispose();

                Assert.True(_delimitedListener.Delimiter == ",,,,", "Error! Delimiter wrong");
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg2));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg3));
            }
            finally
            {
                CommonUtilities.DeleteFile(fileName);
            }
        }
Esempio n. 4
0
        public void Test02()
        {
            try
            {
                //Testing ctor(Stream)
                //[] Vanilla - pass a valid stream. Also check via FileName return the expected value
                string msg1;
                _fileName = string.Format("{0}_2.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(_fileName);

                _stream     = new FileStream(_fileName, FileMode.OpenOrCreate, FileAccess.Write);
                _textWriter = new TextWriterTraceListener(_stream);
                msg1        = "HelloWorld";
                _textWriter.WriteLine(msg1);
                _textWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(TextWriterTraceListener) }, new string[] { _fileName }, msg1));
            }
            finally
            {
                CommonUtilities.DeleteFile(_fileName);
            }
        }
Esempio n. 5
0
        public void Test05()
        {
            string fileName = string.Format("{0}_8.txt", this.GetType().Name);

            try
            {
                CommonUtilities.DeleteFile(fileName);
                FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                _delimitedListener = new DelimitedListTraceListener(stream);
                Assert.True(_delimitedListener.Delimiter == ";");
                Assert.True(_delimitedListener.Name == "");

                _delimitedListener.Delimiter = "";
                _delimitedListener.Dispose();
            }
            catch (ArgumentException)
            {
                _delimitedListener.Dispose();
            }
            finally
            {
                CommonUtilities.DeleteFile(fileName);
            }
        }
Esempio n. 6
0
 public TextWriterTraceListener_WriteTestsCtorStream()
 {
     CommonUtilities.DeleteFile(_fileName);
     _stream = new FileStream(_fileName, FileMode.OpenOrCreate, FileAccess.Write);
 }
Esempio n. 7
0
 public TextWriterTraceListener_WriteTestsCtorFileName()
 {
     CommonUtilities.DeleteFile(_fileName);
 }
Esempio n. 8
0
        public void RunTest()
        {
            DelimitedListTraceListener delimitedWriter;
            string          fileName, msg1, msg2, msg3, format, source;
            TraceEventCache eventCache;
            TraceEventType  severity;
            int             id;

            object[]     args, data;
            FileStream   stream;
            StreamWriter writer;

            try
            {
                //Scenario 1: TraceEvent (TraceEventCache eventCache, string source, TraceEventType severity, int id, string format, params object[] args)
                fileName = string.Format("{0}_1.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                eventCache = null;
                source     = "Co1971";
                severity   = TraceEventType.Information;
                id         = 1000;
                format     = "This is an object of type string:{0} and this is of type int: {1}";
                args       = new Object[] { "Hello", 6 };
                msg1       = string.Format(format, args);
                delimitedWriter.TraceEvent(eventCache, source, severity, id, format, args);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));

                CommonUtilities.DeleteFile(fileName);

                //Scenario 2: TraceEvent(TraceEventCache eventCache, string source, TraceEventType severity, int id, string message)

                fileName = string.Format("{0}_2.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                eventCache = null;
                source     = "Co1971";
                severity   = TraceEventType.Information;
                id         = 1000;
                msg1       = "Hello World";
                delimitedWriter.TraceEvent(eventCache, source, severity, id, msg1);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 3: TraceData(TraceEventCache eventCache, string source, TraceEventType severity, int id, object data)

                fileName = string.Format("{0}_3.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);
                object data1;
                eventCache = null;
                source     = "Co1971";
                severity   = TraceEventType.Information;
                id         = 1000;
                data1      = Decimal.MaxValue;
                delimitedWriter.TraceData(eventCache, source, severity, id, data1);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data1.ToString()));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 4: TraceData(TraceEventCache eventCache, string source, TraceEventType severity, int id, params object[] data)

                fileName = string.Format("{0}_4.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                eventCache = null;
                source     = "Co1971";
                severity   = TraceEventType.Information;
                id         = 1000;
                data       = new Object[] { Decimal.MaxValue, Int64.MinValue, Int32.MaxValue, "Hello" };
                msg1       = string.Format("{0}{1}{2}{3}", data);
                delimitedWriter.TraceData(eventCache, source, severity, id, data);
                delimitedWriter.Dispose();


                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, source));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, severity.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, id.ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[0].ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[1].ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[2].ToString()));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, data[3].ToString()));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 5: Write(string message)

                fileName = string.Format("{0}_5.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                msg1 = "Hello World";
                delimitedWriter.Write(msg1);
                delimitedWriter.Dispose();
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 6: WriteLine(string message)
                fileName = string.Format("{0}_6.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                msg1 = "Hello World";
                delimitedWriter.WriteLine(msg1);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 7: some TraceListener methods that are not overridden
                fileName = string.Format("{0}_7.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);
                msg1            = "Msg1";
                msg2            = "Msg2";
                delimitedWriter.Fail(msg1, msg2);
                msg3 = "Hello World";
                delimitedWriter.Fail(msg3);
                delimitedWriter.Dispose();

                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg2));
                Assert.True(CommonUtilities.TestListenerContent(new Type[] { typeof(DelimitedListTraceListener) }, new string[] { fileName }, msg1));
                CommonUtilities.DeleteFile(fileName);

                //Scenario 8: some TraceListener properties that are not overridden
                fileName = string.Format("{0}_8.xml", this.GetType().Name);
                CommonUtilities.DeleteFile(fileName);
                stream          = new FileStream(fileName, FileMode.Create, FileAccess.Write);
                writer          = new StreamWriter(stream);
                delimitedWriter = new DelimitedListTraceListener(writer);

                Assert.True(delimitedWriter.Filter == null);
                Assert.True(delimitedWriter.IndentLevel == 0);
                Assert.True(delimitedWriter.IndentSize == 4);
                Assert.True(delimitedWriter.Name == string.Empty);
                Assert.True(delimitedWriter.TraceOutputOptions == TraceOptions.None);
                delimitedWriter.Dispose();
                CommonUtilities.DeleteFile(fileName);
            }
            finally
            {
                for (int i = 1; i <= 8; i++)
                {
                    fileName = string.Format("{0}_{1}.xml", this.GetType().Name, i);
                    CommonUtilities.DeleteFile(fileName);
                }
            }
        }
 public DelimiterWriteMethodTestsCtorStream()
 {
     CommonUtilities.DeleteFile(_fileName);
     _stream = new FileStream(_fileName, FileMode.OpenOrCreate, FileAccess.Write);
 }
 public DelimiterWriteMethodTestsCtorFileName()
 {
     CommonUtilities.DeleteFile(_fileName);
 }
 public void Dispose()
 {
     _stream.Dispose();
     CommonUtilities.DeleteFile(_fileName);
 }
 public DelimiterWriteMethodTests()
 {
     _fileName = string.Format("{0}.xml", GetType().Name);
     CommonUtilities.DeleteFile(_fileName);
     _stream = new FileStream(_fileName, FileMode.OpenOrCreate, FileAccess.Write);
 }
Esempio n. 13
0
 public TextWriterTraceListener_WriteTests()
 {
     _fileName = $"{GetTestFilePath()}.xml";
     CommonUtilities.DeleteFile(_fileName);
     _stream = new FileStream(_fileName, FileMode.OpenOrCreate, FileAccess.Write);
 }
Esempio n. 14
0
 public TextWriterTraceListener_WriteTests()
 {
     _fileName = string.Format("{0}.xml", GetType().Name);
     CommonUtilities.DeleteFile(_fileName);
     _stream = new FileStream(_fileName, FileMode.OpenOrCreate, FileAccess.Write);
 }
Esempio n. 15
0
 public DelimiterWriteMethodTests()
 {
     _fileName = $"{GetTestFilePath()}.xml";
     CommonUtilities.DeleteFile(_fileName);
     _stream = new FileStream(_fileName, FileMode.OpenOrCreate, FileAccess.Write);
 }