Example #1
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");
        }
Example #2
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);
        }