Example #1
0
        public void ResourcesNamespaceSpecialChars()
        {
            // ResourcesNamespace doesnt seem to be validated at all in .NET framework
            string []          unmatchables;
            string             input, output, expected;
            CodeCompileUnit    ccu;
            CodeMemberProperty resourceManager;
            CodeVariableDeclarationStatement cvds;

            foreach (char c in specialChars)
            {
                input = "test" + c.ToString();

                expected = input + ".TestClass";

                ccu = StronglyTypedResourceBuilder.Create(testResources,
                                                          "TestClass",
                                                          "TestNameSpace",
                                                          input,
                                                          provider,
                                                          true,
                                                          out unmatchables);

                resourceManager = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> (
                    "ResourceManager", ccu);
                cvds   = ((CodeVariableDeclarationStatement)((CodeConditionStatement)resourceManager.GetStatements [0]).TrueStatements [0]);
                output = ((CodePrimitiveExpression)((CodeObjectCreateExpression)cvds.InitExpression).Parameters [0]).Value.ToString();

                Assert.AreEqual(expected, output);
            }
        }
Example #2
0
        public void ResourcesNamespaceProviderKeywords()
        {
            // not validated against provider keywords in .net framework
            string output, expected;

            string []          unmatchables;
            CodeCompileUnit    ccu;
            CodeMemberProperty resourceManager;
            CodeVariableDeclarationStatement cvds;

            foreach (string input in keywords)
            {
                ccu = StronglyTypedResourceBuilder.Create(testResources,
                                                          "TestClass",
                                                          "TestNamespace",
                                                          input,
                                                          provider,
                                                          true,
                                                          out unmatchables);

                expected        = input + ".TestClass";
                resourceManager = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> (
                    "ResourceManager", ccu);
                cvds   = ((CodeVariableDeclarationStatement)((CodeConditionStatement)resourceManager.GetStatements [0]).TrueStatements [0]);
                output = ((CodePrimitiveExpression)((CodeObjectCreateExpression)cvds.InitExpression).Parameters [0]).Value.ToString();

                Assert.AreEqual(expected, output);
            }
        }
Example #3
0
        public void ResourcesNamespaceNull()
        {
            // when ResourcesNamespace is null generatedCodeNamespace is used in its place
            string[]           unmatchables;
            string             input, output, expected;
            CodeCompileUnit    ccu;
            CodeMemberProperty resourceManager;
            CodeVariableDeclarationStatement cvds;

            input = null;

            expected = "TestNameSpace.TestClass";

            ccu = StronglyTypedResourceBuilder.Create(testResources,
                                                      "TestClass",
                                                      "TestNameSpace",
                                                      input,
                                                      provider,
                                                      true,
                                                      out unmatchables);

            resourceManager = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> (
                "ResourceManager", ccu);
            cvds   = ((CodeVariableDeclarationStatement)((CodeConditionStatement)resourceManager.GetStatements [0]).TrueStatements [0]);
            output = ((CodePrimitiveExpression)((CodeObjectCreateExpression)cvds.InitExpression).Parameters [0]).Value.ToString();

            Assert.AreEqual(expected, output);
        }
        public void InternalClassFalse()
        {
            // check access modifiers for class, Culture, ResourceManager, string, stream and standard resource properties
            Dictionary <string, object> testResources = GetAllResourceTypes();

            string []          unmatchables;
            CodeCompileUnit    ccu;
            CodeMemberProperty cmp;

            bool isInternal = false;

            ccu = StronglyTypedResourceBuilder.Create(testResources,
                                                      "TestClass",
                                                      "TestNamespace",
                                                      "TestResourcesNameSpace",
                                                      provider,
                                                      isInternal,
                                                      out unmatchables);

            CodeTypeDeclaration resType = ccu.Namespaces [0].Types [0];

            Assert.IsTrue(resType.TypeAttributes == TypeAttributes.Public);

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> (
                "ResourceManager", ccu);
            Assert.IsTrue(cmp.Attributes == (MemberAttributes.Abstract
                                             | MemberAttributes.Final
                                             | MemberAttributes.FamilyAndAssembly
                                             | MemberAttributes.FamilyOrAssembly));

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> ("Culture", ccu);
            Assert.IsTrue(cmp.Attributes == (MemberAttributes.Abstract
                                             | MemberAttributes.Final
                                             | MemberAttributes.FamilyAndAssembly
                                             | MemberAttributes.FamilyOrAssembly));

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> ("astring", ccu);
            Assert.IsTrue(cmp.Attributes == (MemberAttributes.Abstract
                                             | MemberAttributes.Final
                                             | MemberAttributes.FamilyAndAssembly
                                             | MemberAttributes.FamilyOrAssembly));

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> ("bmp", ccu);
            Assert.IsTrue(cmp.Attributes == (MemberAttributes.Abstract
                                             | MemberAttributes.Final
                                             | MemberAttributes.FamilyAndAssembly
                                             | MemberAttributes.FamilyOrAssembly));

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> ("wav", ccu);
            Assert.IsTrue(cmp.Attributes == (MemberAttributes.Abstract
                                             | MemberAttributes.Final
                                             | MemberAttributes.FamilyAndAssembly
                                             | MemberAttributes.FamilyOrAssembly));
        }
Example #5
0
        public void ResxFileProcessed()
        {
            // resources in resx should be present in codecompileunit with correct property type
            string []       unmatchables;
            CodeCompileUnit ccu;

            Bitmap       bmp = new Bitmap(100, 100);
            MemoryStream wav = new MemoryStream(1000);

            string resxFileName = Path.GetTempFileName();

            using (ResXResourceWriter writer = new ResXResourceWriter(resxFileName)) {
                writer.AddResource("astring", "myvalue");                  // dont use key of "string" as its a keyword
                writer.AddResource("bmp", bmp);
                writer.AddResource("wav", wav);
                writer.Generate();
            }

            ccu = StronglyTypedResourceBuilder.Create(resxFileName,
                                                      "TestRes",
                                                      "TestNamespace",
                                                      "TestResourcesNameSpace",
                                                      provider,
                                                      true,
                                                      out unmatchables);

            CodeMemberProperty cmp;

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> ("astring", ccu);
            Assert.IsNotNull(cmp);
            Assert.AreEqual("System.String", cmp.Type.BaseType);

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> ("wav", ccu);
            Assert.IsNotNull(cmp);
            Assert.AreEqual("System.IO.UnmanagedMemoryStream", cmp.Type.BaseType);

            cmp = StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> ("bmp", ccu);
            Assert.IsNotNull(cmp);
            Assert.AreEqual("System.Drawing.Bitmap", cmp.Type.BaseType);

            wav.Close();
            File.Delete(resxFileName);
        }
Example #6
0
        public void ResourceNamesIgnored()
        {
            // names beginning with the chars "$" and ">>" ignored and not put in unmatchables
            Dictionary <string, object> testResources = new Dictionary <string, object>();

            string [] unmatchables;

            testResources.Add("$test1", String.Empty);
            testResources.Add("$test2", String.Empty);
            testResources.Add(">>test1", String.Empty);
            testResources.Add(">>test2", String.Empty);
            testResources.Add("$", String.Empty);
            testResources.Add(">>", String.Empty);
            testResources.Add(">", String.Empty);
            testResources.Add(">test1", String.Empty);
            testResources.Add("test>>", String.Empty);
            // resource name with $ somwhere else goes into unmatchables as invalid with csharpprovider

            CodeCompileUnit ccu = StronglyTypedResourceBuilder.Create(testResources,
                                                                      "TestRes",
                                                                      "TestNamespace",
                                                                      "TestResourcesNameSpace",
                                                                      provider,
                                                                      true,
                                                                      out unmatchables);

            Assert.AreEqual(0, unmatchables.Length);

            Assert.AreEqual(8, ccu.Namespaces [0].Types [0].Members.Count);             // 3 valid + 5 standard
            Assert.IsNotNull(StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> (
                                 "_", ccu));
            Assert.IsNotNull(StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> (
                                 "_test1", ccu));
            Assert.IsNotNull(StronglyTypedResourceBuilderCodeDomTest.Get <CodeMemberProperty> (
                                 "test__", ccu));
        }