public async Task <IActionResult> GetInfo(string kind, string name, [FromQuery] string version) { try { var atomId = await _storage.FetchVersionAsync(new AtomId(kind, name, version)); var dependencies = await _storage.GetDependenciesAsync(atomId); return(Ok(new AtomInfo { Kind = kind, Name = name, Version = atomId.Version, Dependencies = dependencies.ToList() })); } catch (ArgumentException e) { return(NotFound(e.Message)); } catch (FormatException e) { return(BadRequest(e.Message)); } }
private async Task AtomDfs(AtomId atom, HashSet <AtomId> resolved, List <AtomId> ordered) { var current = await _storage.FetchVersionAsync(atom); var deps = await _storage.GetDependenciesAsync(current); foreach (var dep in deps) { await AtomDfs(dep, resolved, ordered); } if (!resolved.Contains(current)) { resolved.Add(current); ordered.Add(current); } }
public async Task AtomAсquisition_GetDependencies_DependenciesGot() { // Given var context = InitContext(); var contentString = "Hello, world!"; var content = Encoding.UTF8.GetBytes(contentString); var dependency = new AtomId("PlainText", "Hello", "1.0.1"); var dependent = new AtomId("Sentence", "World", "1.0.0"); var dbAtomDep = new Atom { Kind = dependency.Kind, Name = dependency.Name, Version = dependency.Version }; dbAtomDep.Content = new AtomContent { Atom = dbAtomDep, Content = content }; var dbAtom = new Atom { Kind = dependent.Kind, Name = dependent.Name, Version = dependent.Version }; dbAtom.Content = new AtomContent { Atom = dbAtom, Content = content }; dbAtom.Dependencies = new List <AtomDependency> { new AtomDependency { Dependent = dbAtom, Dependency = dbAtomDep } }; context.Atoms.Add(dbAtomDep); context.Atoms.Add(dbAtom); context.SaveChanges(); // When using (var storage = new AtomStorage(context)) { var deps = await storage.GetDependenciesAsync(dependent); Assert.Single(deps); var dep = deps.Single(); // Then Assert.Equal(dependency.Kind, dep.Kind); Assert.Equal(dependency.Name, dep.Name); Assert.Equal(dependency.Version, dep.Version); } }