Exemplo n.º 1
0
        public void AssemblySearcherShouldReturnNullIfItCantFindAMethod()
        {
            var searcher = new AssemblySearcher();

            var assembly = Assembly()
                           .With(Type("SomeClass")
                                 .With(Method("SomeFirstMethod"))
                                 .With(Method("SomeSecondMethod"))
                                 .With(Method("SomeLastMethod")));

            var actualMethod = searcher.FindMethod(assembly.Object, typeof(TestMethodAttribute));
            Assert.IsNull(actualMethod);
        }
Exemplo n.º 2
0
        public void AssemblySearcherShouldReturnNullIfItCanFindTheMethodInType()
        {
            var searcher = new AssemblySearcher();

            var type = Type("SomeClass")
                                 .With(Method("SomeFirstMethod"))
                                 .With(Method("SomeTestMethod"))
                                 .With(Method("SomeLastMethod"));

            var actualMethod = searcher.FindMethod(type.Object, typeof(TestMethodAttribute));

            Assert.IsNull(actualMethod);
        }
Exemplo n.º 3
0
        public void AssemblySearcherShouldLookForAllMethodsInAllTypesWithMatchingAttribute()
        {
            var searcher = new AssemblySearcher();

            var assembly = Assembly()
                           .With(Type("SomeFirstClass")
                                 .With(Method("Method1"))
                                 .With(Method("Method2").With(typeof(TestMethodAttribute)))
                                 .With(Method("Method3")))
                            .With(Type("SomeSecondClass")
                                 .With(Method("Method4").With(typeof(TestMethodAttribute)))
                                 .With(Method("Method5").With(typeof(TestMethodAttribute)))
                                 .With(Method("Method6").With(typeof(TestMethodAttribute))))
                            .With(Type("SomeThirdClass")
                                 .With(Method("Method7"))
                                 .With(Method("Method8"))
                                 .With(Method("Method9")));

            var actualMethods = searcher.FindMethods(assembly.Object, typeof(TestMethodAttribute));
            var expectedMethods = new List<string> { "Method2", "Method4", "Method5", "Method6" };

            Assert.IsTrue(expectedMethods.SequenceEqual(actualMethods.OrderBy(m => m.Name).Select(m => m.Name)));
        }
Exemplo n.º 4
0
        public void AssemblySearcherShouldLookForTheMethodInAllTypes()
        {
            var searcher = new AssemblySearcher();

            var assembly = Assembly()
                           .With(Type("SomeFirstClass")
                                 .With(Method("SomeFirstMethod"))
                                 .With(Method("SomeSecondMethod"))
                                 .With(Method("SomeLastMethod")))
                            .With(Type("SomeSecondClass")
                                 .With(Method("SomeFirstMethod"))
                                 .With(Method("SomeTestMethod").With(typeof(TestMethodAttribute)))
                                 .With(Method("SomeLastMethod")))
                            .With(Type("SomeThirdClass")
                                 .With(Method("SomeFirstMethod"))
                                 .With(Method("SomeSecondMethod"))
                                 .With(Method("SomeLastMethod")));

            var actualMethod = searcher.FindMethod(assembly.Object, typeof(TestMethodAttribute));
            Assert.AreEqual("SomeTestMethod", actualMethod.Name);
        }
Exemplo n.º 5
0
        public void AssemblySearcherShouldFindFirstMethodOfMatchingAttributeInType()
        {
            var searcher = new AssemblySearcher();

            var type = Type("SomeClass")
                                 .With(Method("SomeFirstMethod"))
                                 .With(Method("SomeTestMethod").With(typeof(TestMethodAttribute)))
                                 .With(Method("SomeLastMethod"));

            var actualMethod = searcher.FindMethod(type.Object, typeof(TestMethodAttribute));

            Assert.AreEqual("SomeTestMethod", actualMethod.Name);
        }