public void CulturedResourceFileFindByConvention() { using (var env = TestEnvironment.Create(_testOutput)) { var csFile = env.CreateFile("SR1.cs", "namespace MyStuff.Namespace { class Class { } }"); var resXFile = env.CreateFile("SR1.de.resx", ""); ITaskItem i = new TaskItem(resXFile.Path); i.SetMetadata("BuildAction", "EmbeddedResource"); // this data is set automatically through the AssignCulture task, so we manually set it here i.SetMetadata("WithCulture", "true"); i.SetMetadata("Culture", "de"); env.SetCurrentDirectory(Path.GetDirectoryName(resXFile.Path)); CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName { BuildEngine = new MockEngine(), UseDependentUponConvention = true, ResourceFiles = new ITaskItem[] { i }, }; t.Execute().ShouldBeTrue("Expected the task to succeed"); t.ManifestResourceNames.ShouldHaveSingleItem(); // CreateManifestNameImpl appends culture to the end of the convention t.ManifestResourceNames[0].ItemSpec.ShouldBe("MyStuff.Namespace.Class.de", "Expected Namespace.Class.Culture"); } }
public void DependentUpon_SpecifyNewFile() { using (var env = TestEnvironment.Create()) { var conventionCSFile = env.CreateFile("SR1.cs", "namespace MyStuff.Namespace { class Class { } }"); var nonConventionCSFile = env.CreateFile("SR2.cs", "namespace MyStuff2.Namespace { class Class2 { } }"); var resXFile = env.CreateFile("SR1.resx", ""); ITaskItem i = new TaskItem(resXFile.Path); i.SetMetadata("BuildAction", "EmbeddedResource"); i.SetMetadata("DependentUpon", "SR2.cs"); CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName { BuildEngine = new MockEngine(_testOutput), UseDependentUponConvention = true, ResourceFiles = new ITaskItem[] { i } }; t.Execute().ShouldBeTrue("Expected the task to succeed."); t.ManifestResourceNames.ShouldHaveSingleItem(); t.ManifestResourceNames[0].ItemSpec.ShouldBe("MyStuff2.Namespace.Class2", "Expected the namespace & class of SR2."); } }
public void DependentUponConvention_ConventionDisabledDoesNotReadConventionFile() { using (var env = TestEnvironment.Create()) { var csFile = env.CreateFile("SR1.cs", "namespace MyStuff.Namespace { class Class { } }"); var resXFile = env.CreateFile("SR1.resx", ""); ITaskItem i = new TaskItem(Path.GetFileName(resXFile.Path)); i.SetMetadata("BuildAction", "EmbeddedResource"); // No need to set DependentUpon // Use relative paths to ensure short manifest name based on the path to the resx. // See CreateManifestNameImpl env.SetCurrentDirectory(Path.GetDirectoryName(resXFile.Path)); CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName { BuildEngine = new MockEngine(_testOutput), UseDependentUponConvention = false, ResourceFiles = new ITaskItem[] { i } }; t.Execute().ShouldBeTrue("Expected the task to succeed."); t.ManifestResourceNames.ShouldHaveSingleItem(); t.ManifestResourceNames[0].ItemSpec.ShouldBe("SR1", "Expected only the file name."); } }
public void DependentUpon_UseConventionFileDoesNotExist() { using (var env = TestEnvironment.Create()) { // cs file doesn't exist for this case. var resXFile = env.CreateFile("SR1.resx", ""); ITaskItem i = new TaskItem(Path.GetFileName(resXFile.Path)); i.SetMetadata("BuildAction", "EmbeddedResource"); // Don't set DependentUpon so it goes by convention // Use relative paths to ensure short manifest name based on the path to the resx. // See CreateManifestNameImpl env.SetCurrentDirectory(Path.GetDirectoryName(resXFile.Path)); CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName { BuildEngine = new MockEngine(_testOutput), UseDependentUponConvention = true, ResourceFiles = new ITaskItem[] { i } }; t.Execute().ShouldBeTrue("Expected the task to succeed."); t.ManifestResourceNames.ShouldHaveSingleItem(); t.ManifestResourceNames[0].ItemSpec.ShouldBe("SR1", "Expected only the file name."); } }
public void DependentUponConvention_FindsMatchInSubfolder() { using (var env = TestEnvironment.Create()) { var subfolder = env.DefaultTestDirectory.CreateDirectory("SR1"); var csFile = subfolder.CreateFile("SR1.cs", "namespace MyStuff.Namespace { class Class { } }"); var resXFile = subfolder.CreateFile("SR1.resx", ""); env.SetCurrentDirectory(env.DefaultTestDirectory.Path); ITaskItem i = new TaskItem(@"SR1\SR1.resx"); i.SetMetadata("BuildAction", "EmbeddedResource"); // Don't set DependentUpon so it goes by convention CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName { BuildEngine = new MockEngine(_testOutput), UseDependentUponConvention = true, ResourceFiles = new ITaskItem[] { i } }; t.Execute().ShouldBeTrue("Expected the task to succeed."); t.ManifestResourceNames.ShouldHaveSingleItem(); t.ManifestResourceNames[0].ItemSpec.ShouldBe("MyStuff.Namespace.Class", "Expecting to find the namespace & class name from SR1.cs"); } }
public void DependentUponConvention_DoesNotApplyToNonResx(bool explicitlySpecifyType) { using (var env = TestEnvironment.Create()) { var csFile = env.CreateFile("SR1.cs", "namespace MyStuff.Namespace { class Class { } }"); const string ResourceFileName = "SR1.txt"; var resourceFile = env.CreateFile(ResourceFileName, ""); // Default resource naming is based on the item include, so use a relative // path here instead of a full path. env.SetCurrentDirectory(Path.GetDirectoryName(resourceFile.Path)); ITaskItem i = new TaskItem(ResourceFileName); i.SetMetadata("BuildAction", "EmbeddedResource"); if (explicitlySpecifyType) { i.SetMetadata("Type", "Non-Resx"); } // Don't set DependentUpon so it goes by convention CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName { BuildEngine = new MockEngine(_testOutput), UseDependentUponConvention = true, ResourceFiles = new ITaskItem[] { i } }; t.Execute().ShouldBeTrue("Expected the task to succeed."); t.ManifestResourceNames.ShouldHaveSingleItem(); t.ManifestResourceNames[0].ItemSpec.ShouldBe(ResourceFileName, "Expecting to find the namespace & class name from SR1.cs"); } }
public void ResourceFilesWithManifestResourceNamesContainsAdditionalMetadata() { CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName(); t.BuildEngine = new MockEngine(); ITaskItem i = new TaskItem("strings.resx"); t.ResourceFiles = new ITaskItem[] { i }; t.RootNamespace = "ResourceRoot"; bool success = t.Execute(); Assert.True(success); // "Expected the task to succeed." ITaskItem[] resourceFiles = t.ResourceFilesWithManifestResourceNames; Assert.Single(resourceFiles); Assert.Equal(@"strings.resx", resourceFiles[0].ItemSpec); Assert.Equal(@"ResourceRoot.strings", resourceFiles[0].GetMetadata("ManifestResourceName")); }
public void NoLogicalNameAddedForResx() { CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName(); t.BuildEngine = new MockEngine(); ITaskItem i = new TaskItem("strings.resx"); i.SetMetadata("Type", "Resx"); t.ResourceFiles = new ITaskItem[] { i }; t.RootNamespace = "ResourceRoot"; bool success = t.Execute(); Assert.True(success); // "Expected the task to succeed." ITaskItem[] resourceFiles = t.ResourceFilesWithManifestResourceNames; Assert.Single(resourceFiles); Assert.Equal(@"strings.resx", resourceFiles[0].ItemSpec); Assert.Equal(String.Empty, resourceFiles[0].GetMetadata("LogicalName")); }
public void AddLogicalNameForNonResx() { CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName(); t.BuildEngine = new MockEngine(); ITaskItem i = new TaskItem("pic.bmp"); i.SetMetadata("Type", "Non-Resx"); t.ResourceFiles = new ITaskItem[] { i }; t.RootNamespace = "ResourceRoot"; bool success = t.Execute(); Assert.True(success); // "Expected the task to succeed." ITaskItem[] resourceFiles = t.ResourceFilesWithManifestResourceNames; Assert.Equal(1, resourceFiles.Length); Assert.Equal(@"pic.bmp", resourceFiles[0].ItemSpec); Assert.Equal(@"ResourceRoot.pic.bmp", resourceFiles[0].GetMetadata("LogicalName")); }
public void Regress188319() { CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName(); t.BuildEngine = new MockEngine(); ITaskItem i = new TaskItem("SR1.resx"); i.SetMetadata("BuildAction", "EmbeddedResource"); i.SetMetadata("DependentUpon", "SR1.strings"); // Normally, this would be a C# file. t.ResourceFiles = new ITaskItem[] { i }; t.RootNamespace = "CustomToolTest"; bool success = t.Execute ( new Microsoft.Build.Tasks.CreateFileStream(CreateFileStream) ); Assert.True(success); // "Expected the task to succeed." ITaskItem[] resourceNames = t.ManifestResourceNames; Assert.Single(resourceNames); Assert.Equal(@"CustomToolTest.SR1", resourceNames[0].ItemSpec); }