Пример #1
0
        public void GenericCSharpReplaceMethodReadOnlyTest()
        {
            Assert.Throws <FileReadOnlyException>(() =>
            {
                // Get Project object
                Project testProject                 = (Project)(extensibility.Solution.Projects.Item(3));
                ProjectItem codeFile                = testProject.ProjectItems.Item("Program.cs");
                CSharpHardCodedString hcs           = new CSharpHardCodedString(codeFile, 19, 32);
                IExtractResourceAction actionObject = new Common.GenericCSharpExtractResourceAction();
                ResourceFileCollection resources    = new ResourceFileCollection(testProject, new FilterMethod(actionObject.IsValidResourceFile));

                ResourceFile resFile         = resources["Resource1.resx"];
                string fileName              = codeFile.get_FileNames(1);
                FileAttributes oldAttributes = System.IO.File.GetAttributes(fileName);
                System.IO.File.SetAttributes(fileName, oldAttributes | FileAttributes.ReadOnly);
                try
                {
                    ExtractToResourceActionSite refactorSite = new ExtractToResourceActionSite(hcs);
                    refactorSite.ExtractStringToResource(resFile, "Test");
                }
                finally
                {
                    System.IO.File.SetAttributes(fileName, oldAttributes);
                }
            });
        }
Пример #2
0
        public void VBWebsiteReplaceMethodTest()
        {
            // Get Project object
            Project             testProject = (Project)(extensibility.Solution.Projects.Item(4));
            ProjectItem         codeFile    = testProject.ProjectItems.Item("App_Code").ProjectItems.Item("Class1.vb");
            BaseHardCodedString hcs         = new CSharpHardCodedString(codeFile, 73, 86);

            TestReplaceMethod(codeFile, "Resource.resx", hcs, TestStrings.VBWebsiteTestString, "TestResource");
        }
Пример #3
0
        public void GenericCSharpReplaceMethodTest()
        {
            // Get Project object
            Project               testProject = (Project)(extensibility.Solution.Projects.Item(3));
            ProjectItem           codeFile    = testProject.ProjectItems.Item("Program.cs");
            CSharpHardCodedString hcs         = new CSharpHardCodedString(codeFile, 349, 362);

            TestReplaceMethod(codeFile, "Resource1.resx", hcs, TestStrings.CSharpReplaceTestExpectedLine, "Test");
        }
Пример #4
0
        public void CSharpWebsiteReplaceMethodTest()
        {
            // Get Project object
            Project             testProject = (Project)(extensibility.Solution.Projects.Item(4));
            ProjectItem         codeFile    = testProject.ProjectItems.Item("Default.aspx.cs");
            BaseHardCodedString hcs         = new CSharpHardCodedString(codeFile, 376, 389);

            TestReplaceMethod(codeFile, "Resource.resx", hcs, TestStrings.CSharpWebsiteTestString, "TestResource");
        }
        public void IndexGetterTests()
        {
            CSharpHardCodedString hcs = new CSharpHardCodedString(this.codeFile, 349, 362);
            TextDocument          doc = ((EnvDTE.TextDocument) this.codeFile.Document.Object(null));
            EditPoint             ep  = doc.StartPoint.CreateEditPoint();
            string text = ep.GetLines(17, 18);

            Assert.AreEqual(text.IndexOf("\"Test\\\"\\\"\\n\\t\""), hcs.StartIndex);
            Assert.AreEqual(15, hcs.StartingLine);
        }
Пример #6
0
        public void VBReplaceTestLocalResource()
        {
            // Get Project object
            Project     testProject = (Project)(extensibility.Solution.Projects.Item(2));
            ProjectItem codeFile    = testProject.ProjectItems.Item("Test.vb");

            CommonMethods.CloseDocument(codeFile);
            CSharpHardCodedString hcs = new CSharpHardCodedString(codeFile, 40, 46);

            ExtractResourceActionTests.TestReplaceMethod(codeFile, "LocalResource.resx", hcs, TestStrings.WebApplicationLocalTestStringVB, "Test");
        }
Пример #7
0
        public void CSharpReplaceTestGlobalResource()
        {
            // Get Project object
            Project     testProject = (Project)(extensibility.Solution.Projects.Item(1));
            ProjectItem codeFile    = testProject.ProjectItems.Item("Test.cs");

            CommonMethods.CloseDocument(codeFile);
            CSharpHardCodedString hcs = new CSharpHardCodedString(codeFile, 307, 313);

            ExtractResourceActionTests.TestReplaceMethod(codeFile, "Global.resx", hcs, TestStrings.WebApplicationGlobalTestStringCSharp, "Test");
        }
        public void ValueGetterTest()
        {
            CSharpHardCodedString hcs = new CSharpHardCodedString(this.codeFile, 349, 362);

            Assert.AreEqual("Test String", hcs.Value, "Simple string Value get failed");
            hcs = new CSharpHardCodedString(this.codeFile, 383, 397);
            Assert.AreEqual("Test\"\"\n\t", hcs.Value, "String with escape characters Value get failed");
            hcs = new CSharpHardCodedString(this.codeFile, 418, 432);
            Assert.AreEqual(@"Test String", hcs.Value, "Value property for simple verbatim string failed");
            hcs = new CSharpHardCodedString(this.codeFile, 453, 470);
            Assert.AreEqual(@"Test""String""", hcs.Value, "Value property for verbatim string with escaped quotes failed");
        }