public void AddEntryAndRetrieveTest() { IAtomEntryRepository repository = GetEntryRepository(); // create an entry AtomSite.Domain.AtomEntry entry = new AtomSite.Domain.AtomEntry() { Id = new Id("test.com", "2008", Guid.NewGuid().ToString()), Title = new AtomText() { Text = "Test Title" }, Updated = DateTimeOffset.Now, Published = DateTimeOffset.Now, Content = new AtomContent() { Text = "Test content" }, Authors = new List<AtomSite.Domain.AtomPerson> { new AtomSite.Domain.AtomAuthor() { Name = "Author" } }, Media = false, Control = new AppControl() { AllowAnnotate = false, Approved = false, Draft = true } }; entry.SetProperty<string>("test", "test attribute"); // save the entry entry = repository.CreateEntry(entry); AtomSite.Domain.AtomEntry dbEntry = repository.GetEntry(entry.Id); Assert.AreEqual(entry.Title, dbEntry.Title); Assert.IsTrue(entry.Updated.Subtract(dbEntry.Updated).Seconds < 1); if (entry.Published.HasValue) { Assert.IsTrue(entry.Published.Value.Subtract(dbEntry.Published.Value).Seconds < 1); } Assert.AreEqual(entry.Content, dbEntry.Content); Assert.AreEqual(entry.Authors.First(), dbEntry.Authors.First()); Assert.AreEqual(entry.Media, dbEntry.Media); Assert.AreEqual(entry.Control, dbEntry.Control); Assert.AreEqual(dbEntry.GetProperty<string>("test"), "test attribute"); }
private AtomEntry GetParentEntry(AtomEntry entry) { Id parentId = entry.Id.GetParentId(); if (parentId != null) { return GetEntryById(parentId); } return null; }
public AtomEntry UpdateEntry(AtomEntry entry) { AtomEntry existingEntry = GetEntryById(entry.Id); if (existingEntry == null) { entriesList.Add(entry); eTags.Add(entry.Id.ToString(), 1); } else { int index = IndexOfId(entry.Id); entriesList[index] = entry; // entry has changed, increment the entry's eTag string eTagKey = entry.Id.ToString(); eTags[eTagKey] = eTags[eTagKey] + 1; } return entry; }
public AtomEntry CreateEntry(AtomEntry entry) { if (!entriesList.Contains(entry)) { entriesList.Add(entry); eTags.Add(entry.Id.ToString(), 1); Domain.AtomEntry parent = GetParentEntry(entry); if (parent != null) { AttachAnnotation(parent, entry); } } return entry; }