コード例 #1
0
        public IClassCollection Create(IClassCollector classCollector, bool negate, bool not)
        {
            var classes     = classCollector.Get();
            var classFilter = new FilteredClasses(classes);
            var result      = new ClassCondition(classFilter, negate);

            return(not ? result.Not() : result);
        }
コード例 #2
0
        public void HasNameMatching_Should_FilterByPattern()
        {
            var classFilter = new FilteredClasses(CreateSampleClasses());
            var sut         = new ClassCondition(classFilter, false);

            sut.HasNameMatching("A");

            Assert.AreEqual(1, classFilter.FilteredItems.Count());
            Assert.IsTrue(classFilter.FilteredItems.Any(f => f.Name == "A"));
        }
コード例 #3
0
        public void HasAttribute_Should_FilterByAttribute()
        {
            var classFilter = new FilteredClasses(CreateSampleClasses());
            var sut         = new ClassCondition(classFilter, false);

            _mockClass1.SetupGet(c => c.ClassType).Returns(typeof(ClassConditionFixture));
            _mockClass2.SetupGet(c => c.ClassType).Returns(typeof(int));
            _mockClass3.SetupGet(c => c.ClassType).Returns(typeof(int));

            sut.HasAttribute <TestClassAttribute>();

            Assert.AreEqual(1, classFilter.FilteredItems.Count());
            Assert.IsTrue(classFilter.FilteredItems.Any(f => f.Name == "A"));
        }
コード例 #4
0
        public void Is_Should_FilterByTypePredicate()
        {
            var classFilter = new FilteredClasses(CreateSampleClasses());
            var sut         = new ClassCondition(classFilter, false);

            _mockClass1.SetupGet(c => c.ClassType).Returns(typeof(SampleImplementation));
            _mockClass2.SetupGet(c => c.ClassType).Returns(typeof(int));
            _mockClass3.SetupGet(c => c.ClassType).Returns(typeof(int));

            sut.Is(t => t == typeof(SampleImplementation));

            Assert.AreEqual(1, classFilter.FilteredItems.Count());
            Assert.IsTrue(classFilter.FilteredItems.Any(f => f.Name == "A"));
        }
コード例 #5
0
        public void ImplementsInterfaceMatching_Should_FilterByImplementedInterfaceName()
        {
            var classFilter = new FilteredClasses(CreateSampleClasses());
            var sut         = new ClassCondition(classFilter, false);

            _mockClass1.SetupGet(c => c.ClassType).Returns(typeof(SampleImplementation));
            _mockClass2.SetupGet(c => c.ClassType).Returns(typeof(int));
            _mockClass3.SetupGet(c => c.ClassType).Returns(typeof(int));

            sut.ImplementsInterfaceMatching("*Sampl*");

            Assert.AreEqual(1, classFilter.FilteredItems.Count());
            Assert.IsTrue(classFilter.FilteredItems.Any(f => f.Name == "A"));
        }
コード例 #6
0
        public void IsDerivedFrom_Should_FilterByTypePredicate_WhenTypeIsGeneric()
        {
            var classFilter = new FilteredClasses(CreateSampleClasses());
            var sut         = new ClassCondition(classFilter, false);

            _mockClass1.SetupGet(c => c.ClassType).Returns(typeof(ClassCondition));
            _mockClass2.SetupGet(c => c.ClassType).Returns(typeof(int));
            _mockClass3.SetupGet(c => c.ClassType).Returns(typeof(int));

            sut.IsDerivedFrom(typeof(TestCollectionBase <, , ,>));

            Assert.AreEqual(1, classFilter.FilteredItems.Count());
            Assert.IsTrue(classFilter.FilteredItems.Any(f => f.Name == "A"));
        }
コード例 #7
0
        public void IsDeclaredInAssemblyMatching_Should_FilterByPAttern()
        {
            var classFilter = new FilteredClasses(CreateSampleClasses());
            var sut         = new ClassCondition(classFilter, false);

            var sampleAssembly = new MarkUnitAssembly(GetType().Assembly);
            var otherAssembly  = new MarkUnitAssembly(typeof(List <>).Assembly);

            _mockClass1.SetupGet(c => c.AssemblyInfo).Returns(sampleAssembly);
            _mockClass2.SetupGet(c => c.AssemblyInfo).Returns(otherAssembly);
            _mockClass3.SetupGet(c => c.AssemblyInfo).Returns(otherAssembly);

            sut.IsDeclaredInAssemblyMatching("Tests.*");

            Assert.AreEqual(1, classFilter.FilteredItems.Count());
            Assert.IsTrue(classFilter.FilteredItems.Any(f => f.Name == "A"));
        }