public void LogOccurrenceSessionNull()
        {
            var perf = this.Occurrence();

            perf.SessionIdentifier = null;
            using (var client = new DatumClient())
            {
                client.LogPerformance(perf);
            }

            var source = new Server.Core.LogCore();
            var query  = new Server.Contracts.LogQuery()
            {
                ApplicationIdentifier = Settings.ApplicationIdentifier,
            };

            var occurance = (from data in source.SelectOccurrences(query)
                             where perf.Message == data.Message
                             select data).FirstOrDefault();

            Assert.IsNotNull(occurance, "Occurrence should not be null");
            Assert.AreEqual <Guid>(perf.Token.ApplicationId, occurance.Token.ApplicationId, "Application Id should match");
            Assert.AreEqual <DateTime>(perf.OccurredOn.Date, occurance.OccurredOn.Date, "Occurred On should match");
            Assert.AreEqual <string>(perf.MachineName, occurance.MachineName, "Machine Name should match");
            Assert.AreEqual <string>(perf.Message, occurance.Message, "Message should match");
            Assert.AreEqual <string>(perf.Class, occurance.Class, "Type should match");
            Assert.AreEqual <TimeSpan>(perf.Duration, occurance.Duration, "Duration should match");
            Assert.AreEqual <string>(perf.Method, occurance.Method, "Method should match");
            Assert.AreEqual <int>(perf.ThreadId, occurance.ThreadId, "Thread Id should match");
            Assert.AreEqual <Guid?>(perf.SessionIdentifier, occurance.SessionIdentifier, "Session Identifier should match");
        }
        public void DurationTooSmall()
        {
            var message = Guid.NewGuid().ToString();

            using (var perf = new PerformanceMonitor())
            {
                Assert.IsNull(perf.Content, "Content should be null");
                perf.Append(message);
                Assert.AreEqual <string>(message, perf.Content, "Message should match");
            }

            var source = new Abc.Services.Core.LogCore();
            var query  = new Abc.Services.Contracts.LogQuery()
            {
                ApplicationIdentifier = Application.Identifier,
            };
            var items = source.SelectOccurrences(query);

            foreach (var item in items)
            {
                if (item.Message == message)
                {
                    Assert.Fail("Perf occurance was saved.");
                }
            }
        }
        public void LogMessage()
        {
            var msg   = this.Message();
            var query = new Server.Contracts.LogQuery()
            {
                ApplicationIdentifier = msg.Token.ApplicationId,
            };

            using (var client = new DatumClient())
            {
                client.LogMessage(msg);
            }

            var source = new Server.Core.LogCore();
            int i      = 0;

            Abc.Services.Contracts.MessageDisplay message = null;
            while (message == null && i < 50)
            {
                Thread.Sleep(10);
                message = (from data in source.SelectMessages(query)
                           where msg.Message == data.Message
                           select data).FirstOrDefault();
                i++;
            }
            Assert.IsNotNull(message, "Message should not be null");
            Assert.AreEqual <Guid>(msg.Token.ApplicationId, message.Token.ApplicationId, "Application Id should match");
            Assert.AreEqual <DateTime>(msg.OccurredOn.Date, message.OccurredOn.Date, "Occured On should match");
            Assert.AreEqual <string>(msg.MachineName, message.MachineName, "Machine Name should match");
            Assert.AreEqual <string>(msg.Message, message.Message, "Message should match");
        }
        public Abc.Services.Contracts.Message GetMessage(string text)
        {
            var source = new LogCore();

            Abc.Services.Contracts.Message message = null;
            int i = 0;

            while (i < 100 && null == message)
            {
                var query = new Abc.Services.Contracts.LogQuery()
                {
                    ApplicationIdentifier = Application.Identifier,
                };
                var messages = source.SelectMessages(query);
                if (null != messages)
                {
                    message = (from data in messages
                               where text == data.Message
                               select data).FirstOrDefault();
                }

                i++;
                Thread.Sleep(75);
            }

            return(message);
        }
        public void LogErrorWithParents()
        {
            var err     = this.Error();
            var parentA = this.Error();

            parentA.Token.ApplicationId = err.Token.ApplicationId;
            var parentB = this.Error();

            parentB.Token.ApplicationId = err.Token.ApplicationId;
            err.Parent     = parentA;
            parentA.Parent = parentB;
            using (var client = new DatumClient())
            {
                client.LogException(err);
            }

            var source = new Server.Core.LogCore();
            var query  = new Server.Contracts.LogQuery()
            {
                ApplicationIdentifier = err.Token.ApplicationId,
            };
            var errors = source.SelectErrors(query);

            Assert.IsNotNull(errors, "Errors should not be null");
            ErrorItem data;

            foreach (var error in errors)
            {
                if (error.Message == err.Message)
                {
                    data = err;
                }
                else if (error.Message == parentB.Message)
                {
                    data = parentB;
                }
                else if (error.Message == parentA.Message)
                {
                    data = parentA;
                }
                else
                {
                    continue;
                }

                Assert.IsNotNull(error, "Error should not be null");
                Assert.AreEqual <Guid>(data.Token.ApplicationId, error.Token.ApplicationId, "Application Id should match");
                Assert.AreEqual <string>(data.MachineName, error.MachineName, "Machine Name should match");
                Assert.AreEqual <string>(data.Message, error.Message, "Message should match");
                Assert.AreEqual <string>(data.ClassName, error.ClassName, "Type should match");
                Assert.AreEqual <int>(data.ErrorCode, error.ErrorCode, "Error Code should match");
                Assert.AreEqual <DateTime>(data.OccurredOn.Date, error.OccurredOn.Date, "Occured On should match");
            }
        }
Beispiel #6
0
        public void LogOccurrence()
        {
            var operationName = Guid.NewGuid().ToString();
            var perf          = new WcfPerformanceMonitor(typeof(WcfPerformanceMonitorTest));

            perf.BeforeCall(null, null);

            Thread.Sleep(3000);

            perf.AfterCall(operationName, null, null, null);

            Thread.Sleep(3000);

            operationName = ' ' + operationName;

            var source = new Abc.Services.Core.LogCore();
            var query  = new Abc.Services.Contracts.LogQuery()
            {
                ApplicationIdentifier = Settings.ApplicationIdentifier,
            };

            var className = typeof(WcfPerformanceMonitorTest).ToString();
            int i         = 0;

            Abc.Services.Contracts.OccurrenceDisplay occurance = null;
            while (occurance == null && i < 50)
            {
                Thread.Sleep(50);
                occurance = (from data in source.SelectOccurrences(query)
                             where data.Class == className &&
                             data.Method == operationName
                             select data).FirstOrDefault();
                i++;
            }

            Assert.IsNotNull(occurance, "Occurance should not be null");
            Assert.AreEqual <Guid>(Settings.ApplicationIdentifier, occurance.Token.ApplicationId, "Application Id should match");
            Assert.AreEqual <string>(Environment.MachineName, occurance.MachineName, "Machine Name should match");
            Assert.AreEqual <string>(operationName, occurance.Method, "Method should match");
            Assert.AreEqual <string>(this.GetType().ToString(), occurance.Class, "Type should match");
            Assert.AreEqual <int>(Thread.CurrentThread.ManagedThreadId, occurance.ThreadId, "Thread Id should match");
        }
        public void WriteLineInvalidMessage()
        {
            this.CleanUp();

            var now = DateTime.UtcNow;

            Trace.WriteLine(StringHelper.NullEmptyWhiteSpace());

            Trace.Flush();

            var source = new LogCore();
            var query  = new Abc.Services.Contracts.LogQuery()
            {
                ApplicationIdentifier = Application.Identifier,
                From = now,
            };
            var messages = source.SelectMessages(query);

            Assert.IsNotNull(messages, "Messages should not be null");
            Assert.AreEqual <int>(0, messages.Count());
        }
        public void WriteObjectNull()
        {
            this.CleanUp();

            var now = DateTime.UtcNow;

            Trace.Write((object)null);

            Trace.Flush();

            var source = new LogCore();
            var query  = new Abc.Services.Contracts.LogQuery()
            {
                ApplicationIdentifier = Settings.ApplicationIdentifier,
                From = now,
            };
            var messages = source.SelectMessages(query);

            Assert.IsNotNull(messages, "Messages should not be null");
            Assert.AreEqual <int>(0, messages.Count());
        }
Beispiel #9
0
        public void DurationTooSmall()
        {
            var operationName = Guid.NewGuid().ToString();
            var perf          = new WcfPerformanceMonitor(typeof(WcfPerformanceMonitorTest));

            perf.BeforeCall(null, null);
            perf.AfterCall(operationName, null, null, null);

            var source = new Abc.Services.Core.LogCore();
            var query  = new Abc.Services.Contracts.LogQuery()
            {
                ApplicationIdentifier = Settings.ApplicationIdentifier,
            };

            var className = typeof(WcfPerformanceMonitorTest).ToString();
            var item      = (from data in source.SelectOccurrences(query)
                             where data.Class == className &&
                             data.Method == operationName
                             select data).FirstOrDefault();

            Assert.IsNull(item);
        }
        public void LogOccurrence()
        {
            var message = Guid.NewGuid().ToString();

            using (var perf = new PerformanceMonitor())
            {
                Assert.IsNull(perf.Content, "Content should be null");
                Thread.Sleep(perf.MinimumDuration.Add(new TimeSpan(0, 0, 2)));
                perf.Append(message);
            }

            var source = new Abc.Services.Core.LogCore();
            var query  = new Abc.Services.Contracts.LogQuery()
            {
                ApplicationIdentifier = Settings.ApplicationIdentifier,
                From = DateTime.UtcNow.AddMinutes(-5),
            };

            int i = 0;

            Abc.Services.Contracts.OccurrenceDisplay occurance = null;
            while (occurance == null && i < 50)
            {
                Thread.Sleep(100);
                occurance = (from data in source.SelectOccurrences(query)
                             where message == data.Message
                             select data).FirstOrDefault();
                i++;
            }

            Assert.IsNotNull(occurance, "Occurrence should not be null");
            Assert.AreEqual <Guid>(Application.Identifier, occurance.Token.ApplicationId, "Application Id should match");
            Assert.AreEqual <string>(Environment.MachineName, occurance.MachineName, "Machine Name should match");
            Assert.AreEqual <string>(message, occurance.Message, "Message should match");
            Assert.AreEqual <string>("Void LogOccurrence()", occurance.Method, "Method should match");
            Assert.AreEqual <string>(this.GetType().ToString(), occurance.Class, "Type should match");
            Assert.AreEqual <int>(Thread.CurrentThread.ManagedThreadId, occurance.ThreadId, "Thread Id should match");
        }