예제 #1
0
        public void FindAllDerivedFrom_When_1_exists_should_find_1()
        {
            #region test source
            var testControllerBase = @"
using System;

namespace Test.Controllers{ 
    public abstract class ControllerBase{
        public ActionResult Index(){
        }
    }
    public class ControllerTest:ControllerBase{
    }
}";

            #endregion

            var compilation = ObjectMother.CreateCompilation().AddSource(testControllerBase);

            var controlleBase = compilation.GetTypeByMetadataName("Test.Controllers.ControllerBase");

            var input = new Input(compilation).Selector<INamedTypeSymbol>((s) =>
            {
                return s.InheritsFrom(controlleBase);
            });


            PAssert.IsTrue(() => input.GetResults().Count() == 1);
        }
예제 #2
0
        public void FindMethod_When_three_exists_in_different_classes_should_find_three()
        {
            #region test source
            var testControllerBase = @"
using System;

namespace Test.Controllers{ 
    public abstract class ControllerBase{
    }
    public class ControllerTest:ControllerBase{
        public ActionResult Test(){
        }
        public ActionResult Test2(){
        }
    }
    public class ControllerTest:ControllerBase{
        public ActionResult Test3(){
        }
    }
}";

            #endregion

            var compilation = ObjectMother.CreateCompilation().AddSource(testControllerBase);

            var controlleBase = compilation.GetTypeByMetadataName("Test.Controllers.ControllerBase");

            var input = new Input(compilation).Selector<INamedTypeSymbol>((s) =>
            {
                return s.InheritsFrom(controlleBase);
            });
            var symbols = new List<ISymbol>();

            foreach (var result in input.GetResults())
            {
                var methodInput = new Input(result).Selector<IMethodSymbol>((s) =>
                {
                    return s.MethodKind == MethodKind.Ordinary;
                });
                symbols.AddRange(methodInput.GetResults());
            }

            PAssert.IsTrue(() => symbols.Count == 3);
        }