Exemplo n.º 1
0
        public void TestLogEntryException_AspectOnMethod()
        {
            const string expectedName = "PubComp.Aspects.Monitoring.UnitTests.MonitorMocks.MonitoredMock.ThrowSomething()";

            var target = new MonitoredMock();

            bool caughtException = false;

            try
            {
                target.ThrowSomething();
            }
            catch (ApplicationException)
            {
                caughtException = true;
            }

            Assert.IsTrue(caughtException);

            var stats = MonitorAttribute.GetStatistics(expectedName);

            Assert.AreEqual(1, stats.Entries);
            Assert.AreEqual(1, stats.Exits);
            Assert.AreEqual(1, stats.Failures);
        }
Exemplo n.º 2
0
        public void TestLogEntryExit_AspectOnMethod()
        {
            const string expectedName = "PubComp.Aspects.Monitoring.UnitTests.MonitorMocks.MonitoredMock.Long()";

            var target = new MonitoredMock();

            target.Long();

            var names = MonitorAttribute.GetMonitorNames();

            Assert.IsTrue(names.Contains(expectedName));

            var stats = MonitorAttribute.GetStatistics(expectedName);

            Assert.AreEqual(1, stats.Entries);
            Assert.AreEqual(1, stats.Exits);
            Assert.AreEqual(0, stats.Failures);
            Assert.IsTrue(stats.AverageDuration >= 90.0);
            Assert.IsTrue(stats.TotalDuration >= 90.0);
            Assert.IsTrue(stats.LastDuration >= 90.0);

            target.Long();

            stats = MonitorAttribute.GetStatistics(expectedName);

            Assert.AreEqual(2, stats.Entries);
            Assert.AreEqual(2, stats.Exits);
            Assert.AreEqual(0, stats.Failures);
            Assert.IsTrue(stats.AverageDuration >= 90.0);
            Assert.IsTrue(stats.TotalDuration >= 180.0);
            Assert.IsTrue(stats.LastDuration >= 90.0);
        }