public void CorrectlyInferViewModelName_OnlyPageSuffixConfigured()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ViewGeneration.XamlFileSuffix = "Page";

            var sut = new SetDataContextCommandLogic(
                profile,
                DefaultTestLogger.Create(),
                new TestVisualStudioAbstraction(),
                new TestFileSystem());

            var(view, viewModel, _) = sut.InferViewModelNameFromFileName("TestPage.xaml.cs");

            Assert.AreEqual("TestPage", view);
            Assert.AreEqual("Test", viewModel);
        }
        public void CorrectlySplitCamelCasePropertyNames()
        {
            var profile = TestProfile.CreateEmpty();

            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "$namewithspaces$",
            });

            var cpb    = new CodeParserBase(DefaultTestLogger.Create(), 4, profile);
            var result = cpb.GetPropertyOutput("string", "MyProperty", isReadOnly: false);

            Assert.AreEqual("My Property", result);
        }
        public void DetectsWhenPageContentIsAlreadySet()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ViewGeneration.XamlFileSuffix      = "Page";
            profile.ViewGeneration.ViewModelFileSuffix = "ViewModel";
            profile.Datacontext.CodeBehindPageContent  = @"public $viewmodelclass$ ViewModel
{
    get
    {
        return new $viewmodelclass$();
    }
}";

            var logger = DefaultTestLogger.Create();

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "TestPage.xaml.cs",
                ActiveDocumentText     = @"class TestPage
{
    public TestPage()
    {
        this.Initialize();
    }

    public TestViewModel ViewModel
    {
        get
        {
            return new TestViewModel();
        }
    }
}",
            };

            var fs = new TestFileSystem();

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var result = sut.ShouldEnableCommand();

            Assert.IsFalse(result);
        }
        public void CanMapMultipleAttributesToSameTypeInSingleMapping()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "<TextBlock Text=\"FALLBACK_$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Foo]int|[Bar]int",
                NameContains = "",
                Output       = "<TextBlock Text=\"FOOBAR_$name$\" />",
                IfReadOnly   = false,
            });

            var code = @"
namespace tests
{
    class Class1☆
    {
        public string Property1 { get; set; }
        public int Property2 { get; set; }
        [Foo]
        public int Property5 { get; set; }
        [Bar]
        public int Property6 { get; set; }
    }
}";

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <TextBlock Text=\"FALLBACK_Property1\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"FALLBACK_Property2\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"FOOBAR_Property5\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"FOOBAR_Property6\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void GetStructAllPropertyOptions()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping = "StackPanel";
            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<String Name=\"$name$\" />",
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "integer",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<Int Name=\"$name$\" />",
            });

            var code = @"
Namespace tests
    Structure Str☆uctViewModel
        Public Property Property1 As String
        Public Property Property2 As Integer
    End Structure
End Namespace";

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <String Name=\"Property1\" />"
                                 + Environment.NewLine + "    <Int Name=\"Property2\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "StructViewModel",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void CorrectlyInferViewModelNameSpace()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ViewGeneration.ViewModelDirectoryName = "VMS";

            var sut = new SetDataContextCommandLogic(
                profile,
                DefaultTestLogger.Create(),
                new TestVisualStudioAbstraction
            {
                ActiveProject = new ProjectWrapper {
                    Name = "TestApp"
                },
            },
                new TestFileSystem());

            var(_, _, vmNamespace) = sut.InferViewModelNameFromFileName("Test.xaml.cs");

            Assert.AreEqual("TestApp.VMS", vmNamespace);
        }
        public void MappingSupportsGenericTypeInVBAndCSFormats()
        {
            var profile = TestProfile.CreateEmpty();

            profile.SubPropertyOutput = "<DymnProp Value=\"$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "List<Int>",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<Int />",
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "List(Of String)",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<String />",
            });

            var code = @"
namespace tests
{
    class Class1
    {
        ☆public List<Int> SomeInts { get; set; }
        public List<String> SomeStrings { get; set; }☆
    }
}";

            var expected = new AnalyzerOutput
            {
                Name   = "SomeInts and SomeStrings",
                Output = "<Int />" + Environment.NewLine
                         + "<String />",
                OutputType = AnalyzerOutputType.Selection,
            };

            this.SelectionBetweenStarsShouldProduceExpected(code, expected, profile);
        }
Beispiel #8
0
        public void DetectsWhenPageContentIsAlreadySet()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ViewGeneration.XamlFileSuffix      = "Page";
            profile.ViewGeneration.ViewModelFileSuffix = "ViewModel";
            profile.Datacontext.CodeBehindPageContent  = @"Public ReadOnly Property ViewModel As $viewmodelclass$
    Get
        Return New $viewmodelclass$
    End Get
End Property";

            var logger = DefaultTestLogger.Create();

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "TestPage.xaml.vb",
                ActiveDocumentText     = @"Public NotInheritable Class TestPage
    Inherits Page

    Sub New()
        InitializeComponent()
    End Sub

    Public ReadOnly Property ViewModel As TestViewModel
        Get
            Return New TestViewModel
        End Get
    End Property
End Class",
            };

            var fs = new TestFileSystem();

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var result = sut.ShouldEnableCommand();

            Assert.IsFalse(result);
        }
Beispiel #9
0
        public void CanDetectWhereAndWhenToInsertConstructorContentAndConstructorExists()
        {
            var profile = TestProfile.CreateEmpty();

            profile.Datacontext.CodeBehindConstructorContent = "DataContext = ViewModel";

            var logger = DefaultTestLogger.Create();

            var fs = new TestFileSystem
            {
                FileText = @"Public NotInheritable Class TestPage
    Inherits Page

    Sub New()
        InitializeComponent()
    End Sub
End Class",
            };

            var synTree = VisualBasicSyntaxTree.ParseText(fs.FileText);

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "TestPage.xaml.vb",
                ActiveDocumentText     = fs.FileText,
                SyntaxTree             = synTree,
                DocumentIsCSharp       = false,
            };

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var(anythingToAdd, lineNoToAddAfter, contentToAdd, constructorAdded)
                = sut.GetCodeBehindConstructorContentToAdd(vs.ActiveDocumentText, vs.SyntaxTree.GetRoot(), "TestPage", "TestViewModel");

            Assert.IsTrue(anythingToAdd);
            Assert.AreEqual(5, lineNoToAddAfter);
            Assert.AreEqual($"{Environment.NewLine}{Environment.NewLine}DataContext = ViewModel", contentToAdd);
            Assert.IsFalse(constructorAdded);
        }
        public void CanDetectWhereAndWhenToInsertConstructorContentAndConstructorExists()
        {
            var profile = TestProfile.CreateEmpty();

            profile.Datacontext.CodeBehindConstructorContent = "this.DataContext = this.ViewModel;";

            var logger = DefaultTestLogger.Create();

            var fs = new TestFileSystem
            {
                FileText = @"class TestPage
{
    public TestPage()
    {
        this.Initialize();
    }
}",
            };

            var synTree = CSharpSyntaxTree.ParseText(fs.FileText);

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "test.xaml.cs",
                ActiveDocumentText     = fs.FileText,
                SyntaxTree             = synTree,
                DocumentIsCSharp       = true,
            };

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var(anythingToAdd, lineNoToAddAfter, contentToAdd, constructorAdded)
                = sut.GetCodeBehindConstructorContentToAdd(vs.ActiveDocumentText, vs.SyntaxTree.GetRoot(), "TestPage", "TestViewModel");

            Assert.IsTrue(anythingToAdd);
            Assert.AreEqual(5, lineNoToAddAfter);
            Assert.AreEqual($"{Environment.NewLine}{Environment.NewLine}this.DataContext = this.ViewModel;", contentToAdd);
            Assert.IsFalse(constructorAdded);
        }
        public void GetSelectionOfStructProperties()
        {
            var profile = TestProfile.CreateEmpty();

            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<String Name=\"$name$\" />",
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "integer",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<Int Name=\"$name$\" />",
            });

            var code = @"
Namespace tests
    Structure StructViewModel
        ☆Public Property Property1 As String
        Public Property Property2 As Integer☆
    End Structure
End Namespace";

            var expectedOutput = "<String Name=\"Property1\" />"
                                 + Environment.NewLine + "<Int Name=\"Property2\" />";

            var expected = new ParserOutput
            {
                Name       = "Property1 and Property2",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Selection,
            };

            this.SelectionBetweenStarsShouldProduceExpected(code, expected, profile);
        }
Beispiel #12
0
        public void MappingSupportsGenericTypeInVBAndCSFormats()
        {
            var profile = TestProfile.CreateEmpty();

            profile.SubPropertyOutput = "<DymnProp Value=\"$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "List<Int>",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<Int />",
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "List(Of String)",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<String />",
            });

            var code = @"
Namespace tests
    Class Class1
        *Public Property SomeInts As List(Of int)
        Public Property SomeStrings As List(Of String)*
    End Class
End Namespace";

            var expected = new AnalyzerOutput
            {
                Name       = "SomeInts and SomeStrings",
                Output     = @"<Int />
<String />",
                OutputType = AnalyzerOutputType.Selection,
            };

            this.SelectionBetweenStarsShouldProduceExpected(code, expected, profile);
        }
        // This is based on GetVisualBasicClassTests.GetClassWithAllTheProperties
        private void GetNameAndType(string property, string xaml)
        {
            var code = @"
Namespace tests
    Public Class TestClass
        ☆" + property + @"
    EndClass
End Namespace";

            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "<TextBlock Name=\"$name$\" Type=\"$type$\" />";

            var expected = new ParserOutput
            {
                Name       = "IgNoRe",
                Output     = xaml,
                OutputType = ParserOutputType.Member,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
Beispiel #14
0
        public void GetClassWithDynamicListProperty()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping     = "form";
            profile.SubPropertyOutput = "<DymnProp Value=\"$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "List<dynamic>",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<Dyno>$subprops$</Dyno>",
            });

            var code = @"
namespace tests
{
    *class Class1
    {*
        public List<dynamic> SomeList { get; set; }
    }
}";

            // A single "DymnProp" with no value indicates that no sub-properties of the dynamic type were found
            var expected = new AnalyzerOutput
            {
                Name       = "Class1",
                Output     = @"<form>
<Dyno>
<DymnProp Value="""" />
</Dyno>
</form>",
                OutputType = AnalyzerOutputType.Class,
            };

            this.EachPositionBetweenStarsShouldProduceExpected(code, expected, profile);
        }
        public void GetDynamicListProperty()
        {
            var profile = TestProfile.CreateEmpty();

            profile.SubPropertyOutput = "<DymnProp Value=\"$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "List<dynamic>",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<Dyno>$subprops$</Dyno>",
            });

            var code = @"
namespace tests
{
    class Class1
    {
        ☆public List<dynamic> SomeList { get; set; }☆
    }
}";

            var expectedXaml = "<Dyno>"
                               + Environment.NewLine + "    <DymnProp Value=\"\" />"
                               + Environment.NewLine + "</Dyno>";

            // A single "DymnProp" with no value indicates that no sub-properties of the dynamic type were found
            var expected = new ParserOutput
            {
                Name       = "SomeList",
                Output     = expectedXaml,
                OutputType = ParserOutputType.Property,
            };

            this.EachPositionBetweenStarsShouldProduceExpected(code, expected, profile);
        }
        public void GetStructProperty()
        {
            var profile = TestProfile.CreateEmpty();

            profile.Mappings.Add(new Mapping
            {
                Type         = "MyStruct",
                IfReadOnly   = false,
                NameContains = string.Empty,
                Output       = "<MyStruct />",
            });

            var code = @"
namespace tests
{
    class Class1
    {
        *public MyStruct Property2 { get; set; }*
    }

    struct MyStruct
    {
        public string MyProperty1 { get; set; }
        public int MyProperty2 { get; set; }
    }
}";

            var expected = new AnalyzerOutput
            {
                Name       = "Property2",
                Output     = "<MyStruct />",
                OutputType = AnalyzerOutputType.Property,
            };

            this.EachPositionBetweenStarsShouldProduceExpected(code, expected, profile);
        }
        public void GetAttributedTypeAndReadOnlyCombinations()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "<TextBlock Text=\"FALLBACK_$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                NameContains = "",
                Output       = "<TextBlock Text=\"STRING_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                NameContains = "",
                Output       = "<TextBlock Text=\"STRING_RO_$name$\" />",
                IfReadOnly   = true,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]string",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_STRING_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]string",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_STRING_RO_$name$\" />",
                IfReadOnly   = true,
            });

            var code = @"
Namespace tests
    Class Class1☆
        <Hidden>
        Public Property Property1 As String
        <Hidden>
        Public ReadOnly Property Property2 As String
        <Hidden>
        Public Property Property3 As String
        <Hidden>
        Public ReadOnly Property Property4 As String
    End Class
End Namespace";

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_Property1\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_RO_Property2\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_Property3\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_RO_Property4\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void GetClassAllAttributedTypeCombinations()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "<TextBlock Text=\"FALLBACK_$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                NameContains = "",
                Output       = "<TextBlock Text=\"STRING_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "T",
                NameContains = "",
                Output       = "<TextBlock Text=\"T_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "object",
                NameContains = "",
                Output       = "<TextBlock Text=\"OBJECT_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]T",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_T_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]string",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_STRING_$name$\" />",
                IfReadOnly   = false,
            });

            var code = @"
namespace tests
{
    class Class1☆
    {
        public string Property1 { get; set; }
        public int Property2 { get; set; }
        public object Property3 { get; set; }
        public double Property4 { get; set; }
        [Hidden]
        public string Property5 { get; set; }
        [Hidden]
        public int Property6 { get; set; }
        [Hidden]
        public object Property7 { get; set; }
        [Hidden]
        public double Property8 { get; set; }
        [Awesome]
        public string Property9 { get; set; }
        [Awesome]
        public int Property10 { get; set; }
    }
}";

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <TextBlock Text=\"STRING_Property1\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"T_Property2\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"OBJECT_Property3\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"T_Property4\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_Property5\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_T_Property6\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_T_Property7\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_T_Property8\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"STRING_Property9\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"T_Property10\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void CheckConstructorRequiredParam_VS()
        {
            var profile = TestProfile.CreateEmpty();

            var sut = new DropHandlerLogic(DefaultTestLogger.Create(), null);
        }
        public void GetAttributedTypeAndReadOnlyCombinations()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "<TextBlock Text=\"FALLBACK_$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                NameContains = "",
                Output       = "<TextBlock Text=\"STRING_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                NameContains = "",
                Output       = "<TextBlock Text=\"STRING_RO_$name$\" />",
                IfReadOnly   = true,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]string",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_STRING_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]string",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_STRING_RO_$name$\" />",
                IfReadOnly   = true,
            });

            var code = @"
namespace tests
{
    class Class1☆
    {
        [Hidden]
        public string Property1 { get; set; }
        [Hidden]
        public string Property2 { get; private set; }
        [Hidden]
        public string Property3 { get; set; }
        [Hidden]
        public string Property4 { get; private set; }
    }
}";

            // Note that property1 test does not start "STRING_" because the mapping with an attribute takes priority over the one without.
            // Note that property2 test does not start "STRING2_" because the attribute/Type mapping takes priority over name.
            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_Property1\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_RO_Property2\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_Property3\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_RO_Property4\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void FallbackIsNotUsedForMethods()
        {
            var code = @"
Namespace tests
    Class Class1☆
        Public Sub New()
            ' Constructor is a method but shouldn't match anything
        End Sub

        Public Sub OnPhotoTaken(ByVal args As CameraControlEventArgs)
        End Sub

        Public Sub ZoomIn()
            Return _zoomService?.ZoomIn()
        End Sub

        Public Sub Undo()
        End Sub

        Public Async Sub SwitchTheme(ByVal theme As ElementTheme)
        End Sub

        Public Async Sub Redo()
        End Sub

        Public Sub MethodName(ByVal name As String, ByVal amount As Integer)
        End Sub

        Private Sub DoNotMatchBecausePrivate()
        End Sub

        Public Function DoNotMatchBecauseOfReturnType() As Integer
        End Function

        Friend Sub DoNotMatchBecauseInternal()
        End Sub

        Protected Sub DoNotMatchBecauseProtected()
        End Sub

        Public Sub DoNotMatchAsGeneric(Of T)()
        End Sub
    End Class
End Namespace
";

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "<DoNotOutputForMethods />";
            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void FilterMethodsByName()
        {
            var code = @"
Namespace tests
    Class Class1☆
        Public Sub OnPhotoTaken(ByVal args As CameraControlEventArgs)
        End Sub

        Public Sub ZoomIn()
            Return _zoomService?.ZoomIn()
        End Sub

        Public Sub Undo()
        End Sub

        Public Async Sub SwitchTheme(ByVal theme As ElementTheme)
        End Sub

        Public Async Sub Redo()
        End Sub

        Public Sub MethodName(ByVal name As String, ByVal amount As Integer)
        End Sub

        Public Async Sub OtherMethodNamez(ByVal name As String, ByVal amount As Integer)
        End Sub
    End Class
End Namespace
";

            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "$nooutput$";
            profile.Mappings.Add(new Mapping
            {
                Type         = "method()",
                NameContains = "e",
                Output       = "<TextBlock Text=\"NOPARAMS_$method$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T)",
                NameContains = "e",
                Output       = "<TextBlock Text=\"ONEPARAM_$method$_$arg1$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T,T)",
                NameContains = "z",
                Output       = "<TextBlock Text=\"TWOPARAMS_$method$_$arg1$_$arg2$\" />",
                IfReadOnly   = false,
            });

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_OnPhotoTaken_args\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_SwitchTheme_theme\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_Redo\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"TWOPARAMS_OtherMethodNamez_name_amount\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void MethodOutputCanBeInGrid_TwoColumns()
        {
            var code = @"
Namespace tests
    Class Class1☆
        Public Sub OnPhotoTaken(ByVal args As CameraControlEventArgs)
        End Sub

        Public Sub ZoomIn()
            Return _zoomService?.ZoomIn()
        End Sub

        Public Sub Undo()
        End Sub

        Public Async Sub SwitchTheme(ByVal theme As ElementTheme)
        End Sub

        Public Async Sub Redo()
        End Sub

        Public Sub MethodName(ByVal name As String, ByVal amount As Integer)
        End Sub
    End Class
End Namespace";

            var expectedOutput = "<Grid>"
                                 + Environment.NewLine + "    <Grid.ColumnDefinitions>"
                                 + Environment.NewLine + "        <ColumnDefinition Width=\"Auto\" />"
                                 + Environment.NewLine + "        <ColumnDefinition Width=\"*\" />"
                                 + Environment.NewLine + "    </Grid.ColumnDefinitions>"
                                 + Environment.NewLine + "    <Grid.RowDefinitions>"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"*\" />"
                                 + Environment.NewLine + "    </Grid.RowDefinitions>"
                                 + Environment.NewLine + "    <Lbl Grid.Column=\"0\" Grid.Row=\"0\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_OnPhotoTaken_args\" Grid.Column=\"1\" Grid.Row=\"0\" />"
                                 + Environment.NewLine + "    <Lbl Grid.Column=\"0\" Grid.Row=\"1\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_ZoomIn\" Grid.Column=\"1\" Grid.Row=\"1\" />"
                                 + Environment.NewLine + "    <Lbl Grid.Column=\"0\" Grid.Row=\"2\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_Undo\" Grid.Column=\"1\" Grid.Row=\"2\" />"
                                 + Environment.NewLine + "    <Lbl Grid.Column=\"0\" Grid.Row=\"3\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_SwitchTheme_theme\" Grid.Column=\"1\" Grid.Row=\"3\" />"
                                 + Environment.NewLine + "    <Lbl Grid.Column=\"0\" Grid.Row=\"4\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_Redo\" Grid.Column=\"1\" Grid.Row=\"4\" />"
                                 + Environment.NewLine + "    <Lbl Grid.Column=\"0\" Grid.Row=\"5\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"TWOPARAMS_MethodName_name_amount\" Grid.Column=\"1\" Grid.Row=\"5\" />"
                                 + Environment.NewLine + "</Grid>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping = "GRID-PLUS-ROWDEFS-2COLS";
            profile.Mappings.Add(new Mapping
            {
                Type         = "method()",
                NameContains = "",
                Output       = "<Lbl Grid.Column=\"0\" Grid.Row=\"$incint$\" /><TextBlock Text=\"NOPARAMS_$method$\" Grid.Column=\"1\" Grid.Row=\"$repint$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T)",
                NameContains = "",
                Output       = "<Lbl Grid.Column=\"0\" Grid.Row=\"$incint$\" /><TextBlock Text=\"ONEPARAM_$method$_$arg1$\" Grid.Column=\"1\" Grid.Row=\"$repint$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T,T)",
                NameContains = "",
                Output       = "<Lbl Grid.Column=\"0\" Grid.Row=\"$incint$\" /><TextBlock Text=\"TWOPARAMS_$method$_$arg1$_$arg2$\" Grid.Column=\"1\" Grid.Row=\"$repint$\" />",
                IfReadOnly   = false,
            });

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
        public void CanDetectWhereAndWhenToInsertConstructorAndPageContentWhenConstructorDoesNotExist()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ViewGeneration.XamlFileSuffix            = "Page";
            profile.ViewGeneration.ViewModelFileSuffix       = "ViewModel";
            profile.Datacontext.CodeBehindConstructorContent = "this.DataContext = this.ViewModel;";
            profile.Datacontext.DefaultCodeBehindConstructor = @"public $viewclass$()
{
    this.Initialize();
}";
            profile.Datacontext.CodeBehindPageContent        = @"public $viewmodelclass$ ViewModel
{
    get
    {
        return new $viewmodelclass$();
    }
}";

            var logger = DefaultTestLogger.Create();

            var fs = new TestFileSystem
            {
                FileText = @"class TestPage
{
}",
            };

            var synTree = CSharpSyntaxTree.ParseText(fs.FileText);

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "TestPage.xaml.cs",
                ActiveDocumentText     = fs.FileText,
                SyntaxTree             = synTree,
                DocumentIsCSharp       = true,
            };

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var documentRoot = synTree.GetRoot();

            var result = sut.GetCodeBehindContentToAdd("TestPage", "TestViewModel", "TestVmNamespace", documentRoot);

            var expectedContent0 = @"
public TestPage()
{
    this.Initialize();

this.DataContext = this.ViewModel;
}
";

            Assert.IsTrue(result[0].anythingToAdd);
            Assert.AreEqual(2, result[0].lineNoToAddAfter);
            Assert.AreEqual(expectedContent0, result[0].contentToAdd);

            var expectedContent1 = @"

public TestViewModel ViewModel
{
    get
    {
        return new TestViewModel();
    }
}";

            Assert.IsTrue(result[1].anythingToAdd);
            Assert.AreEqual(8, result[1].lineNoToAddAfter);
            Assert.AreEqual(expectedContent1, result[1].contentToAdd);
        }
Beispiel #25
0
        public void MethodOutputCanBeInGrid_OneColumn()
        {
            var code = @"
namespace tests
{
    class Class1☆
    {
        public void OnPhotoTaken(CameraControlEventArgs args) { }

        public void ZoomIn() => _zoomService?.ZoomIn();

        public void Undo() {  }

        public async void SwitchTheme(ElementTheme theme) { }

        public async void Redo() {  }

        public void MethodName(string name, int amount) { }
    }
}";

            var expectedOutput = "<Grid>"
                                 + Environment.NewLine + "    <Grid.RowDefinitions>"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"Auto\" />"
                                 + Environment.NewLine + "        <RowDefinition Height=\"*\" />"
                                 + Environment.NewLine + "    </Grid.RowDefinitions>"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_OnPhotoTaken_args\" Grid.Row=\"0\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_ZoomIn\" Grid.Row=\"1\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_Undo\" Grid.Row=\"2\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_SwitchTheme_theme\" Grid.Row=\"3\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_Redo\" Grid.Row=\"4\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"TWOPARAMS_MethodName_name_amount\" Grid.Row=\"5\" />"
                                 + Environment.NewLine + "</Grid>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping = "GRID-PLUS-ROWDEFS";
            profile.Mappings.Add(new Mapping
            {
                Type         = "method()",
                NameContains = "",
                Output       = "<TextBlock Text=\"NOPARAMS_$method$\" Grid.Row=\"$incint$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T)",
                NameContains = "",
                Output       = "<TextBlock Text=\"ONEPARAM_$method$_$arg1$\" Grid.Row=\"$incint$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T,T)",
                NameContains = "",
                Output       = "<TextBlock Text=\"TWOPARAMS_$method$_$arg1$_$arg2$\" Grid.Row=\"$incint$\" />",
                IfReadOnly   = false,
            });

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
Beispiel #26
0
        public void FilterMethodsByName()
        {
            var code = @"
namespace tests
{
    class Class1☆
    {
        public void OnPhotoTaken(CameraControlEventArgs args) { }

        public void ZoomIn() => _zoomService?.ZoomIn();

        public void Undo() {  }

        public async void SwitchTheme(ElementTheme theme) { }

        public async void Redo() {  }

        public void MethodName(string name, int amount) { }

        public async void OtherMethodNamez(string name, int amount) { }
    }
}";

            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "$nooutput$";
            profile.Mappings.Add(new Mapping
            {
                Type         = "method()",
                NameContains = "e",
                Output       = "<TextBlock Text=\"NOPARAMS_$method$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T)",
                NameContains = "e",
                Output       = "<TextBlock Text=\"ONEPARAM_$method$_$arg1$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "method(T,T)",
                NameContains = "z",
                Output       = "<TextBlock Text=\"TWOPARAMS_$method$_$arg1$_$arg2$\" />",
                IfReadOnly   = false,
            });

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_OnPhotoTaken_args\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"ONEPARAM_SwitchTheme_theme\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"NOPARAMS_Redo\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"TWOPARAMS_OtherMethodNamez_name_amount\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }
Beispiel #27
0
        public void CanDetectWhereAndWhenToInsertConstructorAndPageContentWhenConstructorDoesNotExist()
        {
            var defaultConstructor = "Sub New()"
                                     + Environment.NewLine + "    InitializeComponent()"
                                     + Environment.NewLine + "End Sub";

            var pageContent = "Public ReadOnly Property ViewModel As $viewmodelclass$"
                              + Environment.NewLine + "    Get"
                              + Environment.NewLine + "        Return New $viewmodelclass$"
                              + Environment.NewLine + "    End Get"
                              + Environment.NewLine + "End Property";

            var profile = TestProfile.CreateEmpty();

            profile.ViewGeneration.XamlFileSuffix            = "Page";
            profile.ViewGeneration.ViewModelFileSuffix       = "ViewModel";
            profile.Datacontext.CodeBehindConstructorContent = "DataContext = ViewModel";
            profile.Datacontext.DefaultCodeBehindConstructor = defaultConstructor;
            profile.Datacontext.CodeBehindPageContent        = pageContent;

            var logger = DefaultTestLogger.Create();

            var fs = new TestFileSystem
            {
                FileText = @"Public NotInheritable Class TestPage
    Inherits Page

End Class",
            };

            var synTree = VisualBasicSyntaxTree.ParseText(fs.FileText);

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "TestPage.xaml.vb",
                ActiveDocumentText     = fs.FileText,
                SyntaxTree             = synTree,
                DocumentIsCSharp       = false,
            };

            var sut = new SetDataContextCommandLogic(profile, logger, vs, fs);

            var documentRoot = synTree.GetRoot();

            var result = sut.GetCodeBehindContentToAdd("TestPage", "TestViewModel", "TestVmNamespace", documentRoot);

            var expectedContent0 = ""
                                   + Environment.NewLine + "Sub New()"
                                   + Environment.NewLine + "    InitializeComponent()"
                                   + Environment.NewLine + ""
                                   + Environment.NewLine + "DataContext = ViewModel"
                                   + Environment.NewLine + "End Sub"
                                   + Environment.NewLine + "";

            Assert.IsTrue(result[0].anythingToAdd);
            Assert.AreEqual(2, result[0].lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent0, result[0].contentToAdd);

            var expectedContent1 = ""
                                   + Environment.NewLine + ""
                                   + Environment.NewLine + "Public ReadOnly Property ViewModel As TestViewModel"
                                   + Environment.NewLine + "    Get"
                                   + Environment.NewLine + "        Return New TestViewModel"
                                   + Environment.NewLine + "    End Get"
                                   + Environment.NewLine + "End Property";

            Assert.IsTrue(result[1].anythingToAdd);
            Assert.AreEqual(7, result[1].lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent1, result[1].contentToAdd);
        }
        public void GetClassAllAttributedTypeCombinations()
        {
            var profile = TestProfile.CreateEmpty();

            profile.ClassGrouping  = "StackPanel";
            profile.FallbackOutput = "<TextBlock Text=\"FALLBACK_$name$\" />";
            profile.Mappings.Add(new Mapping
            {
                Type         = "string",
                NameContains = "",
                Output       = "<TextBlock Text=\"STRING_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "T",
                NameContains = "",
                Output       = "<TextBlock Text=\"T_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "object",
                NameContains = "",
                Output       = "<TextBlock Text=\"OBJECT_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]T",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_T_$name$\" />",
                IfReadOnly   = false,
            });
            profile.Mappings.Add(new Mapping
            {
                Type         = "[Hidden]string",
                NameContains = "",
                Output       = "<TextBlock Text=\"HIDDEN_STRING_$name$\" />",
                IfReadOnly   = false,
            });

            var code = @"
Namespace tests
    Class Class1☆
        Public Property Property1 As String
        Public Property Property2 As Integer
        Public Property Property3 As Object
        Public Property Property4 As Double
        <Hidden>
        Public Property Property5 As String
        <Hidden>
        Public Property Property6 As Integer
        <Hidden>
        Public Property Property7 As Object
        <Hidden>
        Public Property Property8 As Double
        <Awesome>
        Public Property Property9 As String
        <Awesome>
        Public Property Property10 As Integer
    End Class
End Namespace";

            var expectedOutput = "<StackPanel>"
                                 + Environment.NewLine + "    <TextBlock Text=\"STRING_Property1\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"T_Property2\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"OBJECT_Property3\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"T_Property4\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_STRING_Property5\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_T_Property6\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_T_Property7\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"HIDDEN_T_Property8\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"STRING_Property9\" />"
                                 + Environment.NewLine + "    <TextBlock Text=\"T_Property10\" />"
                                 + Environment.NewLine + "</StackPanel>";

            var expected = new ParserOutput
            {
                Name       = "Class1",
                Output     = expectedOutput,
                OutputType = ParserOutputType.Class,
            };

            this.PositionAtStarShouldProduceExpected(code, expected, profile);
        }