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); } }
private ResolverContext InitContext() { var context = new InMemoryResolverContext(); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); return(context); }
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); } }
void DependencyAccess_CreateDependentAtom_GetDependencyViaNavigationProperty() { long atomId, dependentId; using (var context = new InMemoryResolverContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var atom = new Atom { Kind = "python", Name = "Eeg", Version = "1.0.0" }; var dependent = new Atom { Kind = "workflow", Name = "Filter", Version = "1.0.0" }; context.Atoms.Add(atom); context.Atoms.Add(dependent); context.SaveChanges(); context.AtomDependencies.Add(new AtomDependency { DependentId = dependent.Id, DependencyId = atom.Id }); context.SaveChanges(); atomId = atom.Id; dependentId = dependent.Id; } using (var context = new InMemoryResolverContext()) { var dependent = context.Atoms .Include(a => a.Dependencies) .ThenInclude(d => d.Dependency) .Single(a => a.Id == dependentId); Assert.NotEmpty(dependent.Dependencies); var atom = dependent.Dependencies.Select(d => d.Dependency).Single(); Assert.Equal("Filter", dependent.Name); Assert.Equal("Eeg", atom.Name); context.Entry(atom).Collection(a => a.Dependent).Load(); var dep = atom.Dependent.Single(); context.Entry(dep).Reference(d => d.Dependent).Load(); Assert.Equal(dependent.Name, dep.Dependent.Name); } }
public void AtomCreation_CreateDuplicate_Fail() { using (var context = new InMemoryResolverContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var atom = new Atom { Kind = "python", Name = "Eeg", Version = "1.0.0" }; context.Atoms.Add(atom); context.SaveChanges(); context.Atoms.Add(atom); Assert.Throws <ArgumentException>(() => context.SaveChanges()); } }
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); } }
public void AtomCreation_CreateSingle_SuccessfullCreation() { using (var context = new InMemoryResolverContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var atom = new Atom { Kind = "python", Name = "Eeg", Version = "1.0.0" }; context.Atoms.Add(atom); context.SaveChanges(); var created = context.Atoms.Find(atom.Id); Assert.Equal(atom.Id, created.Id); Assert.Equal(atom.Name, created.Name); Assert.Equal(atom.Kind, created.Kind); Assert.Equal(atom.Version, created.Version); } }
public void ContentAccess_CreateContent_GetContentViaNavigationProperty() { long atomId; const string Content = "print(\"Hello, eeg!\")"; using (var context = new InMemoryResolverContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var atom = new Atom { Kind = "python", Name = "Eeg", Version = "1.0.0" }; context.Atoms.Add(atom); context.SaveChanges(); atomId = atom.Id; context.AtomContents.Add(new AtomContent { AtomId = atom.Id, Content = Encoding.UTF8.GetBytes(Content) }); context.SaveChanges(); } using (var context = new InMemoryResolverContext()) { var atom = context.Atoms.Include(a => a.Content).Single(a => a.Id == atomId); var content = Encoding.UTF8.GetString(atom.Content.Content); Assert.Equal(Content, content); } }