Ejemplo n.º 1
0
        public void result_for_two_tasks_is_correct()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <int>();
            var task1   = 1;
            var task2   = 2;

            // Act
            monitor.StartTask(task1);
            Thread.Sleep(20);
            monitor.StopTask(task1);

            Thread.Sleep(10);

            monitor.StartTask(task2);
            Thread.Sleep(20);
            monitor.StopTask(task2);
            Thread.Sleep(10);

            // Assert
            var result = monitor.GetResult();

            Assert.That(result[task1].Duration.TotalMilliseconds, Is.InRange(18, 22));
            Assert.That(result[task2].Duration.TotalMilliseconds, Is.InRange(18, 22));
        }
Ejemplo n.º 2
0
        public void can_start_same_task_twice()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);

            // Assert
            monitor.StartTask(task);
        }
Ejemplo n.º 3
0
        private FlatPerformanceMonitor <string> Execute()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <string>();
            var task1   = "task1";
            var task2   = "task2";

            // Act
            monitor.StartTask(task1);
            monitor.StartTask(task2);
            Thread.Sleep(20);
            monitor.StopTask(task1);
            monitor.StopTask(task2);

            return(monitor);
        }
Ejemplo n.º 4
0
        public void stopping_stopped_task_does_not_fail()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            monitor.StopTask(task);

            // Assert
            monitor.StopTask(task);
        }
Ejemplo n.º 5
0
        public void result_for_task_started_twice_is_correct()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            Thread.Sleep(20);
            monitor.StopTask(task);

            Thread.Sleep(10);

            monitor.StartTask(task);
            Thread.Sleep(20);
            monitor.StopTask(task);
            Thread.Sleep(10);

            // Assert
            var result = monitor.GetResult();

            Assert.That(result[task].Duration.TotalMilliseconds, Is.InRange(38, 42));
        }
Ejemplo n.º 6
0
        public void result_contains_started_task()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            var result = monitor.GetResult();

            // Assert
            Assert.AreEqual(1, result.Count);
            Assert.True(result.ContainsKey(task));
        }
Ejemplo n.º 7
0
        public void started_task_is_monitored()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            Thread.Sleep(10);

            // Assert
            var result = monitor.GetResult();

            Assert.Greater(result[task].Duration.Ticks, 0);
        }
Ejemplo n.º 8
0
        public void result_contains_started_tasks()
        {
            // Arrange
            var monitor = new FlatPerformanceMonitor <int>();
            var tasks   = new[] { 1, 2, 3 };

            // Act
            foreach (var task in tasks)
            {
                monitor.StartTask(task);
            }

            var result = monitor.GetResult();

            // Assert
            Assert.AreEqual(3, result.Count);

            foreach (var task in tasks)
            {
                Assert.True(result.ContainsKey(task));
            }
        }