2 using System.Collections.Generic;
7 using Microsoft.Build.BuildEngine;
9 namespace MonoTests.Microsoft.Build.Tasks
12 public class CreateVisualBasicManifestResourceNameTest
15 string [,] resx_no_culture_files, resx_with_culture_files;
16 string [,] non_resx_no_culture_files, non_resx_with_culture_files;
18 public CreateVisualBasicManifestResourceNameTest ()
20 string sample_vb_path = Path.Combine ("Test", Path.Combine ("resources", "Sample.vb"));
21 resx_no_culture_files = new string [,] {
22 // With dependent file
23 { "foo with space.resx", null, sample_vb_path },
24 { "foo with space.resx", "RandomName", sample_vb_path },
26 { "Test/resources/foo with space.resx", null, "Sample.vb" },
27 { "Test/resources/foo with space.resx", "RandomName", "Sample.vb" },
30 { "foo with space.resx", null, null },
31 { "foo with space.resx", "RandomName", null },
33 { "Test/resources/foo with space.resx", null, null },
34 { "Test/resources/foo with space.resx", "RandomName", null },
37 resx_with_culture_files = new string [,] {
38 // With dependent file
39 { "foo with space.de.resx", null, sample_vb_path },
40 { "foo with space.de.resx", "RandomName", sample_vb_path },
42 { "Test/resources/foo with space.de.resx", null, "Sample.vb" },
43 { "Test/resources/foo with space.de.resx", "RandomName", "Sample.vb" },
46 { "foo with space.de.resx", null, null },
47 { "foo with space.de.resx", "RandomName", null },
49 { "Test/resources folder/foo with space.de.resx", null, null },
50 { "Test/resources folder/foo with space.de.resx", "RandomName", null }
53 non_resx_no_culture_files = new string [,] {
54 { "foo with space.txt", null, null },
55 { "foo with space.txt", "RandomName", null },
57 { "Test/resources folder/foo with space.txt", null, null },
58 { "Test/resources folder/foo with space.txt", "RandomName", null }
61 non_resx_with_culture_files = new string [,] {
62 { "foo with space.de.txt", null, null },
63 { "foo with space.de.txt", "RandomName", null },
65 { "Test/resources folder/foo with space.de.txt", null, null },
66 { "Test/resources folder/foo with space.de.txt", "RandomName", null }
72 public void TestNoRootNamespaceNoCulture ()
74 CheckResourceNames (resx_no_culture_files, new string [] {
76 "Mono.Tests.Sample", "Mono.Tests.Sample",
77 "Mono.Tests.Sample", "Mono.Tests.Sample",
80 "foo with space", "foo with space" ,
81 "foo with space", "foo with space"}, null);
85 public void TestWithRootNamespaceNoCulture ()
87 //FIXME: How does LogicalName affect things??
88 CheckResourceNames (resx_no_culture_files, new string [] {
89 // With dependent file
90 "RN1.RN2.Mono.Tests.Sample", "RN1.RN2.Mono.Tests.Sample",
91 "RN1.RN2.Mono.Tests.Sample", "RN1.RN2.Mono.Tests.Sample",
93 "RN1.RN2.foo with space", "RN1.RN2.foo with space",
94 "RN1.RN2.foo with space", "RN1.RN2.foo with space"},
99 public void TestNoRootNamespaceWithCulture ()
101 CheckResourceNames (resx_with_culture_files, new string [] {
102 // With dependent file
103 "Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
104 "Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
105 // W/o dependent file
106 "foo with space.de", "foo with space.de",
107 "foo with space.de", "foo with space.de" }, null);
111 public void TestWithRootNamespaceWithCulture ()
113 CheckResourceNames (resx_with_culture_files, new string [] {
114 // With dependent file
115 "RN1.RN2.Mono.Tests.Sample.de", "RN1.RN2.Mono.Tests.Sample.de",
116 "RN1.RN2.Mono.Tests.Sample.de", "RN1.RN2.Mono.Tests.Sample.de",
117 // W/o dependent file
118 "RN1.RN2.foo with space.de", "RN1.RN2.foo with space.de",
119 "RN1.RN2.foo with space.de", "RN1.RN2.foo with space.de"},
124 public void TestNonResxNoRootNamespaceWithCulture ()
126 CheckResourceNames (non_resx_with_culture_files, new string [] {
127 Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt"),
128 Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt")}, null);
132 public void TestNonResxWithRootNamespaceWithCulture ()
134 CheckResourceNames (non_resx_with_culture_files, new string [] {
135 Path.Combine ("de", "RN1.RN2.foo with space.txt"), Path.Combine ("de", "RN1.RN2.foo with space.txt"),
136 Path.Combine ("de", "RN1.RN2.foo with space.txt"), Path.Combine ("de", "RN1.RN2.foo with space.txt")},
141 public void TestNonResxNoRootNamespaceNoCulture ()
143 CheckResourceNames (non_resx_no_culture_files, new string [] {
144 "foo with space.txt", "foo with space.txt",
145 "foo with space.txt", "foo with space.txt"}, null);
149 public void TestNonResxWithRootNamespaceNoCulture ()
151 CheckResourceNames (non_resx_no_culture_files, new string [] {
152 // With dependent file
153 "RN1.RN2.foo with space.txt", "RN1.RN2.foo with space.txt",
154 "RN1.RN2.foo with space.txt", "RN1.RN2.foo with space.txt"},
158 void CheckResourceNames (string [,] files, string [] names, string rootNamespace)
160 Assert.AreEqual (files.GetUpperBound (0) + 1, names.Length, "Number of files and names must match");
161 string projectText = CreateProject (files, rootNamespace);
163 Engine engine = new Engine (Consts.BinPath);
164 Project project = engine.CreateNewProject ();
165 TestMessageLogger logger = new TestMessageLogger ();
166 engine.RegisterLogger (logger);
167 Console.WriteLine (projectText);
168 project.LoadXml (projectText);
169 if (!project.Build ("1")) {
170 logger.DumpMessages ();
171 Assert.Fail ("Build failed");
174 BuildItemGroup group = project.GetEvaluatedItemsByName ("ResourceNames");
175 Assert.AreEqual (names.Length, group.Count, "A2");
176 for (int i = 0; i <= files.GetUpperBound (0); i++) {
177 Assert.AreEqual (names [i], group [i].FinalItemSpec, "A3 #" + (i + 1));
178 Assert.AreEqual (files [i, 1] != null, group [i].HasMetadata ("LogicalName"), "A4 #" + (i + 1));
179 if (files [i, 1] != null)
180 Assert.AreEqual (files [i, 1], group [i].GetMetadata ("LogicalName"), "A5 #" + (i + 1));
181 Assert.AreEqual (files [i, 2] != null, group [i].HasMetadata ("DependentUpon"), "A6 #" + (i + 1));
182 if (files [i, 2] != null)
183 Assert.AreEqual (files [i, 2], group [i].GetMetadata ("DependentUpon"), "A7 #" + (i + 1));
187 string CreateProject (string [,] files, string rootNamespace)
189 StringBuilder sb = new StringBuilder ();
190 sb.Append ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
192 sb.Append ("\t<ItemGroup>\n");
193 for (int i = 0; i <= files.GetUpperBound (0); i ++) {
194 sb.AppendFormat ("\t\t<ResourceFiles Include = \"{0}\">\n", files [i, 0]);
195 if (files [i, 1] != null)
196 sb.AppendFormat ("\t\t\t<LogicalName>{0}</LogicalName>\n", files [i, 1]);
197 if (files [i, 2] != null)
198 sb.AppendFormat ("\t\t\t<DependentUpon>{0}</DependentUpon>\n", files [i, 2]);
199 sb.AppendFormat ("\t\t</ResourceFiles>\n");
201 sb.Append ("\t</ItemGroup>\n");
203 sb.Append ("\t<Target Name=\"1\">\n");
204 sb.Append ("\t\t<CreateVisualBasicManifestResourceName ResourceFiles=\"@(ResourceFiles)\" ");
205 if (rootNamespace != null)
206 sb.AppendFormat (" RootNamespace = \"{0}\"", rootNamespace);
207 sb.Append (">\n \t\t\t<Output TaskParameter=\"ManifestResourceNames\" ItemName=\"ResourceNames\" />\n");
208 sb.Append ("\t\t</CreateVisualBasicManifestResourceName>\n\t</Target>\n");
209 sb.Append ("\t<UsingTask TaskName=\"Microsoft.Build.Tasks.CreateVisualBasicManifestResourceName\" " +
210 "AssemblyName=\"Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"/>\n");
211 sb.Append ("</Project>");
213 return sb.ToString ();