예제 #1
0
        public void ShouldReturnNullWhenAssemnlyInitializeIsNotPresent()
        {
            var assembly = new Mock<IAssembly>();
            var searcher = new Mock<IAssemblySearcher>();
            IMethodInfo expected = null;

            searcher.Setup(s => s.FindMethod(assembly.Object, typeof(AssemblyInitializeAttribute))).Returns(expected);

            var extractor = new MSTestExtractor(assembly.Object, searcher.Object);

            var actualInit = extractor.GetAssemblyInitialise();

            Assert.AreEqual(expected, actualInit);
        }
예제 #2
0
        public void ShouldGetMethodTestInitializeWhenPresent()
        {
            var assembly = new Mock<IAssembly>();
            var testMethodOwningType = new Mock<IType>();
            var searcher = new Mock<IAssemblySearcher>();
            var expectedInit = BuildMethod("SomeClass", "Init");
            var testMethod = BuildMethod("SomeClass", "Test");
            testMethod.Setup(m => m.DeclaringType).Returns(testMethodOwningType.Object);

            searcher.Setup(s => s.FindMethod(testMethodOwningType.Object, typeof(TestInitializeAttribute))).Returns(expectedInit.Object);

            var extractor = new MSTestExtractor(assembly.Object, searcher.Object);

            var actualCleanup = extractor.GetTestInitialize(testMethod.Object);

            Assert.AreEqual(expectedInit.Object, actualCleanup);
        }
예제 #3
0
        public void ShouldGetAssemblyCleanupWhenPresent()
        {
            var assembly = new Mock<IAssembly>();
            var searcher = new Mock<IAssemblySearcher>();
            var expectedCleanup = BuildMethod("SomeClass", "Cleanup");

            searcher.Setup(s => s.FindMethod(assembly.Object, typeof(AssemblyCleanupAttribute))).Returns(expectedCleanup.Object);

            var extractor = new MSTestExtractor(assembly.Object, searcher.Object);

            var actualCleanup = extractor.GetAssemblyCleanup();

            Assert.AreEqual(expectedCleanup.Object, actualCleanup);
        }
예제 #4
0
        public void ShouldGetAssemblyInitialiseWhenPresent()
        {
            var assembly = new Mock<IAssembly>();
            var searcher = new Mock<IAssemblySearcher>();
            var expectedInit = BuildMethod("SomeClass", "Init");

            searcher.Setup(s => s.FindMethod(assembly.Object, typeof(AssemblyInitializeAttribute))).Returns(expectedInit.Object);

            var extractor = new MSTestExtractor(assembly.Object, searcher.Object);

            var actualInit = extractor.GetAssemblyInitialise();

            Assert.AreEqual(expectedInit.Object, actualInit);
        }
예제 #5
0
        public void ShouldGetAllTestMethodsWhenPresent()
        {
            var assembly = new Mock<IAssembly>();
            var testMethodOwningType = new Mock<IType>();
            var searcher = new Mock<IAssemblySearcher>();
            var expectedCleanup = BuildMethod("SomeClass", "Cleanup");
            var testMethod1 = BuildMethod("SomeClass", "Test1");
            var testMethod2 = BuildMethod("SomeClass", "Test2");

            searcher.Setup(s => s.FindMethods(assembly.Object, typeof(TestMethodAttribute))).Returns(new[] { testMethod1.Object, testMethod2.Object });

            var extractor = new MSTestExtractor(assembly.Object, searcher.Object);

            var actualTestMethods = extractor.GetTestMethods();

            Assert.AreEqual(testMethod1.Object, actualTestMethods[0]);
            Assert.AreEqual(testMethod2.Object, actualTestMethods[1]);
        }