Example #1
0
        public void CanDetectWhereAndWhatToInsert()
        {
            var profile = TestProfile.CreateEmpty();

            profile.Datacontext.XamlPageAttribute = "DataContext=\"HasBeenSet\"";

            var logger = DefaultTestLogger.Create();

            var activeDocText = "<Page"
                                + Environment.NewLine + "    xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\""
                                + Environment.NewLine + "    >"
                                + Environment.NewLine + "    <!-- Content would go here -->"
                                + Environment.NewLine + "</Page>";

            var vs = new TestVisualStudioAbstraction
            {
                ActiveDocumentFileName = "test.xaml",
                ActiveDocumentText     = activeDocText,
            };

            var fs = new TestFileSystem();

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

            var result = sut.GetPageAttributeToAdd("TestViewModel", "Tests");

            Assert.IsTrue(result.anythingToAdd);
            Assert.AreEqual(2, result.lineNoToAddAfter);
            Assert.AreEqual($"{Environment.NewLine}    DataContext=\"HasBeenSet\"", result.contentToAdd);
        }