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))); }
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))); }
public void TypesThat_ArePublic() { var testFunc = (Func <Type, bool>)TypesThat.ArePublic(); Assert.True(testFunc(typeof(DependentService <>))); Assert.False(testFunc(typeof(PrivateClass))); }
public void HaveAttributeGeneric() { Func <Type, bool> haveFilter = TypesThat.HaveAttribute(typeof(SomeTestAttribute)); Assert.True(haveFilter(typeof(AttributedSimpleObjectA))); Assert.False(haveFilter(typeof(AttributedSimpleObjectE))); }
public void AreInTheSameNamespaceAndSubnamespaceGeneric() { Func <Type, bool> sameNamespace = TypesThat.AreInTheSameNamespaceAs <IRpcApi>(true); Assert.True(sameNamespace(typeof(TypesThat))); Assert.False(sameNamespace(GetType())); }
public void AreInTheSameNamespace() { Func <Type, bool> sameNamespace = TypesThat.AreInTheSameNamespaceAs(typeof(IRpcApi)); Assert.True(sameNamespace(typeof(TypesThat))); Assert.False(sameNamespace(GetType())); }
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))); }
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))); }
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))); }
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()); }
public void TypesThat_AreBasedOn_Func_Throws_Null() { Assert.Throws <ArgumentNullException>(() => TypesThat.AreBasedOn((Func <Type, bool>)null)); }
public void TypesThat_AreBasedOn_Throws_Null() { Assert.Throws <ArgumentNullException>(() => TypesThat.AreBasedOn((Type)null)); }
public void TypesThat_HaveProperty() { var testFunc = (Func <Type, bool>)TypesThat.HaveProperty("PropertyA"); Assert.True(testFunc(typeof(PropertyClass))); }
public void TypesThat_AreOpenGeneric() { var testFunc = (Func <Type, bool>)TypesThat.AreOpenGeneric(); Assert.True(testFunc(typeof(DependentService <>))); }
public void TypesThat_AreGeneric() { var testFunc = (Func <Type, bool>)TypesThat.AreConstructedGeneric(); Assert.True(testFunc(typeof(DependentService <IBasicService>))); }
public void TypesThat_AreNotPublic() { var testFunc = (Func <Type, bool>)TypesThat.AreNotPublic(); Assert.True(testFunc(typeof(PrivateClass))); }
/// <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)))); }
public void TypesThat_HaveProperty_Generic_With_Name() { var testFunc = (Func <Type, bool>)TypesThat.HaveProperty <int>("PropertyA"); Assert.True(testFunc(typeof(PropertyClass))); }