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 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."); } } }
/// <summary> /// Delete Tesing Data /// </summary> private static void DeleteData() { var token = new Abc.Services.Contracts.Token() { ApplicationId = Settings.ApplicationIdentifier, }; var source = new Abc.Services.Core.LogCore(); var perf = new Abc.Services.Contracts.Occurrence() { Token = token, OccurredOn = DateTime.UtcNow.AddDays(-1), }; source.Delete(perf); var err = new Abc.Services.Contracts.ErrorItem() { Token = token, OccurredOn = DateTime.UtcNow.AddDays(-1), }; source.Delete(err); var msg = new Abc.Services.Contracts.Message() { Token = token, OccurredOn = DateTime.UtcNow.AddDays(-1), }; source.Delete(msg); }
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"); } }
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 Initialize() { try { var token = new Abc.Services.Contracts.Token() { ApplicationId = Settings.ApplicationIdentifier, }; var perf = new Abc.Services.Contracts.Occurrence() { Token = token, OccurredOn = DateTime.UtcNow, }; var source = new Abc.Services.Core.LogCore(); source.Delete(perf); } catch { } }
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"); }