Beispiel #1
0
        static void TestSetCurrentValue(ResXFileType resXFileType, bool allowNoCodeGeneration, CodeDomProvider codeProvider, string initialCustomTool, string initialNamespace, string newCurrentValue, string expectedCustomTool, string expectedNamespace)
        {
            ResourceEditorRootDesigner designer = new ResourceEditorRootDesigner();
            ProjectItemFake            projectItem;

            projectItem = new ProjectItemWithCustomToolFake(initialCustomTool, initialNamespace);

            IServiceProvider sp = AccessModifierComboboxTests.CreateServiceProviderWithIVSMDCodeDomProvider(codeProvider);

            ResourceEditorView.ResourceEditorAccessModifierCombobox combo =
                new ResourceEditorView.ResourceEditorAccessModifierCombobox(
                    resXFileType == ResXFileType.DefaultResX,
                    allowNoCodeGeneration,
                    designer,
                    sp,
                    projectItem,
                    codeProvider is VBCodeProvider ? "My.Resources" : null
                    );
            Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor accessor =
                new Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor(combo);

            // Call the method under test
            accessor.SetCurrentValue(newCurrentValue);

            // Verify results
            Assert.AreEqual(expectedCustomTool, projectItem.Fake_PropertiesCollection.Item("CustomTool").Value);
            Assert.AreEqual(expectedNamespace, projectItem.Fake_PropertiesCollection.Item("CustomToolNamespace").Value);
        }
Beispiel #2
0
        private string GetPrefixByFileType(ResXFileType fileType)
        {
            var ret                 = "";
            var enumType            = typeof(ResXFileType);
            var memberInfos         = enumType.GetMember(fileType.ToString());
            var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == enumType);
            var valueAttributes     =
                enumValueMemberInfo.GetCustomAttributes(typeof(ResXFileTypeAttribute), false);

            foreach (var attribute in valueAttributes)
            {
                if (attribute is ResXFileTypeAttribute resxFileAttribute)
                {
                    ret = resxFileAttribute.Prefix;
                }
            }

            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// Adds a new file to the resource file.
        /// </summary>
        /// <param name="pathToFile">Path to the file.</param>
        /// <param name="fileType">The file type.</param>
        /// <param name="destinationDirectory">The directory where the file will be copied to.</param>
        public void AddFileResource(string pathToFile, ResXFileType fileType, string destinationDirectory)
        {
            if (!File.Exists(pathToFile))
            {
                throw new FileNotFoundException();
            }

            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(pathToFile);
            var fileName       = Path.GetFileName(pathToFile);
            var fileTypePrefix = GetPrefixByFileType(fileType);
            var newFilePath    = Path.Combine(destinationDirectory, fileName);
            var dataValue      = newFilePath + fileTypePrefix;

            if (!newFilePath.Equals(pathToFile))
            {
                File.Copy(pathToFile, newFilePath);
            }

            _resxRoot.Data.Add(new Data(fileNameWithoutExtension, dataValue, fileType));
        }
Beispiel #4
0
        static void TestIsEnabled(bool expectedIsEnabled, ResXFileType resXFileType, object initialCustomToolValue, bool supportCustomToolValueInProject, CodeDomProvider codeProvider)
        {
            if (resXFileType == ResXFileType.DefaultResX)
            {
                Assert.IsTrue(codeProvider == null || codeProvider is VBCodeProvider, "Problem in the unit test itself: don't pass in ResXFileType.DefaultResX except for VB");
            }

            ResourceEditorRootDesigner designer = new ResourceEditorRootDesigner();
            ProjectItemFake            projectItem;

            if (supportCustomToolValueInProject)
            {
                projectItem = new ProjectItemWithCustomToolFake(initialCustomToolValue);
            }
            else
            {
                projectItem = new ProjectItemFake();
            }

            IServiceProvider sp = AccessModifierComboboxTests.CreateServiceProviderWithIVSMDCodeDomProvider(codeProvider);

            ResourceEditorAccessModifierComboboxSubclass combo =
                new ResourceEditorAccessModifierComboboxSubclass(
                    true,
                    resXFileType == ResXFileType.DefaultResX,
                    !(resXFileType == ResXFileType.DefaultResX),
                    designer,
                    sp,
                    projectItem,
                    codeProvider is VBCodeProvider ? "My.Resources" : null
                    );
            Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor accessor =
                new Microsoft_VisualStudio_Editors_DesignerFramework_AccessModifierComboboxAccessor(combo);

            Assert.AreEqual(expectedIsEnabled, accessor.ShouldBeEnabled());
        }
Beispiel #5
0
 static void TestGetCurrentValue(string expectedCurrentValue, ResXFileType resXFileType, object initialCustomToolValue, bool supportCustomToolValueInProject, CodeDomProvider codeProvider)
 {
 }
Beispiel #6
0
 /// <summary>
 /// Adds a new file to the resource file.
 /// </summary>
 /// <param name="pathToFile">Path to the file.</param>
 /// <param name="fileType">The file type.</param>
 public void AddFileResource(string pathToFile, ResXFileType fileType)
 {
     AddFileResource(pathToFile, fileType, Path.GetDirectoryName(pathToFile));
 }
Beispiel #7
0
 public Data(string name, string value, ResXFileType fileType)
 {
     Name  = name;
     Value = value;
     Type  = "System.Resources.ResXFileRef, System.Windows.Forms";
 }