Example #1
0
        public void ConstructorIsSafe_CS()
        {
            var safeConstructor = new CSharpBuilderPatternCondition(true, new BuilderPatternDescriptor <CSharpSyntax.InvocationExpressionSyntax>(false, (context) => false));

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

            var unsafeConstructor = new CSharpBuilderPatternCondition(false, new BuilderPatternDescriptor <CSharpSyntax.InvocationExpressionSyntax>(false, (context) => false));

            unsafeConstructor.IsInvalidBuilderInitialization(context_CS).Should().BeTrue();
        }
Example #2
0
        public void IsInvalidBuilderInitialization_CS()
        {
            var aaaInvalidator = new BuilderPatternDescriptor <CSharpSyntax.InvocationExpressionSyntax>(false, (context) => context.MethodName == "Aaa");
            var bbbValidator   = new BuilderPatternDescriptor <CSharpSyntax.InvocationExpressionSyntax>(true, (context) => context.MethodName == "Bbb");
            var cccInvalidator = new BuilderPatternDescriptor <CSharpSyntax.InvocationExpressionSyntax>(false, (context) => context.MethodName == "Ccc");

            var condition1 = new CSharpBuilderPatternCondition(false, bbbValidator);

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

            var condition2 = new CSharpBuilderPatternCondition(false, cccInvalidator);

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

            var condition3 = new CSharpBuilderPatternCondition(true, cccInvalidator);

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

            var condition4 = new CSharpBuilderPatternCondition(true, bbbValidator);

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

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

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

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

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

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

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

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

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

            var dddContext = new InvocationContext(FindMethodInvocation_CS(context_CS.Invocation.SyntaxTree, "Ddd"), "Ddd", context_CS.SemanticModel);
            var condition9 = new CSharpBuilderPatternCondition(false);

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