public void TestResXToMcWithCategoryFacilityAndSource()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            //The name of the event source to register, can be qualified with log: "Log-Name/Event-Source"
            builder.Add(".EventSource", "Application/YourAppName");

            //OPTIONAL (default=0): The category id and name for the category of the message, should be unique for this ResX file 
            builder.Add(".EventCategory", 0x0F, "MyCategory");

            //OPTIONAL (default=0): The facility code (256-2047) and name to define for these messages
            builder.Add(".Facility", 258, "MyFacility");
            builder.Add("SimpleText", "Message Text", "#MessageId=1");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }

                string contents = mc.ReadAllText();
                Assert.IsTrue(contents.Contains("\r\nMessage Text\r\n."));

                //Facility defined
                Assert.IsTrue(new Regex(@"FACILITY_MYFACILITY\s*=\s*0x102").IsMatch(contents));
                //Category defined
                Assert.IsTrue(new Regex(@"SymbolicName\s*=\s*CATEGORY_MYCATEGORY").IsMatch(contents) && contents.Contains("\r\nMyCategory\r\n.\r\n"));
                //Facility used
                Assert.IsTrue(new Regex(@"Facility\s*=\s*FACILITY_MYFACILITY").IsMatch(contents));
                //Message defined
                Assert.IsTrue(contents.Contains("\r\nMessage Text\r\n."));
            }
        }
Пример #2
0
        public void TestCreateMessageAssembly()
        {
            /*
             * This is the most simple form of message generation in which we generate a complete dll with
             * the message resource (and optional versioning).  The dll includes the TestResXClass1.Constants.cs
             * and the TestResXClass1.InstallUtil.cs as generated in the example TestGenerateWin32Resource().
             */
            using (TempDirectory tmp = new TempDirectory())
                using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
                    using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
                        using (TempFile dllout = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.dll")))
                        {
                            asminfo.WriteAllText(AsminfoFormat);

                            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                            builder1.Add(".AutoLog", true);
                            builder1.Add(".EventSource", "HelloWorld");
                            builder1.Add("Value1", "value for 1", "#MessageId = 1");
                            builder1.BuildResX(resx1.TempPath);

                            Generators.Commands.ResXtoMessageDll(dllout.TempPath, new string[] { resx1.TempPath },
                                                                 tmp.TempPath, asminfo.TempPath, "TestNamespace", Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")), "/debug-");

                            Assert.IsTrue(dllout.Exists);
                        }
        }
        public void TestSimpleStringResXToMc()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder1.Add("Value1", "value for 1", "#MessageId = 1");
            TestResourceBuilder builder2 = new TestResourceBuilder("TestNamespace", "TestResXClass2");

            builder2.Add("Value2", "value for 2", "#MessageId = 2");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                    using (TempFile resx2 = TempFile.FromExtension(".resx"))
                    {
                        builder1.BuildResX(resx1.TempPath);
                        builder2.BuildResX(resx2.TempPath);
                        Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath, resx2.TempPath });
                    }

                string contents = mc.ReadAllText();

                Assert.IsTrue(contents.Contains("\r\nvalue for 1\r\n.\r\n"));
                Assert.IsTrue(contents.Contains("\r\nvalue for 2\r\n.\r\n"));
            }
        }
        public void TestFormatWithSuffixResXToMc()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder1.Add("WhatsUp(string s, int i)", "Format!%0\n\tstring={0},\n.\r\n\tnumber={1}.", "#messageId=23");
            builder1.Add(".EventMessageFormat", "Suffix\nTest {0} Format");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }

                string contents = mc.ReadAllText();
                Assert.IsTrue(contents.Contains(@"
Format%!%%0%n
	string=%2,%n
%.%n
	number=%3.%n
Suffix%n
Test %1 Format
"));
            }
        }
Пример #5
0
        public void TestProjectResXWithBadAssemblyInfo()
        {
            /* Bad assembly info... */
            using (TempDirectory tmp = new TempDirectory())
                using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
                    using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
                        using (TempFile csproj = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.csproj")))
                            using (TempFile manifest = TempFile.Attach(Path.Combine(tmp.TempPath, "App.manifest")))
                                using (TempFile appico = TempFile.Attach(Path.Combine(tmp.TempPath, "App.ico")))
                                {
                                    asminfo.WriteAllText(AsminfoFormat + "[InvalidAttribute]");
                                    csproj.WriteAllText(String.Format(ProjFormat, Path.GetFileName(resx1.TempPath)));
                                    manifest.WriteAllText(AppManifest);

                                    TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                                    builder1.Add(".AutoLog", true);
                                    builder1.Add(".EventSource", "HelloWorld");
                                    builder1.Add("Value1", "value for 1", "#MessageId = 1");
                                    builder1.BuildResX(resx1.TempPath);

                                    using (Stream s = appico.Open())
                                        Properties.Resources.App.Save(s);

                                    Generators.Commands.ProjectResX(csproj.TempPath, @"Resources\TestResXClass1", null, String.Empty, Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")));
                                }
        }
        public void TestSimpleResXLogEvent()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            string messageText = String.Format("NUnit {0} {1}", GetType(), Guid.NewGuid());
            //Enables the LOG feature to automagically generate log calls on all exception constructors.
            builder.Add(".AutoLog", true);
            builder.Add(".EventSource", "CSharpTest - NUnit");

            //If .NextMessageId is not defined you must specify one for logging to enable on that item.
            builder.Add("SimpleLog(string text)", "{0}", "#MessageId=1");

            TestResourceResult result = builder.Compile();

            Assert.AreEqual(messageText, result.GetValue("SimpleLog", messageText));

            using (EventLog applog = new EventLog("Application"))
            {
                EventLogEntry found = null;
                EventLogEntryCollection entries = applog.Entries;
                int stop = Math.Max(0, entries.Count - 50);
                for (int i = entries.Count - 1; i >= stop; i--)
                    if (entries[i].Message.Contains(messageText))
                    {
                        found = entries[i];
                        break;
                    }
                Assert.IsNotNull(found);
                Assert.AreEqual("CSharpTest - NUnit", found.Source);
                Assert.AreEqual(1, found.ReplacementStrings.Length);
                Assert.AreEqual(messageText, found.ReplacementStrings[0]);
            }
        }
        public void TestResXToMcWithCategoryFacilityAndSource()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            //The name of the event source to register, can be qualified with log: "Log-Name/Event-Source"
            builder.Add(".EventSource", "Application/YourAppName");

            //OPTIONAL (default=0): The category id and name for the category of the message, should be unique for this ResX file
            builder.Add(".EventCategory", 0x0F, "MyCategory");

            //OPTIONAL (default=0): The facility code (256-2047) and name to define for these messages
            builder.Add(".Facility", 258, "MyFacility");
            builder.Add("SimpleText", "Message Text", "#MessageId=1");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }

                string contents = mc.ReadAllText();
                Assert.IsTrue(contents.Contains("\r\nMessage Text\r\n."));

                //Facility defined
                Assert.IsTrue(new Regex(@"FACILITY_MYFACILITY\s*=\s*0x102").IsMatch(contents));
                //Category defined
                Assert.IsTrue(new Regex(@"SymbolicName\s*=\s*CATEGORY_MYCATEGORY").IsMatch(contents) && contents.Contains("\r\nMyCategory\r\n.\r\n"));
                //Facility used
                Assert.IsTrue(new Regex(@"Facility\s*=\s*FACILITY_MYFACILITY").IsMatch(contents));
                //Message defined
                Assert.IsTrue(contents.Contains("\r\nMessage Text\r\n."));
            }
        }
        public void TestFormatStringAnonymousArg()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestString", "Test{0}");
            TestResourceResult result = builder.Compile();
            Assert.AreEqual("TestX123X", result.GetValue("TestString", "X123X"));
        }
        public void TestFormatStringTypedArgComments()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestInt32", "Test-{0}", "(int value)");
            TestResourceResult result = builder.Compile();
            Assert.AreEqual("Test-42", result.GetValue("TestInt32", 42));
        }
        public void TestNonFormatString()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestString", "Test{Value}");
            TestResourceResult result = builder.Compile();
            Assert.AreEqual("Test{Value}", result.GetValue("TestString"));
        }
 public void TestFormatStringTypedArgConflictWinner()
 {
     TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");
     //if both name and comments specify arguments, the name wins
     builder.Add("TestString(string value)", "Test-{0:n2}", "(int value)");
     TestResourceResult result = builder.Compile();
     Assert.AreEqual("Test-Value", result.GetValue("TestString", "Value"));
 }
        public void TestFormatStringTypedArgName()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestDouble(double value)", "Test-{0:n2}", "");
            TestResourceResult result = builder.Compile();
            Assert.AreEqual("Test-42.24", result.GetValue("TestDouble", 42.24));
        }
        public void TestFormatStringTypedArgName()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestDouble(double value)", "Test-{0:n2}", "");
            TestResourceResult result = builder.Compile();

            Assert.AreEqual("Test-42.24", result.GetValue("TestDouble", 42.24));
        }
        public void TestFormatStringTypedArgComments()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestInt32", "Test-{0}", "(int value)");
            TestResourceResult result = builder.Compile();

            Assert.AreEqual("Test-42", result.GetValue("TestInt32", 42));
        }
        public void TestFormatStringAnonymousArg()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestString", "Test{0}");
            TestResourceResult result = builder.Compile();

            Assert.AreEqual("TestX123X", result.GetValue("TestString", "X123X"));
        }
        public void TestNonFormatString()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestString", "Test{Value}");
            TestResourceResult result = builder.Compile();

            Assert.AreEqual("Test{Value}", result.GetValue("TestString"));
        }
        public void TestBasicAssertPasses()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException", "(Test Exception:{0})", "(string message) : ArgumentException");
            TestResourceResult result = builder.Compile();

            result.Assert("TestException", true, "Message");
        }
        public void TestBasicArgumentsRequired()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException", "(Test Exception:{0})");
            TestResourceResult result = builder.Compile();

            result.CreateException("TestException");
        }
        public void TestFormatStringTypedArgConflictWinner()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            //if both name and comments specify arguments, the name wins
            builder.Add("TestString(string value)", "Test-{0:n2}", "(int value)");
            TestResourceResult result = builder.Compile();

            Assert.AreEqual("Test-Value", result.GetValue("TestString", "Value"));
        }
        public void TestBasicTypeArgumentsInName()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException(string message)", "(Test:{0})");
            TestResourceResult result = builder.Compile();
            Exception          e      = result.CreateException("TestException", "Message");

            Assert.AreEqual("(Test:Message)", e.Message);
        }
        public void TestBasicException()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException", "TestValue");
            TestResourceResult result = builder.Compile();
            Exception          e      = result.CreateException("TestException");

            Assert.AreEqual("TestValue", e.Message);
        }
        public void TestMemberNotExposed()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException(int extraData)", "(Test:{0})");
            TestResourceResult result = builder.Compile();
            Exception          e      = result.CreateException("TestException", 42);

            Assert.IsNull(e.GetType().GetProperty("extradata", BindingFlags.Public | BindingFlags.GetProperty |
                                                  BindingFlags.Instance | BindingFlags.IgnoreCase));
        }
Пример #23
0
        public void TestGenerateWin32Resource()
        {
            /*
             * Required: This generation type is used to embed the message resource into the current assembly
             * by using a custom Win32Resource setting in the project, for this example you would use:
             *     <Win32Resource>Resources\TestResXClass1.res</Win32Resource>
             *
             * FYI: You must manually add this to the project or else VStudio will erase <ApplicationIcon>
             * The generated res file contains the <ApplicationIcon> as well as assembly version information
             * from the "AssemblyInfo.cs" file included in the project.  If you want to manually supply the
             * assembly info you can point it to a specific assemblyInfo.cs file, or to a dll to extract it
             * from.
             *
             * Optionally you may include "Resources\TestResXClass1.Constants.cs" to define constants for all
             * hresults, facilities, and categories that are defined.
             *
             * Optionally you may include "Resources\TestResXClass1.InstallUtil.cs" to define an installer for
             * the event log registration.  If you need modifications to this installer, simply copy and paste
             * and use it for a starting point.
             */
            using (TempDirectory tmp = new TempDirectory())
                using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
                    using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
                        using (TempFile csproj = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.csproj")))
                            using (TempFile manifest = TempFile.Attach(Path.Combine(tmp.TempPath, "App.manifest")))
                                using (TempFile appico = TempFile.Attach(Path.Combine(tmp.TempPath, "App.ico")))
                                {
                                    asminfo.WriteAllText(AsminfoFormat);
                                    csproj.WriteAllText(String.Format(ProjFormat, Path.GetFileName(resx1.TempPath)));
                                    manifest.WriteAllText(AppManifest);

                                    TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                                    builder1.Add(".AutoLog", true);
                                    builder1.Add(".EventSource", "HelloWorld");
                                    builder1.Add("Value1", "value for 1", "#MessageId = 1");
                                    builder1.BuildResX(resx1.TempPath);

                                    using (Stream s = appico.Open())
                                        Properties.Resources.App.Save(s);

                                    Generators.Commands.ProjectResX(csproj.TempPath, @"Resources\TestResXClass1", null, String.Empty, Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")));

                                    Assert.IsTrue(Directory.Exists(Path.Combine(tmp.TempPath, "Resources")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\MSG00409.bin")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.mc")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.h")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc")));
                                    Assert.IsTrue(File.ReadAllText(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc")).Contains("1.2.3.4"));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.res")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.Constants.cs")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.InstallUtil.cs")));
                                }
        }
        public void TestWithInnerException()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException()", "(Test)");
            TestResourceResult result = builder.Compile();

            Exception inner = new Exception("My inner exception");
            Exception e     = result.CreateException("TestException", inner);

            Assert.AreEqual(inner, e.InnerException);
        }
        public void TestDerivedException()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("BaseException", "{0}");
            builder.Add("TestException(string message)", "(Test:{0})", ": BaseException");
            TestResourceResult result = builder.Compile();

            Exception e = result.CreateException("TestException", "Message");

            Assert.AreEqual("TestNs.BaseException", e.GetType().BaseType.FullName);
            Assert.AreEqual("(Test:Message)", e.Message);
        }
 public void TestInvalidFormatString()
 {
     TextWriter serr = Console.Error;
     try
     {
         Console.SetError(TextWriter.Null);
         TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");
         builder.Add("TestString(string value)", "Test-{0:n2} {}", "(int value)");
         builder.Compile();
     }
     finally
     {
         Console.SetError(serr);
     }
 }
        public void TestDerivedExceptionWithInterface()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            //The parameter starting with a capital 'E'xtraData denotes that this should be stored and a property accessor exposted.
            builder.Add("TestException(int ExtraData)", "(Test:{0})", ": ApplicationException, CSharpTest.Net.GeneratorsTest.IHaveExtraData<int>");
            TestResourceResult result = builder.Compile();

            Exception e = result.CreateException("TestException", 42);

            Assert.AreEqual(typeof(ApplicationException), e.GetType().BaseType);
            Assert.IsTrue(e is IHaveExtraData <int>, "Interface not found: IHaveExtraData<int>");
            Assert.AreEqual("(Test:42)", e.Message);
            Assert.AreEqual(42, ((IHaveExtraData <int>)e).ExtraData);
        }
Пример #28
0
        public void TestDuplicateHResult()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder1.Add("TestName", "value", "#messageId=23,Severity=Error");
            builder1.Add("TestException", "value", "#messageId=23");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }
            }
        }
        public void TestInvalidFormatString()
        {
            TextWriter serr = Console.Error;

            try
            {
                Console.SetError(TextWriter.Null);
                TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");
                builder.Add("TestString(string value)", "Test-{0:n2} {}", "(int value)");
                builder.Compile();
            }
            finally
            {
                Console.SetError(serr);
            }
        }
        public void TestBasicAssertFails()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException", "(Test Exception:{0})", "(string message) : ArgumentException");
            TestResourceResult result = builder.Compile();

            try
            {
                result.Assert("TestException", false, "Message");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual("TestNs.TestException", ae.GetType().FullName);
                throw;
            }
        }
Пример #31
0
        public void TestBuildMcFromResX()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder1.Add("Testing", "test value 1", "#MessageId=42");

            using (TempDirectory intermediateFiles = new TempDirectory())
                using (TempFile mctxt = TempFile.FromExtension(".mc"))
                {
                    using (TempFile resx1 = TempFile.FromExtension(".resx"))
                    {
                        builder1.BuildResX(resx1.TempPath);
                        Generators.Commands.ResXtoMc(mctxt.TempPath, new string[] { resx1.TempPath });
                    }

                    string mcexe = TestResourceBuilder.FindExe("mc.exe");

                    using (ProcessRunner mc = new ProcessRunner(mcexe, "-U", "{0}", "-r", "{1}", "-h", "{1}"))
                    {
                        mc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { Trace.WriteLine(e.Data, mcexe); };
                        Assert.AreEqual(0, mc.RunFormatArgs(mctxt.TempPath, intermediateFiles.TempPath), "mc.exe failed.");
                    }

                    string rcfile = Path.Combine(intermediateFiles.TempPath, Path.GetFileNameWithoutExtension(mctxt.TempPath) + ".rc");
                    Assert.IsTrue(File.Exists(rcfile));
                    Assert.IsTrue(File.Exists(Path.ChangeExtension(rcfile, ".h")));
                    Assert.IsTrue(File.Exists(Path.Combine(intermediateFiles.TempPath, "MSG00409.bin")));

                    string rcexe = Path.Combine(Path.GetDirectoryName(mcexe), "rc.exe");
                    if (!File.Exists(rcexe))
                    {
                        rcexe = TestResourceBuilder.FindExe("rc.exe");
                    }

                    using (ProcessRunner rc = new ProcessRunner(rcexe, "{0}"))
                    {
                        rc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { Trace.WriteLine(e.Data, rcexe); };
                        Assert.AreEqual(0, rc.RunFormatArgs(rcfile), "rc.exe failed.");
                    }

                    string resfile = Path.ChangeExtension(rcfile, ".res");
                    Assert.IsTrue(File.Exists(resfile));
                    Assert.IsTrue(File.ReadAllText(resfile).Contains("\0t\0e\0s\0t\0 \0v\0a\0l\0u\0e\0 \01"));
                }
        }
        public void TestFormatStringTypedArgOverloads()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("Test(string value)", "Test-{0}");
            builder.Add("Test(int value)", "Test-{0}");
            builder.Add("Test(double value)", "Test-{0:n3}");
            builder.Add("Test(System.Version value)", "Test-{0}");
            builder.Add("Test(System.Uri value)", "Test-{0}");

            TestResourceResult result = builder.Compile();

            Assert.AreEqual("Test-Value", result.GetValue("Test", "Value"));
            Assert.AreEqual("Test-123", result.GetValue("Test", 123));
            Assert.AreEqual("Test-123.321", result.GetValue("Test", 123.321));
            Assert.AreEqual("Test-1.2.3.4", result.GetValue("Test", new Version(1, 2, 3, 4)));
            Assert.AreEqual("Test-http://csharptest.net/blog", result.GetValue("Test", new Uri("http://csharptest.net/blog", UriKind.Absolute)));
        }
        public void TestEmptyResXToMc()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder1.Add("Ignored_Lack_of_MessageId", "");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }

                string contents = mc.ReadAllText();
                string[] lines = contents.TrimEnd().Split('\n');
                //no messages:
                Assert.AreEqual(";// MESSAGES", lines[lines.Length - 1].Trim());
            }
        }
        public void TestBasicTypeArgumentOverloads()
        {
            Exception           e;
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("TestException", "(Test)");
            builder.Add("TestException(string message)", "(Test:{0})");
            builder.Add("TestException(double value)", "(Test:{0:n2})");
            TestResourceResult result = builder.Compile();

            e = result.CreateException("TestException");
            Assert.AreEqual("(Test)", e.Message);

            e = result.CreateException("TestException", "Message");
            Assert.AreEqual("(Test:Message)", e.Message);

            e = result.CreateException("TestException", 1.2);
            Assert.AreEqual("(Test:1.20)", e.Message);
        }
Пример #35
0
        public void TestEmptyResXToMc()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder1.Add("Ignored_Lack_of_MessageId", "");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }

                string   contents = mc.ReadAllText();
                string[] lines    = contents.TrimEnd().Split('\n');
                //no messages:
                Assert.AreEqual(";// MESSAGES", lines[lines.Length - 1].Trim());
            }
        }
Пример #36
0
        public void TestDuplicateNameInFiles()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder1.Add("DuplicateName", "value", "#messageId=23");
            TestResourceBuilder builder2 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder2.Add("DuplicateName", "value", "#messageId=24");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                    using (TempFile resx2 = TempFile.FromExtension(".resx"))
                    {
                        builder1.BuildResX(resx1.TempPath);
                        builder2.BuildResX(resx2.TempPath);
                        Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath, resx2.TempPath });
                    }
            }
        }
Пример #37
0
        public void TestProjectResXVersionByAssembly()
        {
            /* Demonstrates versioning from an existing assembly... */
            using (TempDirectory tmp = new TempDirectory())
                using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
                    using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
                        using (TempFile csproj = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.csproj")))
                            using (TempFile manifest = TempFile.Attach(Path.Combine(tmp.TempPath, "App.manifest")))
                                using (TempFile appico = TempFile.Attach(Path.Combine(tmp.TempPath, "App.ico")))
                                {
                                    asminfo.WriteAllText(AsminfoFormat);
                                    csproj.WriteAllText(String.Format(ProjFormat, Path.GetFileName(resx1.TempPath)));
                                    manifest.WriteAllText(AppManifest);

                                    TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                                    builder1.Add(".AutoLog", true);
                                    builder1.Add(".EventSource", "HelloWorld");
                                    builder1.Add("Value1", "value for 1", "#MessageId = 1");
                                    builder1.BuildResX(resx1.TempPath);

                                    using (Stream s = appico.Open())
                                        Properties.Resources.App.Save(s);

                                    Generators.Commands.ProjectResX(csproj.TempPath, @"Resources\TestResXClass1",
                                                                    typeof(Generators.Commands).Assembly.Location, String.Empty,
                                                                    Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")));

                                    Assert.IsTrue(Directory.Exists(Path.Combine(tmp.TempPath, "Resources")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\MSG00409.bin")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.mc")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.h")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc")));
                                    Assert.IsTrue(File.ReadAllText(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc"))
                                                  .Contains(typeof(Generators.Commands).Assembly.GetName().Version.ToString()));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.res")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.Constants.cs")));
                                    Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.InstallUtil.cs")));
                                }
        }
Пример #38
0
        public void TestDuplicateCategorySameIdDifferentName()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder1.Add(".EventCategory", 1, "MyCategory");
            builder1.Add("name1", "value", "#messageId=23");
            TestResourceBuilder builder2 = new TestResourceBuilder("TestNamespace", "TestResXClass1");

            builder2.Add(".EventCategory", 1, "NotMyCategory");
            builder2.Add("name2", "value", "#messageId=24");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                    using (TempFile resx2 = TempFile.FromExtension(".resx"))
                    {
                        builder1.BuildResX(resx1.TempPath);
                        builder2.BuildResX(resx2.TempPath);
                        Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath, resx2.TempPath });
                    }
            }
        }
        public void TestSimpleStringResXToMc()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder1.Add("Value1", "value for 1", "#MessageId = 1");
            TestResourceBuilder builder2 = new TestResourceBuilder("TestNamespace", "TestResXClass2");
            builder2.Add("Value2", "value for 2", "#MessageId = 2");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                using (TempFile resx2 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    builder2.BuildResX(resx2.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath, resx2.TempPath });
                }

                string contents = mc.ReadAllText();

                Assert.IsTrue(contents.Contains("\r\nvalue for 1\r\n.\r\n"));
                Assert.IsTrue(contents.Contains("\r\nvalue for 2\r\n.\r\n"));
            }
        }
        public void TestSimpleResXLogEvent()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            string messageText = String.Format("NUnit {0} {1}", GetType(), Guid.NewGuid());

            //Enables the LOG feature to automagically generate log calls on all exception constructors.
            builder.Add(".AutoLog", true);
            builder.Add(".EventSource", "CSharpTest - NUnit");

            //If .NextMessageId is not defined you must specify one for logging to enable on that item.
            builder.Add("SimpleLog(string text)", "{0}", "#MessageId=1");

            TestResourceResult result = builder.Compile();

            Assert.AreEqual(messageText, result.GetValue("SimpleLog", messageText));

            using (EventLog applog = new EventLog("Application"))
            {
                EventLogEntry           found   = null;
                EventLogEntryCollection entries = applog.Entries;
                int stop = Math.Max(0, entries.Count - 50);
                for (int i = entries.Count - 1; i >= stop; i--)
                {
                    if (entries[i].Message.Contains(messageText))
                    {
                        found = entries[i];
                        break;
                    }
                }
                Assert.IsNotNull(found);
                Assert.AreEqual("CSharpTest - NUnit", found.Source);
                Assert.AreEqual(1, found.ReplacementStrings.Length);
                Assert.AreEqual(messageText, found.ReplacementStrings[0]);
            }
        }
        public void TestFormatWithSuffixResXToMc()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder1.Add("WhatsUp(string s, int i)", "Format!%0\n\tstring={0},\n.\r\n\tnumber={1}.", "#messageId=23");
            builder1.Add(".EventMessageFormat", "Suffix\nTest {0} Format");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }

                string contents = mc.ReadAllText();
                Assert.IsTrue(contents.Contains(@"
Format%!%%0%n
	string=%2,%n
%.%n
	number=%3.%n
Suffix%n
Test %1 Format
"));
            }
        }
        public void TestFormatStringTypedArgOverloads()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            builder.Add("Test(string value)", "Test-{0}");
            builder.Add("Test(int value)", "Test-{0}");
            builder.Add("Test(double value)", "Test-{0:n3}");
            builder.Add("Test(System.Version value)", "Test-{0}");
            builder.Add("Test(System.Uri value)", "Test-{0}");

            TestResourceResult result = builder.Compile();
            Assert.AreEqual("Test-Value", result.GetValue("Test", "Value"));
            Assert.AreEqual("Test-123", result.GetValue("Test", 123));
            Assert.AreEqual("Test-123.321", result.GetValue("Test", 123.321));
            Assert.AreEqual("Test-1.2.3.4", result.GetValue("Test", new Version(1, 2, 3, 4)));
            Assert.AreEqual("Test-http://csharptest.net/blog", result.GetValue("Test", new Uri("http://csharptest.net/blog", UriKind.Absolute)));
        }
        public void TestDuplicateHResult()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder1.Add("TestName", "value", "#messageId=23,Severity=Error");
            builder1.Add("TestException", "value", "#messageId=23");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath });
                }
            }
        }
        public void TestBuildMcFromResX()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder1.Add("Testing", "test value 1", "#MessageId=42");

            using (TempDirectory intermediateFiles = new TempDirectory())
            using (TempFile mctxt = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    Generators.Commands.ResXtoMc(mctxt.TempPath, new string[] { resx1.TempPath });
                }

                string mcexe = TestResourceBuilder.FindExe("mc.exe");

                using (ProcessRunner mc = new ProcessRunner(mcexe, "-U", "{0}", "-r", "{1}", "-h", "{1}"))
                {
                    mc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { Trace.WriteLine(e.Data, mcexe); };
                    Assert.AreEqual(0, mc.RunFormatArgs(mctxt.TempPath, intermediateFiles.TempPath), "mc.exe failed.");
                }

                string rcfile = Path.Combine(intermediateFiles.TempPath, Path.GetFileNameWithoutExtension(mctxt.TempPath) + ".rc");
                Assert.IsTrue(File.Exists(rcfile));
                Assert.IsTrue(File.Exists(Path.ChangeExtension(rcfile, ".h")));
                Assert.IsTrue(File.Exists(Path.Combine(intermediateFiles.TempPath, "MSG00409.bin")));

                string rcexe = Path.Combine(Path.GetDirectoryName(mcexe), "rc.exe");
                if (!File.Exists(rcexe))
                    rcexe = TestResourceBuilder.FindExe("rc.exe");

                using (ProcessRunner rc = new ProcessRunner(rcexe, "{0}"))
                {
                    rc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { Trace.WriteLine(e.Data, rcexe); };
                    Assert.AreEqual(0, rc.RunFormatArgs(rcfile), "rc.exe failed.");
                }

                string resfile = Path.ChangeExtension(rcfile, ".res");
                Assert.IsTrue(File.Exists(resfile));
                Assert.IsTrue(File.ReadAllText(resfile).Contains("\0t\0e\0s\0t\0 \0v\0a\0l\0u\0e\0 \01"));
            }
        }
        public void TestDuplicateCategorySameIdDifferentName()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder1.Add(".EventCategory", 1, "MyCategory");
            builder1.Add("name1", "value", "#messageId=23");
            TestResourceBuilder builder2 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder2.Add(".EventCategory", 1, "NotMyCategory");
            builder2.Add("name2", "value", "#messageId=24");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                using (TempFile resx2 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    builder2.BuildResX(resx2.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath, resx2.TempPath });
                }
            }
        }
        public void TestDuplicateNameInFiles()
        {
            TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder1.Add("DuplicateName", "value", "#messageId=23");
            TestResourceBuilder builder2 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
            builder2.Add("DuplicateName", "value", "#messageId=24");

            using (TempFile mc = TempFile.FromExtension(".mc"))
            {
                using (TempFile resx1 = TempFile.FromExtension(".resx"))
                using (TempFile resx2 = TempFile.FromExtension(".resx"))
                {
                    builder1.BuildResX(resx1.TempPath);
                    builder2.BuildResX(resx2.TempPath);
                    Generators.Commands.ResXtoMc(mc.TempPath, new string[] { resx1.TempPath, resx2.TempPath });
                }
            }
        }
        public void TestFormatResxOptions()
        {
            TestResourceBuilder builder = new TestResourceBuilder("TestNs", "ResXClass");

            //the next message id to use when autoLog is enabled.
            builder.Add(".NextMessageId", 5);

            //the format string for the full hresult to a uri.
            builder.Add(".HelpLink", new Uri("http://mydomain/errorcodes.aspx?id={0:x8}"));

            //Trailing message text for event log, can include {0} formats. which are specified before the message-specific values
            builder.Add(".EventMessageFormat", "Trailing message text for event log, can include {0} formats.");

            //Enables the LOG feature to automagically generate log calls on all exception constructors.
            builder.Add(".AutoLog", true);

            //The fully-qualified method used to write the log to the event log
            builder.Add(".AutoLogMethod", String.Format("{0}.TestCustomEventWriter", GetType().FullName));

            //The name of the event source to register, can be qualified with log: "Log-Name/Event-Source"
            builder.Add(".EventSource", "Application/YourAppName");

            //OPTIONAL (default=0): The category id and name for the category of the message, should be unique for this ResX file 
            builder.Add(".EventCategory", 0x0F, "MyCategory");

            //OPTIONAL (default=0): The facility code (256-2047) and name to define for these messages
            builder.Add(".Facility", 258, "MyFacility");

            builder.Add("TestFormatting(int value)", "TestFormatting-{0:x8}", "#MessageId=3");
            builder.Add("TestWarning", "TestWarning", "(int unprinted) #MessageId=251, Severity=Warn");
            builder.Add("TestException(string s, int i)", "TestException-{0}-{1}", ":System.Runtime.InteropServices.COMException");

            string code, resx;
            TestResourceResult result;
            StringWriter captureErr = new StringWriter();
            TextWriter stderr = Console.Error;
            try
            {
                Console.SetError(captureErr);
                result = builder.Compile("-reference:" + GetType().Assembly.Location, out code, out resx);
            }
            finally { Console.SetError(stderr); }

            _lastEvent = null;
            Assert.AreEqual("TestFormatting-000e1234", result.GetValue("TestFormatting", 0x0e1234));
            Assert.IsNotNull(_lastEvent);
            Assert.AreEqual("Application", _lastLog.Log);
            Assert.AreEqual("YourAppName", _lastLog.Source);
            Assert.AreEqual(0x0F, _lastEvent.CategoryId);
            Assert.AreEqual(EventLogEntryType.Information, _lastEvent.EntryType);
            Assert.AreEqual(0x41020003L, _lastEvent.InstanceId);
            Assert.AreEqual(1, _lastArgs.Length);
            Assert.AreEqual("000e1234", _lastArgs[0]);

            _lastEvent = null;
            Assert.AreEqual("TestWarning", result.GetValue("TestWarning", 3579));
            Assert.IsNotNull(_lastEvent);
            Assert.AreEqual("Application", _lastLog.Log);
            Assert.AreEqual("YourAppName", _lastLog.Source);
            Assert.AreEqual(0x0F, _lastEvent.CategoryId);
            Assert.AreEqual(EventLogEntryType.Warning, _lastEvent.EntryType);
            Assert.AreEqual(0x810200fbL, _lastEvent.InstanceId);
            Assert.AreEqual(1, _lastArgs.Length);
            Assert.AreEqual("3579", _lastArgs[0]);

            _lastEvent = null;
            COMException error = (COMException)result.CreateException("TestException", "error", 1234);
            Assert.AreEqual("TestException-error-1234", error.Message);
            Assert.AreEqual(unchecked((int)0xe1020005), error.ErrorCode);//5 was auto-assigned by NextMessageId
            Assert.AreEqual("http://mydomain/errorcodes.aspx?id=e1020005", error.HelpLink);

            Assert.IsNotNull(_lastEvent);
            Assert.AreEqual("Application", _lastLog.Log);
            Assert.AreEqual("YourAppName", _lastLog.Source);
            Assert.AreEqual(0x0F, _lastEvent.CategoryId);
            Assert.AreEqual(EventLogEntryType.Error, _lastEvent.EntryType);
            Assert.AreEqual(0xC1020005L, _lastEvent.InstanceId);
            Assert.AreEqual(2, _lastArgs.Length);
            Assert.AreEqual("error", _lastArgs[0]);
            Assert.AreEqual("1234", _lastArgs[1]);
        }
        public void TestProjectResXVersionByAssembly()
        {
            /* Demonstrates versioning from an existing assembly... */
            using (TempDirectory tmp = new TempDirectory())
            using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
            using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
            using (TempFile csproj = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.csproj")))
            using (TempFile manifest = TempFile.Attach(Path.Combine(tmp.TempPath, "App.manifest")))
            using (TempFile appico = TempFile.Attach(Path.Combine(tmp.TempPath, "App.ico")))
            {
                asminfo.WriteAllText(AsminfoFormat);
                csproj.WriteAllText(String.Format(ProjFormat, Path.GetFileName(resx1.TempPath)));
                manifest.WriteAllText(AppManifest);

                TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                builder1.Add(".AutoLog", true);
                builder1.Add(".EventSource", "HelloWorld");
                builder1.Add("Value1", "value for 1", "#MessageId = 1");
                builder1.BuildResX(resx1.TempPath);

                using (Stream s = appico.Open())
                    Properties.Resources.App.Save(s);

                Generators.Commands.ProjectResX(csproj.TempPath, @"Resources\TestResXClass1",
                    typeof(Generators.Commands).Assembly.Location, String.Empty, 
                    Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")));

                Assert.IsTrue(Directory.Exists(Path.Combine(tmp.TempPath, "Resources")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\MSG00409.bin")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.mc")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.h")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc")));
                Assert.IsTrue(File.ReadAllText(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc"))
                    .Contains(typeof(Generators.Commands).Assembly.GetName().Version.ToString()));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.res")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.Constants.cs")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.InstallUtil.cs")));
            }
        }
        public void TestCreateMessageAssembly()
        {
            /* 
             * This is the most simple form of message generation in which we generate a complete dll with
             * the message resource (and optional versioning).  The dll includes the TestResXClass1.Constants.cs
             * and the TestResXClass1.InstallUtil.cs as generated in the example TestGenerateWin32Resource().
             */
            using (TempDirectory tmp = new TempDirectory())
            using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
            using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
            using (TempFile dllout = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.dll")))
            {
                asminfo.WriteAllText(AsminfoFormat);

                TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                builder1.Add(".AutoLog", true);
                builder1.Add(".EventSource", "HelloWorld");
                builder1.Add("Value1", "value for 1", "#MessageId = 1");
                builder1.BuildResX(resx1.TempPath);

                Generators.Commands.ResXtoMessageDll(dllout.TempPath, new string[] { resx1.TempPath },
                    tmp.TempPath, asminfo.TempPath, "TestNamespace", Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")), "/debug-");

                Assert.IsTrue(dllout.Exists);
            }
        }
        public void TestProjectResXWithBadAssemblyInfo()
        {
            /* Bad assembly info... */
            using (TempDirectory tmp = new TempDirectory())
            using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
            using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
            using (TempFile csproj = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.csproj")))
            using (TempFile manifest = TempFile.Attach(Path.Combine(tmp.TempPath, "App.manifest")))
            using (TempFile appico = TempFile.Attach(Path.Combine(tmp.TempPath, "App.ico")))
            {
                asminfo.WriteAllText(AsminfoFormat + "[InvalidAttribute]");
                csproj.WriteAllText(String.Format(ProjFormat, Path.GetFileName(resx1.TempPath)));
                manifest.WriteAllText(AppManifest);

                TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                builder1.Add(".AutoLog", true);
                builder1.Add(".EventSource", "HelloWorld");
                builder1.Add("Value1", "value for 1", "#MessageId = 1");
                builder1.BuildResX(resx1.TempPath);

                using (Stream s = appico.Open())
                    Properties.Resources.App.Save(s);

                Generators.Commands.ProjectResX(csproj.TempPath, @"Resources\TestResXClass1", null, String.Empty, Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")));
            }
        }
        public void TestGenerateWin32Resource()
        {
            /* 
             * Required: This generation type is used to embed the message resource into the current assembly
             * by using a custom Win32Resource setting in the project, for this example you would use:
             *     <Win32Resource>Resources\TestResXClass1.res</Win32Resource>
             *     
             * FYI: You must manually add this to the project or else VStudio will erase <ApplicationIcon>
             * The generated res file contains the <ApplicationIcon> as well as assembly version information
             * from the "AssemblyInfo.cs" file included in the project.  If you want to manually supply the
             * assembly info you can point it to a specific assemblyInfo.cs file, or to a dll to extract it
             * from.
             * 
             * Optionally you may include "Resources\TestResXClass1.Constants.cs" to define constants for all
             * hresults, facilities, and categories that are defined.
             * 
             * Optionally you may include "Resources\TestResXClass1.InstallUtil.cs" to define an installer for
             * the event log registration.  If you need modifications to this installer, simply copy and paste
             * and use it for a starting point.
             */
            using (TempDirectory tmp = new TempDirectory())
            using (TempFile asminfo = TempFile.Attach(Path.Combine(tmp.TempPath, "AssemblyInfo.cs")))
            using (TempFile resx1 = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.resx")))
            using (TempFile csproj = TempFile.Attach(Path.Combine(tmp.TempPath, "TestResXClass1.csproj")))
            using (TempFile manifest = TempFile.Attach(Path.Combine(tmp.TempPath, "App.manifest")))
            using (TempFile appico = TempFile.Attach(Path.Combine(tmp.TempPath, "App.ico")))
            {
                asminfo.WriteAllText(AsminfoFormat);
                csproj.WriteAllText(String.Format(ProjFormat, Path.GetFileName(resx1.TempPath)));
                manifest.WriteAllText(AppManifest);

                TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1");
                builder1.Add(".AutoLog", true);
                builder1.Add(".EventSource", "HelloWorld");
                builder1.Add("Value1", "value for 1", "#MessageId = 1");
                builder1.BuildResX(resx1.TempPath);

                using (Stream s = appico.Open())
                    Properties.Resources.App.Save(s);

                Generators.Commands.ProjectResX(csproj.TempPath, @"Resources\TestResXClass1", null, String.Empty, Path.GetDirectoryName(TestResourceBuilder.FindExe("mc.exe")));

                Assert.IsTrue(Directory.Exists(Path.Combine(tmp.TempPath, "Resources")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\MSG00409.bin")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.mc")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.h")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc")));
                Assert.IsTrue(File.ReadAllText(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.rc")).Contains("1.2.3.4"));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.res")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.Constants.cs")));
                Assert.IsTrue(File.Exists(Path.Combine(tmp.TempPath, @"Resources\TestResXClass1.InstallUtil.cs")));
            }
        }