public void KnownTypes_FromAssembly_ExcludingNamespace_OpinionIsIndifferent_ReturnsAllTypesOutsideNamespace() { var subject = new DetectTypes(); var indifferentOpinion = new TypeListOpinion( null, null); subject.FromAssemblyContaining<IService>() .ExcludeNamespaceContaining<ICompoundNeed>() .TakeAdviceFrom(indifferentOpinion); var knownTypes = subject.KnownTypes().ToList(); var includedTypes = typeof(IService).Assembly.GetTypes() .Where(type => !type.Namespace.StartsWith( typeof(ICompoundNeed).Namespace)) .ToList(); foreach (var inclusion in includedTypes) { Assert.Contains(inclusion, knownTypes); } }
public void KnownTypes_FromAssembly_ExcludingNamepsace_TypeInNamespaceIncludedBySecondOpinion_ReturnsType() { var inclusions = new[] { typeof(CompoundModule) }; var subject = new DetectTypes(); var inclusionOpinion = new TypeListOpinion( inclusions, null); subject.FromAssemblyContaining<IService>() .ExcludeNamespaceContaining<CompoundModule>() .TakeAdviceFrom(inclusionOpinion); var knownTypes = subject.KnownTypes().ToList(); foreach (var inclusion in inclusions) { Assert.Contains(inclusion, knownTypes); } }
public void KnownTypes_FromAssembly_TakingAdviceFromOneOpinion_ReturnsNoTypesExcludedByOpinion() { var inclusions = new[] { typeof(CompoundModule), typeof(SubImplementor) }; var exclusions = new[] { typeof(Implementor1), typeof(Implementor2) }; var subject = new DetectTypes(); subject.FromAssemblyContaining<IService>() .TakeAdviceFrom( new TypeListOpinion( inclusions, exclusions)); var knownTypes = subject.KnownTypes().ToList(); foreach (var exclusion in exclusions) { Assert.DoesNotContain(exclusion, knownTypes); } }
public void KnownTypes_FromAssembly_IncludingTypeCondition_ReturnsNoTypesNotMatchingCondition() { var markerType = typeof(IGeneralInterface); var subject = new DetectTypes(); Func<Type, bool> matchCondition = t => t.Namespace.EndsWith("ThreeDeep"); subject.FromAssemblyContaining<IService>() .IncludeTypesWhere(matchCondition); var knownTypes = subject.KnownTypes().ToList(); var excludedTypes = markerType.Assembly.GetTypes() .Where(type => !matchCondition(type)) .ToList(); foreach (var excludedType in excludedTypes) { Assert.DoesNotContain(excludedType, knownTypes); } }
public void KnownTypes_FromAssembly_IncludingTwoTypeConditions_ReturnsAllTypesMatchingEitherCondition() { var markerType = typeof(IGeneralInterface); var subject = new DetectTypes(); Func<Type, bool> matchCondition = t => t.Namespace.EndsWith("ThreeDeep"); Func<Type, bool> matchCondition2 = t => t.Namespace.EndsWith("Compound"); subject.FromAssemblyContaining<IService>() .IncludeTypesWhere(matchCondition) .IncludeTypesWhere(matchCondition2); var knownTypes = subject.KnownTypes().ToList(); var includedTypes = markerType.Assembly.GetTypes() .Where(type => matchCondition(type) || matchCondition2(type)) .ToList(); foreach (var includedType in includedTypes) { Assert.Contains(includedType, knownTypes); } }
public void KnownTypes_FromAssembly_IncludingTwoNamespaces_ReturnsNoTypesOutsideIncludedNamespaces() { var markerTypes = new[] { typeof(IGeneralInterface), typeof(IThreeDeepNeed) }; var markerTypeNamespaces = markerTypes.Select(type => type.Namespace).ToList(); var subject = new DetectTypes(); subject.FromAssemblyContaining<IService>() .IncludeNamespaceContaining<IGeneralInterface>() .IncludeNamespaceContaining<IThreeDeepNeed>(); var knownTypes = subject.KnownTypes().ToList(); var excludedTypes = typeof(IService).Assembly.GetTypes() .Where(t => !markerTypeNamespaces.Any(ns => t.Namespace.StartsWith(ns))) .ToList(); foreach (var excludedType in excludedTypes) { Assert.DoesNotContain(excludedType, knownTypes); } }
public void KnownTypes_FromAssembly_IncludingOneTypeCondition_ExcludingOverlappingTypeCondition_ReturnsNoTypesMatchingNeitherCondition() { var markerType = typeof(IGeneralInterface); var subject = new DetectTypes(); Func<Type, bool> inclusionCondition = t => t.Namespace.Contains("MultipleImplementors"); Func<Type, bool> exclusionCondition = t => t.Namespace.EndsWith("SubImplementor"); subject.FromAssemblyContaining<IService>() .IncludeTypesWhere(inclusionCondition) .ExcludeTypesWhere(exclusionCondition); var knownTypes = subject.KnownTypes().ToList(); var excludedTypes = markerType.Assembly.GetTypes() .Where(type => !inclusionCondition(type) && !exclusionCondition(type)) .ToList(); foreach (var excludedType in excludedTypes) { Assert.DoesNotContain(excludedType, knownTypes); } }
public void KnownTypes_FromAssembly_IncludingOneNamespace_ExcludingSubNamespace_ReturnsNoTypesInSubNamespace() { var subject = new DetectTypes(); subject.FromAssemblyContaining<IService>() .IncludeNamespaceContaining<IGeneralInterface>() .ExcludeNamespaceContaining<SubImplementor>(); var knownTypes = subject.KnownTypes().ToList(); var excludedTypes = typeof(IService).Assembly.GetTypes() .Where(t => t.Namespace == typeof(SubImplementor).Namespace) .ToList(); foreach (var excludedType in excludedTypes) { Assert.DoesNotContain(excludedType, knownTypes); } }
public void KnownTypes_FromAssembly_IncludingNamespace_TypeInNamespaceExcludedBySecondOpinion_DoesNotReturnType() { var exclusions = new[] { typeof(CompoundModule) }; var subject = new DetectTypes(); var exclusionOpinion = new TypeListOpinion( null, exclusions); subject.FromAssemblyContaining<IService>() .IncludeNamespaceContaining<CompoundModule>() .TakeAdviceFrom(exclusionOpinion); var knownTypes = subject.KnownTypes().ToList(); foreach (var exclusion in exclusions) { Assert.DoesNotContain(exclusion, knownTypes); } }
public void KnownTypes_FromAssembly_IncludingNamespace_ReturnsNoTypesOutsideIncludedNamespace() { var markerType = typeof(IGeneralInterface); var subject = new DetectTypes(); subject.FromAssemblyContaining<IService>() .IncludeNamespaceContaining<IGeneralInterface>(); var knownTypes = subject.KnownTypes().ToList(); var excludedTypes = markerType.Assembly.GetTypes() .Where(t => !t.Namespace.StartsWith(markerType.Namespace)) .ToList(); foreach (var excludedType in excludedTypes) { Assert.DoesNotContain(excludedType, knownTypes); } }
public void KnownTypes_FromAssembly_ExcludingOneNamespace_IncludingSubNamespace_ReturnsAllTypesOutsideExcludedNamespace() { var subject = new DetectTypes(); subject.FromAssemblyContaining<IService>() .ExcludeNamespaceContaining<IGeneralInterface>() .IncludeNamespaceContaining<SubImplementor>(); var knownTypes = subject.KnownTypes().ToList(); var includedTypes = typeof(IService).Assembly.GetTypes() .Where(t => !t.Namespace.StartsWith(typeof(IGeneralInterface).Namespace)) .ToList(); foreach (var includedType in includedTypes) { Assert.Contains(includedType, knownTypes); } }
public void KnownTypes_FromAssembly_ExcludingNamespace_ReturnsNoTypesInExcludedSubNamespace() { var markerType = typeof(ICompoundNeed); var subject = new DetectTypes(); subject.FromAssemblyContaining<IService>() .ExcludeNamespaceContaining<ICompoundNeed>(); var knownTypes = subject.KnownTypes().ToList(); var excludedTypes = markerType.Assembly.GetTypes() .Where(t => t.Namespace.StartsWith(markerType.Namespace)) .ToList(); foreach (var excludedType in excludedTypes) { Assert.DoesNotContain(excludedType, knownTypes); } }
public void KnownTypes_GivenFromTypesHasBeenCalled_ReturnsTypesInCollection() { var sourceTypes = new[] { typeof(CompoundModule), typeof(SimpleModule), typeof(ThreeDeepModule) }; var subject = new DetectTypes(); subject.FromTypes(sourceTypes); var knownTypes = subject.KnownTypes(); foreach (var type in sourceTypes) Assert.Contains( type, knownTypes); }
public void KnownTypes_GivenFromNamespaceContainingHasBeenCalled_ReturnsTypesInAssembly() { var subject = new DetectTypes(); subject.FromNamespaceContaining<IService>(); var ns = typeof(IService).Namespace; var expectedTypes = typeof(IService).Assembly.GetTypes().Where(type => type.Namespace == ns); var knownTypes = subject.KnownTypes(); foreach (var type in expectedTypes) Assert.Contains( type, knownTypes); }