public void MatchFileNameOnlyWithAnInvalidPath() { FindAppConfigFile f = new FindAppConfigFile(); f.BuildEngine = new MockEngine(); f.PrimaryList = new ITaskItem[] { new TaskItem("yyy"), new TaskItem("xxx") }; f.SecondaryList = new ITaskItem[] { new TaskItem("|||"), new TaskItem(@"foo\\app.config"), new TaskItem(@"!@#$@$%|"), new TaskItem("uuu") }; f.TargetPath = "targetpath"; Assert.True(f.Execute()); // Should ignore the invalid paths Assert.Equal(FileUtilities.FixFilePath(@"foo\\app.config"), f.AppConfigFile.ItemSpec); }
public void FoundInFirstInProjectDirectory() { FindAppConfigFile f = new FindAppConfigFile(); f.BuildEngine = new MockEngine(); f.PrimaryList = new ITaskItem[] { new TaskItem("app.config"), new TaskItem("xxx") }; f.SecondaryList = new ITaskItem[] { }; f.TargetPath = "targetpath"; Assert.True(f.Execute()); Assert.Equal("app.config", f.AppConfigFile.ItemSpec); Assert.Equal("targetpath", f.AppConfigFile.GetMetadata("TargetPath")); }
public void FoundInSecondBelowProjectDirectory() { FindAppConfigFile f = new FindAppConfigFile(); f.BuildEngine = new MockEngine(); f.PrimaryList = new ITaskItem[] { new TaskItem("yyy"), new TaskItem("xxx") }; f.SecondaryList = new ITaskItem[] { new TaskItem("foo\\app.config"), new TaskItem("xxx") }; f.TargetPath = "targetpath"; Assert.True(f.Execute()); Assert.Equal(FileUtilities.FixFilePath("foo\\app.config"), f.AppConfigFile.ItemSpec); Assert.Equal("targetpath", f.AppConfigFile.GetMetadata("TargetPath")); }
private static string GetAppConfigFile(Project project) { // TODO: it wouldn't work for a .netcore|.netstandard var primaryList = new List <TaskItem>(64); foreach (var projectItem in project.GetItems("None")) { var metadata = new Dictionary <string, string>(32); foreach (var item in projectItem.Metadata) { metadata.Add(item.Name, item.EvaluatedValue); } primaryList.Add(new TaskItem(projectItem.EvaluatedInclude.GetFullPath(project.DirectoryPath), metadata)); } var secondaryList = new List <TaskItem>(64); foreach (var projectItem in project.GetItems("Content")) { var metadata = new Dictionary <string, string>(32); foreach (var item in projectItem.Metadata) { metadata.Add(item.Name, item.EvaluatedValue); } secondaryList.Add(new TaskItem(projectItem.EvaluatedInclude.GetFullPath(project.DirectoryPath), metadata)); } using (var logger = LogManager.GetLogger("FindAppConfig")) { logger.Info("Executing FindAppConfigFile task......"); var findTask = new FindAppConfigFile { BuildEngine = new MsBuildEngine(logger), PrimaryList = primaryList.ToArray(), SecondaryList = secondaryList.ToArray(), TargetPath = project.GetPropertyValue("TargetPath") + ".config" }; var result = findTask.Execute(); if (result) { logger.Info("FindAppConfigFile task was successfully done"); } else { logger.Error("FindAppConfigFile task was failed"); } return(findTask.AppConfigFile?.ItemSpec); } }
public void ReturnsLastOne() { FindAppConfigFile f = new FindAppConfigFile(); f.BuildEngine = new MockEngine(); ITaskItem item1 = new TaskItem("app.config"); item1.SetMetadata("id", "1"); ITaskItem item2 = new TaskItem("app.config"); item2.SetMetadata("id", "2"); f.PrimaryList = new ITaskItem[] { item1, item2 }; f.SecondaryList = new ITaskItem[] { }; f.TargetPath = "targetpath"; Assert.True(f.Execute()); Assert.Equal("app.config", f.AppConfigFile.ItemSpec); Assert.Equal(item2.GetMetadata("id"), f.AppConfigFile.GetMetadata("id")); }