예제 #1
0
        public void Run_ShouldFailAfterBeingDisposed()
        {
            var runner = new PmlTestRunner(Mock.Of <ObjectProxy>(), Mock.Of <MethodInvoker>(), Mock.Of <Clock>());

            runner.Dispose();
            Assert.Throws <ObjectDisposedException>(() => runner.Run(TestCase));
            Assert.Throws <ObjectDisposedException>(() => runner.Run(Test));
        }
예제 #2
0
        public void Run_ShouldReturnPassedResultWhenTestPasses()
        {
            var runner = new PmlTestRunner(Mock.Of <ObjectProxy>(), Mock.Of <MethodInvoker>());
            var result = runner.Run(Test);

            Assert.IsTrue(result.Passed);
        }
예제 #3
0
        public void Run_ShouldQueryTheClock()
        {
            var clock  = new Mock <Clock>();
            var runner = new PmlTestRunner(Mock.Of <ObjectProxy>(), Mock.Of <MethodInvoker>(), clock.Object);

            runner.Run(Test);
            clock.VerifyGet(mock => mock.CurrentInstant, Times.Exactly(2));
        }
예제 #4
0
        public void Run_ShouldAssignTestResultToAllTestsInTheTestCase()
        {
            TestCase.Tests.Add("two");
            TestCase.Tests.Add("three");

            var runner = new PmlTestRunner(Mock.Of <ObjectProxy>(), Mock.Of <MethodInvoker>());

            runner.Run(TestCase);

            Assert.NotNull(TestCase.Tests["one"].Result);
            Assert.NotNull(TestCase.Tests["two"].Result);
            Assert.NotNull(TestCase.Tests["three"].Result);
        }
예제 #5
0
        public void Run_ShouldInvokeTheProxysRunMethod(bool hasSetUp, bool hasTearDown)
        {
            // Arrange
            var proxy  = new Mock <ObjectProxy>();
            var runner = new PmlTestRunner(proxy.Object, Mock.Of <MethodInvoker>());

            TestCase.HasSetUp    = hasSetUp;
            TestCase.HasTearDown = hasTearDown;
            // Act
            runner.Run(Test);
            // Assert
            proxy.Verify(p => p.Invoke("run", "Test", "one", hasSetUp, hasTearDown), Times.Exactly(1));
        }
예제 #6
0
        public void Run_ShouldDisposeTestReturnValue()
        {
            // Arrange
            var result = new Mock <IDisposable>();
            var proxy  = new Mock <ObjectProxy>();

            proxy.Setup(mock => mock.Invoke(It.IsAny <string>(), It.IsAny <object[]>())).Returns(result.Object);
            var runner = new PmlTestRunner(proxy.Object, Mock.Of <MethodInvoker>());

            // Act
            runner.Run(Test);
            // Assert
            result.Verify(mock => mock.Dispose(), Times.Exactly(1));
        }
예제 #7
0
        public void Run_ShouldReturnFailedResultWhenTestReturnsError()
        {
            // Arrange
            var proxy = new Mock <ObjectProxy>();

            proxy.Setup(mock => mock.Invoke(It.IsAny <string>(), It.IsAny <object[]>())).Returns(StackTrace);
            var runner = new PmlTestRunner(proxy.Object, Mock.Of <MethodInvoker>());
            // Act
            var result = runner.Run(Test);

            // Assert
            Assert.IsFalse(result.Passed);
            Assert.NotNull(result.Error);
            Assert.AreEqual(StackTrace[1.0], result.Error.Message);
        }
예제 #8
0
        public void Run_ShouldAssignAndReturnTestResultWithElapsedTime(int duration)
        {
            // Arrange
            int seconds = 0;
            var clock   = new Mock <Clock>();

            clock.SetupGet(mock => mock.CurrentInstant)
            .Returns(() => Instant.FromSeconds(seconds))
            .Callback(() => seconds = duration);
            var runner = new PmlTestRunner(Mock.Of <ObjectProxy>(), Mock.Of <MethodInvoker>(), clock.Object);
            // Act
            var result = runner.Run(Test);

            // Assert
            Assert.AreEqual(TimeSpan.FromSeconds(duration), result.Duration);
            Assert.AreSame(result, Test.Result);
        }