public DependencyMatrix GetDependencyMatrix(string projectStartsWith, string packageStartsWith) { var dependencyMatrix = new DependencyMatrix(); var packages = _context.Packages.AsQueryable(); if (!string.IsNullOrEmpty(packageStartsWith)) { packages = packages.Where(s => s.Name.StartsWith(packageStartsWith)); } foreach (var package in packages) { var projects = package.Projects.AsQueryable(); if (!string.IsNullOrEmpty(projectStartsWith)) { // Here we need StringComparison.InvariantCultureIgnoreCase because this goes against in-memory collection and // not SQL which is case-sensitive by default. projects = projects.Where(s => s.Name.StartsWith(projectStartsWith, StringComparison.InvariantCultureIgnoreCase)); } foreach (var project in projects) // This requires MARS MultipleActiveResultSets=True in connection string { dependencyMatrix.AddDependency($"{package.Name} {package.Version}", project.Name); } } dependencyMatrix.Sort(); return(dependencyMatrix); }
public void DependencyMatrix_Basic() { // a b c // d x // e x // f x var dm = new DependencyMatrix(); dm.AddDependency("d", "a"); dm.AddDependency("e", "c"); dm.AddDependency("f", "b"); dm.Sort(); CollectionAssert.AreEqual(dm.Rows.Select(s => s.Value), new string[] { "d", "e", "f" }); CollectionAssert.AreEqual(dm.Columns.Select(s => s.Value), new string[] { "a", "b", "c" }); Assert.IsTrue(dm.Matrix[dm.Rows[0].Id, dm.Columns[0].Id]); Assert.IsFalse(dm.Matrix[dm.Rows[0].Id, dm.Columns[1].Id]); Assert.IsFalse(dm.Matrix[dm.Rows[0].Id, dm.Columns[2].Id]); Assert.IsFalse(dm.Matrix[dm.Rows[1].Id, dm.Columns[0].Id]); Assert.IsFalse(dm.Matrix[dm.Rows[1].Id, dm.Columns[1].Id]); Assert.IsTrue(dm.Matrix[dm.Rows[1].Id, dm.Columns[2].Id]); Assert.IsFalse(dm.Matrix[dm.Rows[2].Id, dm.Columns[0].Id]); Assert.IsTrue(dm.Matrix[dm.Rows[2].Id, dm.Columns[1].Id]); Assert.IsFalse(dm.Matrix[dm.Rows[2].Id, dm.Columns[2].Id]); }