public void It_excludes_items_in_a_custom_outputpath() { Action <GetValuesCommand> setup = getValuesCommand => { WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Output", "CSharpInOutput.cs"), "!InvalidCSharp!"); WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Code", "Class1.cs"), "public class Class1 {}"); }; Action <XDocument> projectChanges = project => { var ns = project.Root.Name.Namespace; var propertyGroup = new XElement(ns + "PropertyGroup"); project.Root.Add(propertyGroup); propertyGroup.Add(new XElement(ns + "OutputPath", "Output")); }; var compileItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "Compile", setup, projectChanges: projectChanges); RemoveGeneratedCompileItems(compileItems); var expectedItems = new[] { "Helper.cs", @"Code\Class1.cs" } .Select(item => item.Replace('\\', Path.DirectorySeparatorChar)) .ToArray(); compileItems.Should().BeEquivalentTo(expectedItems); }
public void It_ignores_excluded_folders() { Action <GetValuesCommand> setup = getValuesCommand => { foreach (string folder in new[] { "bin", "obj", ".vscode" }) { WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, folder, "source.cs"), "!InvalidCSharp!"); } WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Code", "Class1.cs"), "public class Class1 {}"); WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Packages", "Package.cs"), "public class Package {}"); }; var compileItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "Compile", setup); RemoveGeneratedCompileItems(compileItems); var expectedItems = new[] { "Helper.cs", @"Code\Class1.cs", @"Packages\Package.cs" } .Select(item => item.Replace('\\', Path.DirectorySeparatorChar)) .ToArray(); compileItems.Should().BeEquivalentTo(expectedItems); }
public void It_allows_a_CSharp_file_to_be_used_as_Content() { Action <GetValuesCommand> setup = getValuesCommand => { WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Code", "Class1.cs"), "public class Class1 {}"); WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "CSharpAsContent.cs"), "public class CSharpAsContent {}"); WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "None.txt"), "Content file"); }; Action <XDocument> projectChanges = project => { var ns = project.Root.Name.Namespace; XElement itemGroup = new XElement(ns + "ItemGroup"); project.Root.Add(itemGroup); itemGroup.Add(new XElement(ns + "Content", new XAttribute("Include", "CSharpAsContent.cs"), new XAttribute("CopyToOutputDirectory", "true"))); itemGroup.Add(new XElement(ns + "Compile", new XAttribute("Remove", "CSharpAsContent.cs"))); }; var compileItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "Compile", setup, projectChanges: projectChanges); RemoveGeneratedCompileItems(compileItems); var expectedItems = new[] { "Helper.cs", @"Code\Class1.cs", } .Select(item => item.Replace('\\', Path.DirectorySeparatorChar)) .ToArray(); compileItems.Should().BeEquivalentTo(expectedItems); var contentItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "Content", setup, projectChanges: projectChanges); var expectedContentItems = new[] { "CSharpAsContent.cs", } .Select(item => item.Replace('\\', Path.DirectorySeparatorChar)) .ToArray(); contentItems.Should().BeEquivalentTo(expectedContentItems); var noneItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "None", setup, projectChanges: projectChanges); var expectedNoneItems = new[] { "None.txt" } .Select(item => item.Replace('\\', Path.DirectorySeparatorChar)) .ToArray(); noneItems.Should().BeEquivalentTo(expectedNoneItems); }
public void It_allows_a_project_subfolder_to_be_excluded() { Action <GetValuesCommand> setup = getValuesCommand => { WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Code", "Class1.cs"), "public class Class1 {}"); WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Excluded", "Excluded.cs"), "!InvalidCSharp!"); }; Action <XDocument> projectChanges = project => { var ns = project.Root.Name.Namespace; XElement itemGroup = new XElement(ns + "ItemGroup"); project.Root.Add(itemGroup); itemGroup.Add(new XElement(ns + "Compile", new XAttribute("Remove", "Excluded\\**\\*.cs"))); }; var compileItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "Compile", setup, projectChanges: projectChanges); RemoveGeneratedCompileItems(compileItems); var expectedItems = new[] { "Helper.cs", @"Code\Class1.cs", } .Select(item => item.Replace('\\', Path.DirectorySeparatorChar)) .ToArray(); compileItems.Should().BeEquivalentTo(expectedItems); }
public void It_allows_excluded_folders_to_be_overridden() { Action <GetValuesCommand> setup = getValuesCommand => { foreach (string folder in new[] { "bin", "obj", "packages" }) { WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, folder, "source.cs"), $"public class ClassFrom_{folder} {{}}"); } WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Code", "Class1.cs"), "public class Class1 {}"); }; Action <XDocument> projectChanges = project => { var ns = project.Root.Name.Namespace; project.Root.Element(ns + "PropertyGroup").Add(new XElement(ns + "EnableDefaultItems", "False")); XElement itemGroup = new XElement(ns + "ItemGroup"); project.Root.Add(itemGroup); itemGroup.Add(new XElement(ns + "Compile", new XAttribute("Include", "**\\*.cs"))); }; var compileItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "Compile", setup, new[] { "/p:DisableDefaultRemoves=true" }, GetValuesCommand.ValueType.Item, projectChanges: projectChanges); RemoveGeneratedCompileItems(compileItems); var expectedItems = new[] { "Helper.cs", @"Code\Class1.cs", @"bin\source.cs", @"obj\source.cs", @"packages\source.cs" } .Select(item => item.Replace('\\', Path.DirectorySeparatorChar)) .ToArray(); compileItems.Should().BeEquivalentTo(expectedItems); }