示例#1
0
        public void ConstructorIsSafe_VB()
        {
            var safeConstructor = new VisualBasicBuilderPatternCondition(true, new BuilderPatternDescriptor <VBSyntax.InvocationExpressionSyntax>(false, (context) => false));

            safeConstructor.IsInvalidBuilderInitialization(context_VB).Should().BeFalse();

            var unsafeConstructor = new VisualBasicBuilderPatternCondition(false, new BuilderPatternDescriptor <VBSyntax.InvocationExpressionSyntax>(false, (context) => false));

            unsafeConstructor.IsInvalidBuilderInitialization(context_VB).Should().BeTrue();
        }
        public void ConstructorIsSafe_VB()
        {
            var safeConstructor = new VisualBasicBuilderPatternCondition(true, new BuilderPatternDescriptorVB(false, (context) => false));

            safeConstructor.IsInvalidBuilderInitialization(vbContext).Should().BeFalse();

            var unsafeConstructor = new VisualBasicBuilderPatternCondition(false, new BuilderPatternDescriptorVB(false, (context) => false));

            unsafeConstructor.IsInvalidBuilderInitialization(vbContext).Should().BeTrue();
        }
示例#3
0
        public void IsInvalidBuilderInitialization_VB()
        {
            var aaaInvalidator = new BuilderPatternDescriptor <VBSyntax.InvocationExpressionSyntax>(false, (context) => context.MethodName == "Aaa");
            var bbbValidator   = new BuilderPatternDescriptor <VBSyntax.InvocationExpressionSyntax>(true, (context) => context.MethodName == "Bbb");
            var cccInvalidator = new BuilderPatternDescriptor <VBSyntax.InvocationExpressionSyntax>(false, (context) => context.MethodName == "Ccc");

            var condition1 = new VisualBasicBuilderPatternCondition(false, bbbValidator);

            condition1.IsInvalidBuilderInitialization(context_VB).Should().BeFalse(); // Invalid constructor validated by method

            var condition2 = new VisualBasicBuilderPatternCondition(false, cccInvalidator);

            condition2.IsInvalidBuilderInitialization(context_VB).Should().BeTrue(); // Invalid constructor invalidated by method

            var condition3 = new VisualBasicBuilderPatternCondition(true, cccInvalidator);

            condition3.IsInvalidBuilderInitialization(context_VB).Should().BeTrue(); // Valid constructor invalidated by method

            var condition4 = new VisualBasicBuilderPatternCondition(true, bbbValidator);

            condition4.IsInvalidBuilderInitialization(context_VB).Should().BeFalse(); // Valid constructor validated by method

            var condition5 = new VisualBasicBuilderPatternCondition(false, aaaInvalidator, bbbValidator);

            condition5.IsInvalidBuilderInitialization(context_VB).Should().BeFalse();                     // Invalid constructor, invalidated by Aaa, validated by Bbb

            var condition6 = new VisualBasicBuilderPatternCondition(false, bbbValidator, aaaInvalidator); // Configuration order has no effect

            condition6.IsInvalidBuilderInitialization(context_VB).Should().BeFalse();                     // Invalid constructor, invalidated by Aaa, validated by Bbb

            var condition7 = new VisualBasicBuilderPatternCondition(true, bbbValidator, cccInvalidator);

            condition7.IsInvalidBuilderInitialization(context_VB).Should().BeTrue();                     // Valid constructor, validated by Bbb, invalidated by Ccc

            var condition8 = new VisualBasicBuilderPatternCondition(true, cccInvalidator, bbbValidator); // Configuration order has no effect

            condition8.IsInvalidBuilderInitialization(context_VB).Should().BeTrue();                     // Valid constructor, validated by Bbb, invalidated by Ccc

            var dddContext = new InvocationContext(FindMethodInvocation_VB(context_VB.Invocation.SyntaxTree, "Ddd"), "Ddd", context_VB.SemanticModel);
            var condition9 = new VisualBasicBuilderPatternCondition(false);

            condition9.IsInvalidBuilderInitialization(dddContext).Should().BeFalse(); // Invalid constructor is not tracked through array propagation
        }