public void ResourceFileCollectionCSharpProject()
 {
     // Get Project object
     Project testProject = (Project)(extensibility.Solution.Projects.Item(3));
     IExtractResourceAction action = new GenericCSharpExtractResourceAction();
     ResourceFileCollection collection = new ResourceFileCollection(testProject, new FilterMethod(action.IsValidResourceFile));
     String[] names = new string[] { "Resource1.resx", "Test1.resx", "Resources.resx" };
     Assert.AreEqual(names.Length, collection.Count, Messages.ResourceFilesCountInvalid);
     foreach (string name in names)
     {
         Assert.IsNotNull(collection.GetResourceFile(name), Messages.ResourceFileNotFound);
     }
 }
 public void GetAllMatchesTest()
 {
     Project testProject = (Project)(extensibility.Solution.Projects.Item(1));
     Common.IExtractResourceAction action = new GenericCSharpExtractResourceAction();
     ResourceFileCollection collection = new ResourceFileCollection(testProject, new FilterMethod(action.IsValidResourceFile));
     ResourceFile testFile = collection["Resource1.resx"];
     Collection<ResourceMatch> matches = testFile.GetAllMatches("Test");
     foreach (ResourceMatch m in matches)
     {
         if (m.Percentage == StringMatch.ExactMatch)
         {
             Assert.AreEqual("TestResource", m.ResourceName, "Did not match to expected resource entry");
             Assert.AreEqual("Test", m.Value, "Value does not match the string searched");
         }
     }
 }
 public void ResourceFileReadAfterRefreshWithoutSave()
 {
     Project testProject = (Project)(extensibility.Solution.Projects.Item(1));
     IExtractResourceAction action = new GenericCSharpExtractResourceAction();
     ResourceFileCollection collection = new ResourceFileCollection(testProject, new FilterMethod(action.IsValidResourceFile));
     ResourceFile testFile = collection[0];
     Assert.AreEqual(2, testFile.Resources.Count, Messages.ResourceCountInvalid);
     Assert.AreEqual("Test", testFile.GetValue("TestResource"), Messages.ResourceValueInvalid);
     testFile.AddResource("Test2", "Test3", "Comment Test");
     testFile.Refresh();
     Assert.AreEqual(2, testFile.Resources.Count, Messages.ResourceCountInvalid);
     Assert.AreEqual("Test", testFile.GetValue("TestResource"), Messages.ResourceValueInvalid);
 }
        public void ResourceFileReadAfterSave()
        {
            Project testProject = (Project)(extensibility.Solution.Projects.Item(1));
            IExtractResourceAction action = new GenericCSharpExtractResourceAction();
            ResourceFileCollection collection = new ResourceFileCollection(testProject, new FilterMethod(action.IsValidResourceFile));
            ResourceFile testFile = collection[1];
            FileAttributes attributes = File.GetAttributes(testFile.FileName);
            if (File.Exists(testFile.FileName + ".bak"))
            {
                File.SetAttributes(testFile.FileName + ".bak", attributes & ~FileAttributes.ReadOnly);
                File.Delete(testFile.FileName + ".bak");
            }
            File.Copy(testFile.FileName, testFile.FileName + ".bak");
            File.SetAttributes(testFile.FileName, attributes & ~FileAttributes.ReadOnly);
            File.SetAttributes(testFile.FileName + ".bak", attributes & ~FileAttributes.ReadOnly);
            try
            {
                Assert.AreEqual(1, testFile.Resources.Count, Messages.ResourceCountInvalid);
                Assert.AreEqual("Test", testFile.GetValue("TestString"), Messages.ResourceValueInvalid);
                testFile.AddResource("Test2", "Test3", "Comment Test");
                testFile.SaveFile();
                testFile.Refresh();
                Assert.AreEqual(2, testFile.Resources.Count, Messages.ResourceCountInvalid);
                Assert.AreEqual("Test", testFile.GetValue("TestString"), Messages.ResourceValueInvalid);
                Assert.AreEqual("Comment Test", testFile.Resources["TestString"].Comment, Messages.ResourceCommentInvalid);
                Assert.AreEqual("Test3", testFile.GetValue("Test2"), Messages.ResourceValueInvalid);
                Assert.AreEqual("Comment Test", testFile.Resources["Test2"].Comment, Messages.ResourceCommentInvalid);
            }
            finally
            {
                File.Delete(testFile.FileName);
                File.Move(testFile.FileName + ".bak", testFile.FileName);
                File.SetAttributes(testFile.FileName, attributes);

            }
        }
 public void ResourceFileMultipleAddsSameName()
 {
     Project testProject = (Project)(extensibility.Solution.Projects.Item(1));
     IExtractResourceAction action = new GenericCSharpExtractResourceAction();
     ResourceFileCollection collection = new ResourceFileCollection(testProject, new FilterMethod(action.IsValidResourceFile));
     ResourceFile testFile = collection[0];
     testFile.AddResource("Test2", "Test3", "Comment Test");
     testFile.AddResource("Test2", "TestTest", "Comment");
 }