public async Task <IActionResult> Post([FromBody] AtomCreationRequest request) { if (request == null) { return(BadRequest("Invalid atom creation request format")); } try { var atomId = new AtomId(request.Kind, request.Name, request.Version); var realId = await _storage.AddAsync(atomId, request .Dependencies .Select(dep => new AtomId(dep.Kind, dep.Name, dep.Version)), Convert.FromBase64String(request.Content ?? string.Empty)); return(Ok(realId)); } catch (ArgumentException e) { return(NotFound(e.Message)); } catch (FormatException e) { return(BadRequest(e.Message)); } }
public async Task AtomCreation_CreateAtomNoDeps_AtomWithNoDepsCreated() { // Given var context = InitContext(); var contentString = "Hello, world!"; var content = Encoding.UTF8.GetBytes(contentString); var atomId = new AtomId("PlainText", "Hello", "1.0.1"); // When using (var storage = new AtomStorage(context)) { await storage.AddAsync(atomId, Enumerable.Empty <AtomId>(), content); } // Then using (context = new InMemoryResolverContext()) { var dbAtom = context.Atoms.Include(a => a.Content) .Include(a => a.Dependencies) .ThenInclude(dep => dep.Dependency) .Single(a => a.Kind == atomId.Kind && a.Name == atomId.Name && a.Version == atomId.Version); Assert.Empty(dbAtom.Dependencies); var actualContentString = Encoding.UTF8.GetString(dbAtom.Content.Content); Assert.Equal(contentString, actualContentString); } }
public async Task VersionWildcard_CreateAtomWithoutPredcessors_CreatedAtomWithDefaultVersion() { // Given var context = InitContext(); var contentString = "Hello, world!"; var content = Encoding.UTF8.GetBytes(contentString); var atomId = new AtomId("PlainText", "Hello"); // When using (var storage = new AtomStorage(context)) { await storage.AddAsync(atomId, Enumerable.Empty <AtomId>(), content); } // Then using (context = new InMemoryResolverContext()) { var dbAtom = context.Atoms.Single(a => a.Kind == atomId.Kind && a.Name == atomId.Name); Assert.Equal(AtomId.DefaultVersion, dbAtom.Version); } }
public async Task DependecyResolutionOrdering_MultipleAtomsDependent_CorrectOrderReturned() { var storage = new AtomStorage(InitContext()); var si = await storage.AddAsync(new AtomId("fsdecl", "SI"), Enumerable.Empty <AtomId>(), new byte[0]); var eeg = await storage.AddAsync(new AtomId("fsdecl", "Eeg"), Enumerable.Empty <AtomId>().Append(si), new byte[0]); var resolver = new Resolver.Endpoint.Resolver(storage); var resolved = await resolver.ResolveAsync(new [] { new AtomId("fsdecl", "Eeg"), new AtomId("fsdecl", "SI") }); Assert.Equal(new [] { si, eeg }, resolved); }
public async Task DependecyResolutionOrdering_SingleAtomDuplicateDeps_CorrectOrderReturned() { var storage = new AtomStorage(InitContext()); var si = await storage.AddAsync(new AtomId("fsdecl", "SI"), Enumerable.Empty <AtomId>(), new byte[0]); var eeg = await storage.AddAsync(new AtomId("fsdecl", "Eeg"), Enumerable.Empty <AtomId>().Append(si), new byte[0]); var workflow = await storage.AddAsync(new AtomId("filomena", "IcaFiltering"), Enumerable.Empty <AtomId>().Append(eeg).Append(si), new byte[0]); var resolver = new Resolver.Endpoint.Resolver(storage); var resolved = await resolver.ResolveAsync(new [] { workflow }); Assert.Equal(new [] { si, eeg, workflow }, resolved); }
public async Task AtomCreation_CreateAtomWithDeps_AtomWithDepsCreated() { // 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 }; context.Atoms.Add(dbAtomDep); context.SaveChanges(); // When using (var storage = new AtomStorage(context)) { await storage.AddAsync(dependent, Enumerable.Empty <AtomId>().Append(dependency), content); } // Then using (context = new InMemoryResolverContext()) { var dbAtom = context.Atoms.Include(a => a.Content) .Include(a => a.Dependencies) .ThenInclude(dep => dep.Dependency) .Single(a => a.Kind == dependent.Kind && a.Name == dependent.Name && a.Version == dependent.Version); Assert.Single(dbAtom.Dependencies); var dependencyAtom = dbAtom.Dependencies.Single().Dependency; Assert.Equal(dbAtomDep.Kind, dependencyAtom.Kind); Assert.Equal(dbAtomDep.Name, dependencyAtom.Name); Assert.Equal(dbAtomDep.Version, dependencyAtom.Version); } }
public async Task DependencyResolution_NotDependentAtomPassed_AtomOnlyReturned() { var storage = new AtomStorage(InitContext()); var atomId = await storage.AddAsync(new AtomId("text", "hello"), Enumerable.Empty <AtomId>(), new byte[0]); var resolver = new Resolver.Endpoint.Resolver(storage); var resolved = await resolver.ResolveAsync(new [] { atomId }); Assert.Single(resolved); var resolvedId = resolved.Single(); Assert.Equal(atomId, resolvedId); }
public async Task VersionWildcard_CreateAtomWithPredcessor_CreatedAtomWithMinorIncremented( string predcessorVersion, string expectedVersion) { // Given var context = InitContext(); var contentString = "Hello, world!"; var content = Encoding.UTF8.GetBytes(contentString); var atomId = new AtomId("PlainText", "Hello"); var dbAtom = new Atom { Kind = atomId.Kind, Name = atomId.Name, Version = predcessorVersion }; context.Atoms.Add(dbAtom); context.SaveChanges(); // When using (var storage = new AtomStorage(context)) { await storage.AddAsync(atomId, Enumerable.Empty <AtomId>(), content); } // Then using (context = new InMemoryResolverContext()) { var addedAtom = context.Atoms.Single(a => a.Kind == atomId.Kind && a.Name == atomId.Name && a.Version != predcessorVersion); Assert.Equal(expectedVersion, addedAtom.Version); } }