예제 #1
0
        public void TypesThat_Match()
        {
            var testFunc = (Func <Type, bool>)TypesThat.Match(t => t == typeof(DependentService <>));

            Assert.True(testFunc(typeof(DependentService <>)));
            Assert.False(testFunc(typeof(TypesThatTests)));
        }
예제 #2
0
        public void TypesThat_AreBasedOn_Func()
        {
            var testFunc = (Func <Type, bool>)TypesThat.AreBasedOn(type => type == typeof(IBasicService));

            Assert.True(testFunc(typeof(BasicService)));
            Assert.False(testFunc(typeof(MultipleService1)));
        }
예제 #3
0
        public void TypesThat_ArePublic()
        {
            var testFunc = (Func <Type, bool>)TypesThat.ArePublic();

            Assert.True(testFunc(typeof(DependentService <>)));
            Assert.False(testFunc(typeof(PrivateClass)));
        }
예제 #4
0
        public void HaveAttributeGeneric()
        {
            Func <Type, bool> haveFilter = TypesThat.HaveAttribute(typeof(SomeTestAttribute));

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectE)));
        }
예제 #5
0
        public void AreInTheSameNamespaceAndSubnamespaceGeneric()
        {
            Func <Type, bool> sameNamespace = TypesThat.AreInTheSameNamespaceAs <IRpcApi>(true);

            Assert.True(sameNamespace(typeof(TypesThat)));

            Assert.False(sameNamespace(GetType()));
        }
예제 #6
0
        public void AreInTheSameNamespace()
        {
            Func <Type, bool> sameNamespace = TypesThat.AreInTheSameNamespaceAs(typeof(IRpcApi));

            Assert.True(sameNamespace(typeof(TypesThat)));

            Assert.False(sameNamespace(GetType()));
        }
예제 #7
0
        public void HaveAttributeGenericFiltered()
        {
            Func <Type, bool> haveFilter = TypesThat.HaveAttribute <SomeTestAttribute>(x => x.TestValue == 5);

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectB)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectE)));
        }
예제 #8
0
        public void OrFilteredTest()
        {
            Func <Type, bool> haveFilter = TypesThat.EndWith("A").Or.EndWith("B");

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.True(haveFilter(typeof(AttributedSimpleObjectB)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectC)));
        }
예제 #9
0
        public void HaveAttributeTypeFiltered()
        {
            Func <Type, bool> haveFilter = TypesThat.HaveAttribute(typeof(SomeTestAttribute),
                                                                   x => ((SomeTestAttribute)x).TestValue == 5);

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectB)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectE)));
        }
예제 #10
0
        public void ComplexHaveAttributeNonGeneric()
        {
            var container = new DependencyInjectionContainer();

            container.Configure(c => c.Export(typeof(TypesThatTests).GetTypeInfo().Assembly.ExportedTypes).
                                ByInterface(typeof(IAttributedSimpleObject)).
                                Where(TypesThat.HaveAttribute(t => t == typeof(SomeTestAttribute))));

            IEnumerable <IAttributedSimpleObject> simpleObjects = container.LocateAll <IAttributedSimpleObject>();

            Assert.NotNull(simpleObjects);
            Assert.Equal(3, simpleObjects.Count());
        }
예제 #11
0
 public void TypesThat_AreBasedOn_Func_Throws_Null()
 {
     Assert.Throws <ArgumentNullException>(() => TypesThat.AreBasedOn((Func <Type, bool>)null));
 }
예제 #12
0
 public void TypesThat_AreBasedOn_Throws_Null()
 {
     Assert.Throws <ArgumentNullException>(() => TypesThat.AreBasedOn((Type)null));
 }
예제 #13
0
        public void TypesThat_HaveProperty()
        {
            var testFunc = (Func <Type, bool>)TypesThat.HaveProperty("PropertyA");

            Assert.True(testFunc(typeof(PropertyClass)));
        }
예제 #14
0
        public void TypesThat_AreOpenGeneric()
        {
            var testFunc = (Func <Type, bool>)TypesThat.AreOpenGeneric();

            Assert.True(testFunc(typeof(DependentService <>)));
        }
예제 #15
0
        public void TypesThat_AreGeneric()
        {
            var testFunc = (Func <Type, bool>)TypesThat.AreConstructedGeneric();

            Assert.True(testFunc(typeof(DependentService <IBasicService>)));
        }
예제 #16
0
        public void TypesThat_AreNotPublic()
        {
            var testFunc = (Func <Type, bool>)TypesThat.AreNotPublic();

            Assert.True(testFunc(typeof(PrivateClass)));
        }
예제 #17
0
        /// <summary>
        /// Expose types in the same assembly and namespace as T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configuration"></param>
        /// <param name="includeSubnamespaces"></param>
        /// <returns></returns>
        public static ITypeSetExposureConfiguration ExposeNamespaceContaining <T>(this IRpcApi configuration, bool includeSubnamespaces = true)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(configuration.Expose(typeof(T).GetTypeInfo().Assembly.ExportedTypes.Where(TypesThat.AreInTheSameNamespaceAs <T>(includeSubnamespaces))));
        }
예제 #18
0
        public void TypesThat_HaveProperty_Generic_With_Name()
        {
            var testFunc = (Func <Type, bool>)TypesThat.HaveProperty <int>("PropertyA");

            Assert.True(testFunc(typeof(PropertyClass)));
        }