public void PropertyTypeWriterTest(string patternImplFieldType, string expectedGeneratedFieldName)
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1));

            var implPatternFieldNode = SyntaxTreeHelper.GetFieldSyntax(patternImplFieldType, PatternFieldName);

            var generatedField = NodeWriterHelper.WriteAndAssertSingleMemberOfType <FieldDeclarationSyntax>(pw, implPatternFieldNode);

            Assert.Equal(expectedGeneratedFieldName, generatedField.Declaration.Type.ToString());
        }
        public void SimplePropertyWriterTest(string type, string name, string genType, string genName)
        {
            var srw = SetupStringReplaceWriter("PatternClassName", "NewClassString");

            var implPatternPropNode = SyntaxTreeHelper.GetPropertyImplSyntax(type, name);

            var generatedProperty = NodeWriterHelper.WriteAndAssertSingleMemberOfType <PropertyDeclarationSyntax>(srw, implPatternPropNode);

            Assert.Equal(genName, generatedProperty.Identifier.Text);
            Assert.Equal(genType, generatedProperty.Type.ToString());
        }
        public void SimpleFieldWriterTest(string patternFieldName, string expectedImplPropName)
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1));

            var implPatternPropNode = SyntaxTreeHelper.GetFieldSyntax(PatternPropType, patternFieldName);

            var fieldProperty = NodeWriterHelper.WriteAndAssertSingleMemberOfType <FieldDeclarationSyntax>(pw, implPatternPropNode);

            Assert.Equal(expectedImplPropName, fieldProperty.Declaration.Variables.Single().Identifier.Text);
            Assert.Equal(DeclPropType1, fieldProperty.Declaration.Type.ToString());
        }
        public void SimplePropertyWriterTest()
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1));

            var implPatternPropNode = SyntaxTreeHelper.GetPropertyImplSyntax(PatternPropType, PatternPropName);

            var generatedProperty = NodeWriterHelper.WriteAndAssertSingleMemberOfType <PropertyDeclarationSyntax>(pw, implPatternPropNode);

            Assert.Equal(DeclPropName1, generatedProperty.Identifier.Text);
            Assert.Equal(DeclPropType1, generatedProperty.Type.ToString());
        }
        public void MultiPropertyWriterTest()
        {
            var srw = SetupStringReplaceWriter("PatternClassName", new[] { "NewClassString1", "NewClassString2" });

            var implPatternPropNode = SyntaxTreeHelper.GetPropertyImplSyntax("object", "PatternClassName");

            var generatedProperties = NodeWriterHelper.WriteAndAssertMultiMemberOfType <PropertyDeclarationSyntax>(srw, implPatternPropNode);

            Assert.Equal(2, generatedProperties.Count);
            Assert.Equal("NewClassString1", generatedProperties[0].Identifier.Text);
            Assert.Equal("NewClassString2", generatedProperties[1].Identifier.Text);
        }
        public void PropertyWithAccessorsWriterTest(string patternFieldName, string implPropName)
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1));

            var implPatternPropNode = SyntaxTreeHelper.GetPropertyImplSyntax(PatternPropType, PatternPropName, patternFieldName);

            var generatedProperty = NodeWriterHelper.WriteAndAssertSingleMemberOfType <PropertyDeclarationSyntax>(pw, implPatternPropNode);

            Assert.Equal(DeclPropName1, generatedProperty.Identifier.Text);
            Assert.Equal(DeclPropType1, generatedProperty.Type.ToString());
            Assert.Contains(implPropName, generatedProperty.AccessorList.ToFullString(), StringComparison.InvariantCulture);
            Assert.DoesNotContain(patternFieldName, generatedProperty.AccessorList.ToFullString(), StringComparison.InvariantCulture);
        }
        public void SimpleVariableStatementWriterTest(string patternVariableName, string implPropName)
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1));

            var implPatternVariableNode = SyntaxTreeHelper.GetLocalDeclarationStatementSyntax(
                PatternPropType, $"{patternVariableName}Version", $"this.{patternVariableName}.Version");

            var variableProperty = NodeWriterHelper.WriteAndAssertSingleMemberOfType <FieldDeclarationSyntax>(
                pw, implPatternVariableNode);

            Assert.Equal($"{implPropName}Version", variableProperty.Declaration.Variables.Single().Identifier.Text);
            Assert.Equal($"this.{implPropName}.Version", variableProperty.Declaration.Variables.Single().Initializer.Value.ToString());
        }
        public void SimpleMethodWriterTest(
            string patternMethodName,
            string patternMethodArgumentName,
            string expectedImplMethodName,
            string expectedArgName)
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1));

            var implPatternMethodNode = SyntaxTreeHelper.GetMethodSyntax(PatternPropType, patternMethodName, patternMethodArgumentName, ", string otherArg");

            var methodProperty = NodeWriterHelper.WriteAndAssertSingleMemberOfType <MethodDeclarationSyntax>(pw, implPatternMethodNode);

            Assert.Equal(expectedImplMethodName, methodProperty.Identifier.Text);
            Assert.Equal(expectedArgName, methodProperty.ParameterList.Parameters.First().Identifier.Text);
            Assert.Equal(DeclPropType1, methodProperty.ReturnType.ToString());
        }
        public void ExpressionBodyPropertyWriterTest()
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1));

            var implPatternPropNode = SyntaxTreeHelper.GetExpressionBodyPropertyImplSyntax(
                PatternPropType,
                PatternPropName,
                $"this.{PatternFieldName}");

            var generatedProperty = NodeWriterHelper
                                    .WriteAndAssertSingleMemberOfType <PropertyDeclarationSyntax>(pw, implPatternPropNode);

            Assert.Equal(DeclPropName1, generatedProperty.Identifier.Text);
            Assert.Equal(DeclPropType1, generatedProperty.Type.ToString());
            Assert.NotNull(generatedProperty.ExpressionBody);
            Assert.Equal($"=> this.{DeclFieldName1}", generatedProperty.ExpressionBody.ToString());
        }
        public void MultiPropertyDeclarationWriterTest()
        {
            var pw = SetupPropertyWriter(PatternPropType, PatternPropName, (DeclPropType1, DeclPropName1), (DeclPropType2, DeclPropName2));

            var implPatternFieldNode = SyntaxTreeHelper.GetFieldSyntax(PatternPropType, PatternFieldName);

            var generatedFields = NodeWriterHelper.WriteAndAssertMultiMemberOfType <FieldDeclarationSyntax>(pw, implPatternFieldNode);

            Assert.Equal(2, generatedFields.Count);

            Assert.Equal(DeclPropType1, generatedFields[0].Declaration.Type.ToString());
            var v1 = Assert.Single(generatedFields[0].Declaration.Variables);

            Assert.Equal(DeclFieldName1, v1.Identifier.ValueText);

            Assert.Equal(DeclPropType2, generatedFields[1].Declaration.Type.ToString());
            var v2 = Assert.Single(generatedFields[1].Declaration.Variables);

            Assert.Equal(DeclFieldName2, v2.Identifier.ValueText);
        }
        public void GenericTypeParameterFieldPropertyWriterTest()
        {
            var itfType           = "IList<IPatternType>";
            var declType          = "IList<IDeclType>";
            var patternFieldType  = "AnyImplType<IPatternType>";
            var expectedFieldType = "AnyImplType<IDeclType>";

            var pw = SetupPropertyWriter(
                itfType,
                PatternPropName,
                TypeParamExtract,
                (declType, DeclPropName1));

            var implPatternFieldNode = SyntaxTreeHelper.GetFieldSyntax(patternFieldType, PatternFieldName);

            var generatedFields = NodeWriterHelper.WriteAndAssertMultiMemberOfType <FieldDeclarationSyntax>(pw, implPatternFieldNode);

            var field = Assert.Single(generatedFields);

            Assert.Equal(expectedFieldType, field.Declaration.Type.ToString());
        }