public void IncludeTypeWhenNoTypeRules(RegexFilter sut)
        {
            // Arrange
            Assert.Empty(sut.Rules);

            // Act
            bool actual = ((ITypeFilter)sut).ExcludeType(GetType());

            // Assert
            Assert.False(actual);
        }
        public void ShouldNotThrow()
        {
            var filter = new RegexFilter();
            filter.ExcludeAllTypes().IncludeType(typeof (InternalInnerInterface));
            List<MethodBase> methods =
                typeof(InternalInnerInterface).GetMethods(
                    BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly,
                    new[] { filter }).ToList();

            Assert.NotNull(methods);
            Assert.NotEmpty(methods);
        }
        public void IncludeMethodWhenNoMethodRules(
            Type type,
            Mock <MethodBase> methodMock,
            RegexFilter sut)
        {
            // Arrange
            Assert.Empty(sut.Rules);

            // Act
            bool actual = ((IMethodFilter)sut).ExcludeMethod(type, methodMock.Object);

            // Assert
            Assert.False(actual);
        }
        public void ExcudeType(
            IEnumerable <RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            sut.Rules.AddRange(otherRules);
            sut.ExcludeType(GetType());

            // Act
            bool actual = ((ITypeFilter)sut).ExcludeType(GetType());

            // Assert
            Assert.True(actual);
        }
        public void EnsureIncludeTypeRuleTakesPrecedenceOverExcudeTypeRule(
            IEnumerable <RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            sut.Rules.AddRange(otherRules);
            sut.ExcludeType(GetType())
            .IncludeType(GetType());

            // Act
            bool actual = ((ITypeFilter)sut).ExcludeType(GetType());

            // Assert
            Assert.False(actual);
        }
        public void ExcludeAllMethods()
        {
            // Arrange
            var sut = new RegexFilter();

            // Act
            IRegexFilter result = sut.ExcludeAllMethods();

            // Assert
            Assert.Same(sut, result);
            Assert.Single(sut.Rules);
            RegexRule methodRule = sut.MethodRules.Single();

            Assert.Matches(methodRule.Method, Guid.NewGuid().ToString());
        }
        public void ExcludeAllParameters()
        {
            // Arrange
            var sut = new RegexFilter();

            // Act
            IRegexFilter result = sut.ExcludeAllParameters();

            // Assert
            Assert.Same(sut, result);
            Assert.Single(sut.Rules);
            RegexRule parameterRule = sut.ParameterRules.Single();

            Assert.Matches(parameterRule.Parameter, Guid.NewGuid().ToString());
        }
        public void IncludeParameterWhenNoParameterRules(
            Type type,
            Mock <MethodBase> methodMock,
            Mock <ParameterInfo> parameterMock,
            RegexFilter sut)
        {
            // Arrange
            Assert.Empty(sut.Rules);

            // Act
            bool actual = ((IParameterFilter)sut).ExcludeParameter(type, methodMock.Object, parameterMock.Object);

            // Assert
            Assert.False(actual);
        }
        public void ExcudeMethodWithNoType(
            Type type,
            Mock <MethodBase> methodMock,
            IEnumerable <RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            methodMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            sut.Rules.AddRange(otherRules);
            sut.ExcludeMethod(methodMock.Object.Name);

            // Act
            bool actual = ((IMethodFilter)sut).ExcludeMethod(type, methodMock.Object);

            // Assert
            Assert.True(actual);
        }
        public void EnsureIncludeMethodTakesPrecedenceOverExcudeMethod(
            Type type,
            Mock <MethodBase> methodMock,
            IEnumerable <RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            methodMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            sut.Rules.AddRange(otherRules);
            sut.ExcludeMethod(methodMock.Object.Name, type)
            .IncludeMethod(methodMock.Object.Name);

            // Act
            bool actual = ((IMethodFilter)sut).ExcludeMethod(type, methodMock.Object);

            // Assert
            Assert.False(actual);
        }
        public void ExcudeParameter(
            Type type,
            Mock <MethodBase> methodMock,
            Mock <ParameterInfo> parameterMock,
            IEnumerable <RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            methodMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            parameterMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            sut.Rules.AddRange(otherRules);
            sut.ExcludeParameter(parameterMock.Object.Name, type, methodMock.Object.Name);

            // Act
            bool actual = ((IParameterFilter)sut).ExcludeParameter(type, methodMock.Object, parameterMock.Object);

            // Assert
            Assert.True(actual);
        }
        internal void CreateStaticMethodInvocationData(
            SpecimenProvider specimenProvider,
            RegexFilter filter)
        {
            // Arrange
            filter.IncludeMethod("Compare", typeof (Uri))
                  .Rules.Add(new RegexRule("exclude all", type: new Regex(".*"), method: new Regex(".*")));

            IArgumentNullExceptionFixture sut =
                new ArgumentNullExceptionFixture(typeof(Uri).Assembly,
                                                 specimenProvider,
                                                 new List<IFilter> { filter },
                                                 new List<IMapping>());

            // Act
            List<MethodData> methodDatas = sut.GetData().ToList();

            // Assert
            Assert.Equal(5, methodDatas.Count);
            Assert.Equal(5, methodDatas.Select(m => m.ExecutionSetup).OfType<DefaultExecutionSetup>().Count());
        }
        public void ExcludeAll()
        {
            // Arrange
            var sut = new RegexFilter();

            // Act
            IRegexFilter result = sut.ExcludeAll();

            // Assert
            Assert.Same(sut, result);
            Assert.Equal(3, sut.Rules.Count);
            RegexRule typeRule = sut.TypeRules.Single();

            Assert.Matches(typeRule.Type, Guid.NewGuid().ToString());
            RegexRule methodRule = sut.MethodRules.Single();

            Assert.Matches(methodRule.Method, Guid.NewGuid().ToString());
            RegexRule parameterRule = sut.ParameterRules.Single();

            Assert.Matches(parameterRule.Parameter, Guid.NewGuid().ToString());
        }
        public void ReturnTypeRules(
            List<RegexRule> typeRules,
            List<RegexRule> methodRules,
            List<RegexRule> parameterRules)
        {
            // Arrange
            var sut = new RegexFilter();
            sut.Rules.AddRange(parameterRules.Concat(methodRules).Concat(typeRules));

            // Act
            List<RegexRule> actualTypeRules = sut.TypeRules.ToList();
            List<RegexRule> actualIncludeTypeRules = sut.IncludeTypeRules.ToList();
            List<RegexRule> actualExcludeTypeRules = sut.ExcludeTypeRules.ToList();

            // Assert
            Assert.Equal(typeRules.Count, actualTypeRules.Count);
            Assert.Equal(typeRules.Count(r => r.Include), actualIncludeTypeRules.Count);
            Assert.Equal(typeRules.Count(r => !r.Include), actualExcludeTypeRules.Count);
            Assert.False(typeRules.Except(actualTypeRules).Any());
            Assert.False(typeRules.Where(r => r.Include).Except(actualIncludeTypeRules).Any());
            Assert.False(typeRules.Where(r => !r.Include).Except(actualExcludeTypeRules).Any());
        }
        public void ReturnMethodRules(
            List <RegexRule> typeRules,
            List <RegexRule> methodRules,
            List <RegexRule> parameterRules)
        {
            // Arrange
            var sut = new RegexFilter();

            sut.Rules.AddRange(parameterRules.Concat(methodRules).Concat(typeRules));

            // Act
            List <RegexRule> actualMethodRules        = sut.MethodRules.ToList();
            List <RegexRule> actualIncludeMethodRules = sut.IncludeMethodRules.ToList();
            List <RegexRule> actualExcludeMethodRules = sut.ExcludeMethodRules.ToList();

            // Assert
            Assert.Equal(methodRules.Count, actualMethodRules.Count);
            Assert.Equal(methodRules.Count(r => r.Include), actualIncludeMethodRules.Count);
            Assert.Equal(methodRules.Count(r => !r.Include), actualExcludeMethodRules.Count);
            Assert.False(methodRules.Except(actualMethodRules).Any());
            Assert.False(methodRules.Where(r => r.Include).Except(actualIncludeMethodRules).Any());
            Assert.False(methodRules.Where(r => !r.Include).Except(actualExcludeMethodRules).Any());
        }
        public void IncludeTypeWhenNoTypeRules(RegexFilter sut)
        {
            // Arrange
            Assert.Empty(sut.Rules);

            // Act
            bool actual = ((ITypeFilter)sut).ExcludeType(GetType());

            // Assert
            Assert.False(actual);
        }
        public void EnsureIncludeParameterTakesPrecedenceOverExcudeParameter(
            Type type,
            Mock<MethodBase> methodMock,
            Mock<ParameterInfo> parameterMock,
            IEnumerable<RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            methodMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            parameterMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            sut.Rules.AddRange(otherRules);
            sut.ExcludeParameter(parameterMock.Object.Name, type, methodMock.Object.Name)
               .IncludeParameter(parameterMock.Object.Name);

            // Act
            bool actual = ((IParameterFilter)sut).ExcludeParameter(type, methodMock.Object, parameterMock.Object);

            // Assert
            Assert.False(actual);
        }
        public void ExcludeAll()
        {
            // Arrange
            var sut = new RegexFilter();

            // Act
            IRegexFilter result = sut.ExcludeAll();

            // Assert
            Assert.Same(sut, result);
            Assert.Equal(3, sut.Rules.Count);
            RegexRule typeRule = sut.TypeRules.Single();
            Assert.True(typeRule.Type.IsMatch(Guid.NewGuid().ToString()));
            RegexRule methodRule = sut.MethodRules.Single();
            Assert.True(methodRule.Method.IsMatch(Guid.NewGuid().ToString()));
            RegexRule parameterRule = sut.ParameterRules.Single();
            Assert.True(parameterRule.Parameter.IsMatch(Guid.NewGuid().ToString()));
        }
 public void ReturnName(RegexFilter sut)
 {
     Assert.Equal("RegexFilter", sut.Name);
 }
        public void IncludeParameterWhenNoParameterRules(
            Type type,
            Mock<MethodBase> methodMock,
            Mock<ParameterInfo> parameterMock,
            RegexFilter sut)
        {
            // Arrange
            Assert.Empty(sut.Rules);

            // Act
            bool actual = ((IParameterFilter)sut).ExcludeParameter(type, methodMock.Object, parameterMock.Object);

            // Assert
            Assert.False(actual);
        }
 public void ReturnName(RegexFilter sut)
 {
     Assert.Equal("RegexFilter", sut.Name);
 }
        public void IncludeMethodWhenNoMethodRules(
            Type type,
            Mock<MethodBase> methodMock,
            RegexFilter sut)
        {
            // Arrange
            Assert.Empty(sut.Rules);

            // Act
            bool actual = ((IMethodFilter)sut).ExcludeMethod(type, methodMock.Object);

            // Assert
            Assert.False(actual);
        }
        public void CreateErroredMethodInvocationData(
            Mock<ISpecimenProvider> specimenProviderMock,
            FileNotFoundException exception,
            RegexFilter filter)
        {
            // Arrange
            specimenProviderMock.Setup(sp => sp.GetParameterSpecimens(It.IsAny<IList<ParameterInfo>>(), It.IsAny<int>()))
                                .Throws(exception);
            filter.IncludeMethod("Compare", typeof(Uri))
                  .Rules.Add(new RegexRule("exclude all", type: new Regex(".*"), method: new Regex(".*")));

            IArgumentNullExceptionFixture sut =
                new ArgumentNullExceptionFixture(typeof(Uri).Assembly,
                                                 specimenProviderMock.Object,
                                                 new List<IFilter> { filter },
                                                 new List<IMapping>());

            // Act
            List<MethodData> methodDatas = sut.GetData().ToList();

            // Assert
            Assert.Equal(5, methodDatas.Count);
            List<ErroredExecutionSetup> executionSetups = methodDatas.Select(m => m.ExecutionSetup).OfType<ErroredExecutionSetup>().ToList();
            Assert.Equal(5, executionSetups.Count);
            foreach (ErroredExecutionSetup executionSetup in executionSetups)
            {
                var compositionException = Assert.IsType<CompositionException>(executionSetup.Exception);
                Assert.Same(exception, compositionException.InnerException);
            }
        }
        public void EnsureIncludeTypeRuleTakesPrecedenceOverExcudeTypeRule(
            IEnumerable<RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            sut.Rules.AddRange(otherRules);
            sut.ExcludeType(GetType())
               .IncludeType(GetType());

            // Act
            bool actual = ((ITypeFilter)sut).ExcludeType(GetType());

            // Assert
            Assert.False(actual);
        }
        public void ExcludeAllTypes()
        {
            // Arrange
            var sut = new RegexFilter();

            // Act
            IRegexFilter result = sut.ExcludeAllTypes();

            // Assert
            Assert.Same(sut, result);
            Assert.Equal(1, sut.Rules.Count);
            RegexRule typeRule = sut.TypeRules.Single();
            Assert.True(typeRule.Type.IsMatch(Guid.NewGuid().ToString()));
        }
        public void ExcudeMethod(
            Type type,
            Mock<MethodBase> methodMock,
            IEnumerable<RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            methodMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            sut.Rules.AddRange(otherRules);
            sut.ExcludeMethod(methodMock.Object.Name, type);

            // Act
            bool actual = ((IMethodFilter)sut).ExcludeMethod(type, methodMock.Object);

            // Assert
            Assert.True(actual);
        }
        public void ExcudeType(
            IEnumerable<RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            sut.Rules.AddRange(otherRules);
            sut.ExcludeType(GetType());

            // Act
            bool actual = ((ITypeFilter) sut).ExcludeType(GetType());

            // Assert
            Assert.True(actual);
        }
        public void ExcudeParameterWithNoTypeNoMethod(
            Type type,
            Mock<MethodBase> methodMock,
            Mock<ParameterInfo> parameterMock,
            IEnumerable<RegexRule> otherRules,
            RegexFilter sut)
        {
            // Arrange
            parameterMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid());
            sut.Rules.AddRange(otherRules);
            sut.ExcludeParameter(parameterMock.Object.Name);

            // Act
            bool actual = ((IParameterFilter)sut).ExcludeParameter(type, methodMock.Object, parameterMock.Object);

            // Assert
            Assert.True(actual);
        }