public void AtomIdConstructorTest() { string link = "TestValue"; // TODO: Initialize to an appropriate value AtomId target = new AtomId(link); Assert.AreEqual(link, target.Uri.ToString()); }
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)); } }
/// <summary> /// Initializes a new instance of the <see cref="AtomEntryResource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>. /// </summary> /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this entry.</param> /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this entry.</param> /// <param name="updatedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was modified in a way the publisher considers significant. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <param name="editedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was edited. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <param name="isDraft">A value indicating if client has requested to control the visibility of the entry.</param> /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception> public AtomEntryResource(AtomId id, AtomTextConstruct title, DateTime updatedOn, DateTime editedOn, bool isDraft) : this(id, title, updatedOn, editedOn) { //------------------------------------------------------------ // Initialize class state using properties //------------------------------------------------------------ this.IsDraft = isDraft; }
public async Task <IEnumerable <AtomId> > GetDependenciesAsync(AtomId atomId) { atomId = await FetchVersionAsync(atomId); try { var atom = await _context.Atoms .Include(a => a.Dependencies) .ThenInclude(d => d.Dependency) .SingleAsync(a => a.Kind == atomId.Kind && a.Name == atomId.Name && a.Version == atomId.Version); var deps = from dep in atom.Dependencies select new AtomId(dep.Dependency.Kind, dep.Dependency.Name, dep.Dependency.Version); return(deps.ToList()); } catch (InvalidOperationException) { throw new ArgumentException(string.Format(AtomDoesNotExist, atomId.Kind, atomId.Name, atomId.Version)); } }
public async Task VersionWildcard_GetContent_LastContentGot() { // Given var context = InitContext(); var contentString = "Hello, world!"; var content = Encoding.UTF8.GetBytes(contentString); var atomId = new AtomId("PlainText", "Hello"); string version = "1.0.1"; var dbAtom = new Atom { Kind = atomId.Kind, Name = atomId.Name, Version = version }; dbAtom.Content = new AtomContent { Atom = dbAtom, Content = content }; context.Atoms.Add(dbAtom); context.SaveChanges(); // When using (var storage = new AtomStorage(context)) { var str = Encoding.UTF8.GetString(await storage.GetContentAsync(atomId)); // Then Assert.Equal(contentString, str); } }
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 void AtomIdConstructorTest1() { AtomId target = new AtomId(); Assert.IsNotNull(target); Assert.IsNull(target.Uri); }
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 void SettingVersion_SetValidVersion_NoException(string version) { //When var atomId = new AtomId("Text", "Hello", version); //Then Assert.Equal(version, atomId.Version); }
private async Task <bool> ExistsExactAsync(AtomId atomId) { var all = from atom in _context.Atoms where atom.Kind == atomId.Kind && atom.Name == atomId.Name && atom.Version == atomId.Version select atom; return(await all.CountAsync() == 1); }
public void IdTest() { AtomEntry target = new AtomEntry(); // TODO: Initialize to an appropriate value AtomId expected = new AtomId("http://www.test.com/"); AtomId actual; target.Id = expected; actual = target.Id; Assert.AreEqual(expected, actual); }
public void IdTest() { AtomSource target = new AtomSource(); // TODO: Initialize to an appropriate value AtomId expected = new AtomId(); AtomId actual; target.Id = expected; actual = target.Id; Assert.AreEqual(expected, actual); }
public void EqualsTest() { AtomId a = new AtomId("www.a.com"); AtomId b = new AtomId("www.b.com"); bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = a.Equals(b); Assert.AreEqual(expected, actual); }
public void op_EqualityTest() { AtomId a = new AtomId("www.a.com"); AtomId b = new AtomId("www.b.com"); bool expected = false; bool actual; actual = (a == b); Assert.AreEqual(expected, actual); }
private Contact LoadGoogleContacts(AtomId id) { string message = "Error Loading Google Contacts. Cannot connect to Google.\r\nPlease ensure you are connected to the internet. If you are behind a proxy, change your proxy configuration!"; Contact ret = null; try { GoogleContacts = new Collection <Contact>(); ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default")); query.NumberToRetrieve = 256; query.StartIndex = 0; //Group group = GetGoogleGroupByName(myContactsGroup); //if (group != null) // query.Group = group.Id; //query.ShowDeleted = false; //query.OrderBy = "lastmodified"; Feed <Contact> feed = ContactsRequest.Get <Contact>(query); while (feed != null) { foreach (Contact a in feed.Entries) { GoogleContacts.Add(a); if (id != null && id.Equals(a.ContactEntry.Id)) { ret = a; } } query.StartIndex += query.NumberToRetrieve; feed = ContactsRequest.Get <Contact>(feed, FeedRequestType.Next); } Logger.Log(UserName + " : " + GoogleContacts.Count + " contact(s)", EventType.Debug); } catch (System.Net.WebException ex) { Logger.Log(ex.Message, EventType.Error); //throw new GDataRequestException(message, ex); } catch (System.NullReferenceException ex) { Logger.Log(ex.Message, EventType.Error); //Logger.Log(message, EventType.Error); //throw new GDataRequestException(message, new System.Net.WebException("Error accessing feed", ex)); } return(ret); }
public void CompareToTest() { AtomId a = new AtomId("www.a.com"); AtomId b = new AtomId("www.a.com"); int expected = 0; int actual; actual = a.CompareTo(b); Assert.AreEqual(expected, actual); }
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 <AtomId> FetchVersionAsync(AtomId atomId) { var version = atomId.Version ?? await LastVersionAsync(atomId.Kind, atomId.Name); if (version == null) { throw new ArgumentException(string.Format(AtomDoesNotExist, atomId.Kind, atomId.Name, "lastest")); } return(new AtomId(atomId.Kind, atomId.Name, version)); }
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 void SortingAtoms_SetVersion_GotVersionNumbersAsTuple(string version, int major, int?middle, int?minor, string versionName) { // Given var atomId = new AtomId("Text", "Hello", version); // When var(a, b, c, d) = atomId.VersionTuple; // Then Assert.Equal(major, a); Assert.Equal(middle, b); Assert.Equal(minor, c); Assert.Equal(versionName, d); }
public async Task <byte[]> GetContentAsync(AtomId atomId) { atomId = await FetchVersionAsync(atomId); try { var atom = await _context.Atoms .Include(a => a.Content) .SingleAsync(a => a.Kind == atomId.Kind && a.Name == atomId.Name && a.Version == atomId.Version); return(atom.Content.Content); } catch (InvalidOperationException) { throw new ArgumentException(string.Format(AtomDoesNotExist, atomId.Kind, atomId.Name, atomId.Version)); } }
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 override int GetHashCode() { return(AtomId.GetHashCode()); }
/// If no version specified and atom does not exist, creates atom with default version "1.0.0" /// If no version specified and atom does exist, or there is an atom with specified version, /// creates new version with the same major and middle versions and incremented minor version public async Task <AtomId> AddAsync(AtomId atomId, IEnumerable <AtomId> dependencies, byte[] content) { if (await ExistsExactAsync(atomId)) { throw new ArgumentException(string.Format(AtomAlreadyExists, atomId.Kind, atomId.Name, atomId.Version)); } var version = atomId.Version ?? await LastVersionAsync(atomId.Kind, atomId.Name); if (atomId.Version == null && version != null) { VersionUtils.TryParse(version, out int major, out int?middle, out int?minor, out string name); version = VersionUtils.Serialize(major, middle.GetValueOrDefault(), minor.GetValueOrDefault() + 1, null); } else if (atomId.Version == null) { version = AtomId.DefaultVersion; } var dbAtom = new Atom { Kind = atomId.Kind, Name = atomId.Name, Version = version, }; await _context.Atoms.AddAsync(dbAtom); dependencies = await FetchVersionsAsync(dependencies); var depRefs = dependencies.Select(depId => _context.Atoms.Single(a => a.Kind == depId.Kind && a.Name == depId.Name && a.Version == depId.Version)); var dbDeps = from dep in depRefs select new AtomDependency { Dependent = dbAtom, Dependency = dep }; await _context.AtomDependencies.AddRangeAsync(dbDeps); var dbContent = new AtomContent { Atom = dbAtom, Content = content }; await _context.AtomContents.AddAsync(dbContent); await _context.SaveChangesAsync(); return(new AtomId(atomId.Kind, atomId.Name, version)); }
/// <summary> /// Initializes a new instance of the <see cref="AtomEntryResource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>. /// </summary> /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this entry.</param> /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this entry.</param> /// <param name="updatedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was modified in a way the publisher considers significant. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception> public AtomEntryResource(AtomId id, AtomTextConstruct title, DateTime updatedOn) : base(id, title, updatedOn) { //------------------------------------------------------------ // Initialization handled by base class //------------------------------------------------------------ }
public void XmlNameTest() { AtomId target = new AtomId(); Assert.AreEqual(AtomParserNameTable.XmlIdElement, target.XmlName); }
/// <summary> /// Initializes a new instance of the <see cref="AtomEntryResource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>. /// </summary> /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this entry.</param> /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this entry.</param> /// <param name="updatedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was modified in a way the publisher considers significant. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception> public AtomEntryResource(AtomId id, AtomTextConstruct title, DateTime updatedOn) : base(id, title, updatedOn) { }
/// <summary> /// Initializes a new instance of the <see cref="AtomEntryResource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>. /// </summary> /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this entry.</param> /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this entry.</param> /// <param name="updatedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was modified in a way the publisher considers significant. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <param name="editedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was edited. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception> public AtomEntryResource(AtomId id, AtomTextConstruct title, DateTime updatedOn, DateTime editedOn) : this(id, title, updatedOn) { this.EditedOn = editedOn; }
IEnumerable <AtomId> GetDependencies(AtomId atom) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="AtomEntryResource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>. /// </summary> /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this entry.</param> /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this entry.</param> /// <param name="updatedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was modified in a way the publisher considers significant. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <param name="editedOn"> /// A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was edited. /// The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC). /// </param> /// <param name="isDraft">A value indicating if client has requested to control the visibility of the entry.</param> /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception> public AtomEntryResource(AtomId id, AtomTextConstruct title, DateTime updatedOn, DateTime editedOn, bool isDraft) : this(id, title, updatedOn, editedOn) { this.IsDraft = isDraft; }