public void IncludeAndExcludeWorkWithRelativeAndAbsolutePaths( string projectContents, string includeItem, string includeRelativePath, string excludeItem, string excludeRelativePath, string[] inputFiles, bool includeSurvivesExclude) { Func<bool, string, string, string, string> adjustFilePath = (isAbsolute, testRoot, relativeFragmentFromRootToFile, file) => isAbsolute ? Path.GetFullPath(Path.Combine(testRoot, relativeFragmentFromRootToFile, file)) : Path.Combine(relativeFragmentFromRootToFile, file); Action<bool, bool> runTest = (includeIsAbsolute, excludeIsAbsolute) => { using (var testProject = new Helpers.TestProjectWithFiles(projectContents, inputFiles, "project")) { var projectFile = testProject.ProjectFile; var projectFileDir = Path.GetDirectoryName(projectFile); var include = adjustFilePath(includeIsAbsolute, projectFileDir, includeRelativePath, includeItem); var exclude = adjustFilePath(excludeIsAbsolute, projectFileDir, excludeRelativePath, excludeItem); // includes and exclude may be absolute, so we can only format the project after we have the test directory paths var formattedProject = string.Format(projectContents, include, exclude); File.WriteAllText(projectFile, formattedProject); var expectedInclude = includeSurvivesExclude ? new[] { include } : new string[0]; ObjectModelHelpers.AssertItems(expectedInclude, new Project(projectFile).Items.ToList()); } }; runTest(true, false); runTest(false, true); runTest(true, true); }
public void RemoveMetadataThrowsWhenItemElementSplittingIsDisabledAndItemComesFromGlob(string projectContents, int itemIndex, string[] files) { using (var testProject = new Helpers.TestProjectWithFiles(projectContents, files)) { var projectFile = testProject.ProjectFile; AssertDisabledItemSplitting( projectContents, itemIndex, null, (p, i) => { i.RemoveMetadata("bar"); }, "bar", p => { File.WriteAllText(projectFile, p); return new Project(projectFile); }); } }
private static List<ProjectItem> GetItemsFromFragmentWithGlobs(string itemGroupFragment, params string[] globFiles) { var formattedProjectContents = ObjectModelHelpers.FormatProjectContentsWithItemGroupFragment(itemGroupFragment); List<ProjectItem> itemsFromFragmentWithGlobs; using (var testProject = new Helpers.TestProjectWithFiles(formattedProjectContents, globFiles)) { itemsFromFragmentWithGlobs = Helpers.MakeList(new Project(testProject.ProjectFile).GetItems("i")); } return itemsFromFragmentWithGlobs; }