public void CanDetectWhereAndWhenToInsertPageContentAndConstructorExists()
        {
            var pageContent = "public $viewmodelclass$ ViewModel"
      + Environment.NewLine + "{"
      + Environment.NewLine + "    get"
      + Environment.NewLine + "    {"
      + Environment.NewLine + "        return new $viewmodelclass$();"
      + Environment.NewLine + "    }"
      + Environment.NewLine + "}";

            var profile = TestProfile.CreateEmpty();
            profile.ViewGeneration.XamlFileSuffix = "Page";
            profile.ViewGeneration.ViewModelFileSuffix = "ViewModel";
            profile.Datacontext.CodeBehindPageContent = pageContent;

            var logger = DefaultTestLogger.Create();

            var fileText = "class TestPage"
   + Environment.NewLine + "{"
   + Environment.NewLine + "    public TestPage()"
   + Environment.NewLine + "    {"
   + Environment.NewLine + "        this.Initialize();"
   + Environment.NewLine + "    }"
   + Environment.NewLine + "}";

            var fs = new TestFileSystem
            {
                FileText = fileText,
            };

            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 (anythingToAdd, lineNoToAddAfter, contentToAdd)
                = sut.GetCodeBehindPageContentToAdd(vs.ActiveDocumentText, vs.SyntaxTree.GetRoot(), "TestViewModel", "TestVmNamespace");

            var expectedContent = ""
          + Environment.NewLine + ""
          + Environment.NewLine + "public TestViewModel ViewModel"
          + Environment.NewLine + "{"
          + Environment.NewLine + "    get"
          + Environment.NewLine + "    {"
          + Environment.NewLine + "        return new TestViewModel();"
          + Environment.NewLine + "    }"
          + Environment.NewLine + "}";

            Assert.IsTrue(anythingToAdd);
            Assert.AreEqual(6, lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent, contentToAdd);
        }
Пример #2
0
        public void CanDetectWhereAndWhenToInsertPageContentAndConstructorExists()
        {
            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.CodeBehindPageContent  = pageContent;

            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)
                = sut.GetCodeBehindPageContentToAdd(vs.ActiveDocumentText, vs.SyntaxTree.GetRoot(), "TestViewModel", "TestVmNamespace");

            var expectedContent = ""
                                  + 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(anythingToAdd);
            Assert.AreEqual(6, lineNoToAddAfter);
            StringAssert.AreEqual(expectedContent, contentToAdd);
        }