コード例 #1
0
        public async Task FileJustContainsComments()
        {
            var profile = this.GetDefaultTestProfile();

            profile.ViewGeneration.AllInSameProject       = true;
            profile.ViewGeneration.ViewModelDirectoryName = "Files";
            profile.ViewGeneration.ViewModelFileSuffix    = "ViewModel";
            profile.ViewGeneration.XamlFileDirectoryName  = "Files";
            profile.ViewGeneration.XamlFileSuffix         = "Page";

            var fs = new TestFileSystem
            {
                FileExistsResponse = false,
                FileText           = @" ' Just comments in this file",
            };

            var synTree  = VisualBasicSyntaxTree.ParseText(fs.FileText);
            var semModel = VisualBasicCompilation.Create(string.Empty).AddSyntaxTrees(synTree).GetSemanticModel(synTree, ignoreAccessibility: true);

            var vsa = new TestVisualStudioAbstraction
            {
                SyntaxTree    = synTree,
                SemanticModel = semModel,
                ActiveProject = new ProjectWrapper()
                {
                    Name = "App", FileName = @"C:\Test\App\App.vbproj"
                },
            };

            var sut = new CreateViewCommandLogic(DefaultTestLogger.Create(), vsa, fs, profile);

            await sut.ExecuteAsync(@"C:\Test\App\Files\TestViewModel.vb");

            Assert.IsFalse(sut.CreateView);
        }
コード例 #2
0
        public async Task FileExistsAndDoNotOverwriteMeansNoNewFileCreatedAsync()
        {
            var profile = this.GetDefaultTestProfile();

            profile.ViewGeneration.AllInSameProject       = true;
            profile.ViewGeneration.ViewModelDirectoryName = "ViewModels";
            profile.ViewGeneration.ViewModelFileSuffix    = "ViewModel";
            profile.ViewGeneration.XamlFileDirectoryName  = "Views";
            profile.ViewGeneration.XamlFileSuffix         = "Page";

            var fs = new TestFileSystem
            {
                FileExistsResponse = true,
                FileText           = " public class TestViewModel { public string OnlyProperty { get; set;} }",
            };

            var synTree  = CSharpSyntaxTree.ParseText(fs.FileText);
            var semModel = CSharpCompilation.Create(string.Empty).AddSyntaxTrees(synTree).GetSemanticModel(synTree, ignoreAccessibility: true);

            var vsa = new TestVisualStudioAbstraction
            {
                UserConfirmsResult = false,
                SyntaxTree         = synTree,
                SemanticModel      = semModel,
                ActiveProject      = new ProjectWrapper()
                {
                    Name = "App", FileName = @"C:\Test\App\App.csproj"
                },
            };
            var sut = new CreateViewCommandLogic(profile, DefaultTestLogger.Create(), vsa, fs);

            await sut.ExecuteAsync(@"C:\Test\App\ViewModels\TestViewModel.cs");

            Assert.IsFalse(sut.CreateView);
        }
コード例 #3
0
        public async Task HandleFileNotContainingClassDefinition()
        {
            var profile = this.GetDefaultTestProfile();

            profile.ViewGeneration.AllInSameProject       = true;
            profile.ViewGeneration.ViewModelDirectoryName = "Files";
            profile.ViewGeneration.ViewModelFileSuffix    = "ViewModel";
            profile.ViewGeneration.XamlFileDirectoryName  = "Files";
            profile.ViewGeneration.XamlFileSuffix         = "Page";

            var fs = new TestFileSystem
            {
                FileExistsResponse = false,
                FileText           = " // There's nothing in this file apart from a comment",
            };

            var synTree  = CSharpSyntaxTree.ParseText(fs.FileText);
            var semModel = CSharpCompilation.Create(string.Empty).AddSyntaxTrees(synTree).GetSemanticModel(synTree, ignoreAccessibility: true);

            var vsa = new TestVisualStudioAbstraction
            {
                SyntaxTree    = synTree,
                SemanticModel = semModel,
                ActiveProject = new ProjectWrapper()
                {
                    Name = "App", FileName = @"C:\Test\App\App.csproj"
                },
            };

            var sut = new CreateViewCommandLogic(profile, DefaultTestLogger.Create(), vsa, fs);

            await sut.ExecuteAsync(@"C:\Test\App\Files\TestViewModel.cs");

            Assert.IsFalse(sut.CreateView);
        }
コード例 #4
0
        public async Task CorrectOutputInOtherProjectAsync()
        {
            var profile = this.GetDefaultTestProfile();

            profile.ViewGeneration.AllInSameProject = false;

            profile.ViewGeneration.XamlProjectSuffix      = string.Empty;
            profile.ViewGeneration.ViewModelProjectSuffix = ".ViewModels";

            profile.ViewGeneration.ViewModelDirectoryName = "";
            profile.ViewGeneration.ViewModelFileSuffix    = "ViewModel";
            profile.ViewGeneration.XamlFileDirectoryName  = "Views";
            profile.ViewGeneration.XamlFileSuffix         = "Page";

            var fs = new TestFileSystem
            {
                FileExistsResponse = false,
                FileText           = @"Public Class TestViewModel
    Public Property OnlyProperty As String
End Class",
            };

            var synTree  = VisualBasicSyntaxTree.ParseText(fs.FileText);
            var semModel = VisualBasicCompilation.Create(string.Empty).AddSyntaxTrees(synTree).GetSemanticModel(synTree, ignoreAccessibility: true);

            var vsa = new TestVisualStudioAbstraction
            {
                SyntaxTree    = synTree,
                SemanticModel = semModel,
                ActiveProject = new ProjectWrapper {
                    Name = "App.ViewModels", FileName = @"C:\Test\App.ViewModels\App.ViewModels.vbproj"
                },
                NamedProject = new ProjectWrapper {
                    Name = "App", FileName = @"C:\Test\App\App.vbproj"
                },
            };

            var sut = new CreateViewCommandLogic(DefaultTestLogger.Create(), vsa, fs, profile);

            await sut.ExecuteAsync(@"C:\Test\App.ViewModels\TestViewModel.vb");

            var expectedXaml = "<Page"
                               + Environment.NewLine + "    x:Class=\"App.Views.TestPage\">"
                               + Environment.NewLine + "    <Grid>"
                               + Environment.NewLine + "        <StackPanel>"
                               + Environment.NewLine + "            <TextBlock FB=\"True\" Text=\"OnlyProperty\" />"
                               + Environment.NewLine + "        </StackPanel>"
                               + Environment.NewLine + "    </Grid>"
                               + Environment.NewLine + "</Page>"
                               + Environment.NewLine + "";

            var expectedCodeBehind = "Imports System"
                                     + Environment.NewLine + "Imports Windows.UI.Xaml.Controls"
                                     + Environment.NewLine + "Imports App.ViewModels"
                                     + Environment.NewLine + ""
                                     + Environment.NewLine + "Namespace Views"
                                     + Environment.NewLine + ""
                                     + Environment.NewLine + "    Public NotInheritable Partial Class TestPage"
                                     + Environment.NewLine + "        Inherits Page"
                                     + Environment.NewLine + ""
                                     + Environment.NewLine + "        Public Property ViewModel As TestViewModel"
                                     + Environment.NewLine + ""
                                     + Environment.NewLine + "        Public Sub New()"
                                     + Environment.NewLine + "            Me.InitializeComponent()"
                                     + Environment.NewLine + "            Me.ViewModel = New TestViewModel()"
                                     + Environment.NewLine + "        End Sub"
                                     + Environment.NewLine + "    End Class"
                                     + Environment.NewLine + "End Namespace"
                                     + Environment.NewLine + "";

            Assert.IsTrue(sut.CreateView);
            Assert.AreEqual(@"C:\Test\App\Views\TestPage.xaml", sut.XamlFileName);
            Assert.AreEqual(@"C:\Test\App\Views\TestPage.xaml.vb", sut.CodeFileName);
            StringAssert.AreEqual(expectedXaml, sut.XamlFileContents);
            StringAssert.AreEqual(expectedCodeBehind, sut.CodeFileContents);
        }
コード例 #5
0
        public async Task CorrectOutputInSameFolderAsync()
        {
            var profile = this.GetDefaultTestProfile();

            profile.ViewGeneration.AllInSameProject       = true;
            profile.ViewGeneration.ViewModelDirectoryName = "Files";
            profile.ViewGeneration.ViewModelFileSuffix    = "ViewModel";
            profile.ViewGeneration.XamlFileDirectoryName  = "Files";
            profile.ViewGeneration.XamlFileSuffix         = "Page";

            var fs = new TestFileSystem
            {
                FileExistsResponse = false,
                FileText           = @"Public Class TestViewModel
    Public Property OnlyProperty As String
End Class",
            };

            var synTree  = VisualBasicSyntaxTree.ParseText(fs.FileText);
            var semModel = VisualBasicCompilation.Create(string.Empty).AddSyntaxTrees(synTree).GetSemanticModel(synTree, ignoreAccessibility: true);

            var vsa = new TestVisualStudioAbstraction
            {
                SyntaxTree    = synTree,
                SemanticModel = semModel,
                ActiveProject = new ProjectWrapper()
                {
                    Name = "App", FileName = @"C:\Test\App\App.vbproj"
                },
            };

            var sut = new CreateViewCommandLogic(profile, DefaultTestLogger.Create(), vsa, fs);

            await sut.ExecuteAsync(@"C:\Test\App\Files\TestViewModel.vb");

            var expectedXaml = @"<Page
    x:Class=""App.Files.TestPage"">
    <Grid>
        <StackPanel>
            <TextBlock FB=""True"" Text=""OnlyProperty"" />
        </StackPanel>
    </Grid>
</Page>
";

            var expectedCodeBehind = @"Imports System
Imports Windows.UI.Xaml.Controls
Imports App.Files

Namespace Files

    Public NotInheritable Partial Class TestPage
        Inherits Page

        Public Property ViewModel As TestViewModel

        Public Sub New()
            Me.InitializeComponent()
            Me.ViewModel = New TestViewModel()
        End Sub
    End Class
End Namespace
";

            Assert.IsTrue(sut.CreateView);
            Assert.AreEqual(@"C:\Test\App\Files\TestPage.xaml", sut.XamlFileName);
            Assert.AreEqual(@"C:\Test\App\Files\TestPage.xaml.vb", sut.CodeFileName);
            Assert.AreEqual(expectedXaml, sut.XamlFileContents);
            Assert.AreEqual(expectedCodeBehind, sut.CodeFileContents);
        }
コード例 #6
0
        public async Task CorrectOutputInSameProject()
        {
            var profile = this.GetDefaultTestProfile();

            profile.ViewGeneration.AllInSameProject       = true;
            profile.ViewGeneration.ViewModelDirectoryName = "ViewModels";
            profile.ViewGeneration.ViewModelFileSuffix    = "ViewModel";
            profile.ViewGeneration.XamlFileDirectoryName  = "Views";
            profile.ViewGeneration.XamlFileSuffix         = "Page";

            var fs = new TestFileSystem
            {
                FileExistsResponse = false,
                FileText           = " public class TestViewModel { public string OnlyProperty { get; set;} }",
            };

            var synTree  = CSharpSyntaxTree.ParseText(fs.FileText);
            var semModel = CSharpCompilation.Create(string.Empty).AddSyntaxTrees(synTree).GetSemanticModel(synTree, ignoreAccessibility: true);

            var vsa = new TestVisualStudioAbstraction
            {
                SyntaxTree    = synTree,
                SemanticModel = semModel,
                ActiveProject = new ProjectWrapper()
                {
                    Name = "App", FileName = @"C:\Test\App\App.csproj"
                },
            };

            var sut = new CreateViewCommandLogic(profile, DefaultTestLogger.Create(), vsa, fs);

            await sut.ExecuteAsync(@"C:\Test\App\ViewModels\TestViewModel.cs");

            var expectedXaml = @"<Page
    x:Class=""App.Views.TestPage"">
    <Grid>
        <StackPanel>
<TextBlock FB=""True"" Text=""OnlyProperty"" />
</StackPanel>
    </Grid>
</Page>
";

            var expectedCodeBehind = @"using System;
using Windows.UI.Xaml.Controls;
using App.ViewModels;

namespace App.Views
{
    public sealed partial class TestPage : Page
    {
        public TestViewModel ViewModel { get; set; }

        public TestPage()
        {
            this.InitializeComponent();
            this.ViewModel = new TestViewModel();
        }
    }
}
";

            Assert.IsTrue(sut.CreateView);
            Assert.AreEqual(@"C:\Test\App\Views\TestPage.xaml", sut.XamlFileName);
            Assert.AreEqual(@"C:\Test\App\Views\TestPage.xaml.cs", sut.CodeFileName);
            Assert.AreEqual(expectedXaml, sut.XamlFileContents);
            Assert.AreEqual(expectedCodeBehind, sut.CodeFileContents);
        }