public async Task<bool> UpdateEntry(JournalEntry journalEntry) { var entryToBeUpdated = await GetEntry(journalEntry.Id); if (entryToBeUpdated == null) { return false; //Can't find post so bail out } entryToBeUpdated.Character = journalEntry.Character; entryToBeUpdated.Title = journalEntry.Title; entryToBeUpdated.Body = journalEntry.Body; entryToBeUpdated.LastEdited = DateTime.Now; try { await Entries.ReplaceOneAsync(x => x.Id == journalEntry.Id, entryToBeUpdated); } catch (Exception e) { return false; } return true; }
public void CanSaveEntry() { var entry = new JournalEntry("UnitTestEntry", "test title", "Ttiamus"); var entryRepo = new JournalRepo(); var insertTask = entryRepo.CreateEntry(entry); insertTask.Wait(); Assert.IsTrue(insertTask.IsCompleted); }
public void CanSaveEntry() { var entry = new JournalEntry("UnitTestEntry", "test title", "Ttiamus"); JournalService entryService = new JournalService(); var insertTask = entryService.CreateEntry(entry); Assert.IsTrue(insertTask.Result); }
/// <summary> /// Calls repo to save a new post after generating an Id and createDate /// </summary> /// <param name="journalEntry"></param> /// <returns></returns> public async Task<bool> CreateEntry(JournalEntry journalEntry) { //TODO: Make an Equals overload method for Post that will check everything but the Id to see if an identical post has been made already. Check for that before insertion journalEntry.Id = ObjectId.GenerateNewId().ToString(); //journalEntry.Character = "Atyr"; //TODO: Make sure this is the signed in user if we can't pass it from the UI journalEntry.Created = DateTime.Now; return await journalRepo.CreateEntry(journalEntry); }
public void CanDeleteEntry() { var entryRepo = new JournalRepo(); var entry = new JournalEntry("CanDeleteEntry test", "test title", "Ttiamus"); entryRepo.CreateEntry(entry).Wait(); var deleteEntryTask = entryRepo.DeleteEntry(entry.Id); deleteEntryTask.Wait(); Assert.IsNull(entryRepo.GetEntry(entry.Id).Result); }
public void CanDeleteEntry() { JournalService entryService = new JournalService(); var entry = new JournalEntry("CanDeleteEntry test", "test title", "Ttiamus"); entryService.CreateEntry(entry).Wait(); var deleteEntryTask = entryService.DeleteEntry(entry.Id); deleteEntryTask.Wait(); Assert.IsNull(entryService.GetEntry(entry.Id).Result); }
public async Task<IHttpActionResult> CreateEntry(JournalEntry journalEntry) { var success = await journalService.CreateEntry(journalEntry); if (!success) { return Conflict(); } return Ok(); }
public void CanGetAllEntries() { var entryRepo = new JournalRepo(); var entryToInsert = new JournalEntry("CanGetAllEntries", "test title", "Ttiamus"); entryRepo.CreateEntry(entryToInsert).Wait(); var getAllEntriesTask = entryRepo.GetEntries(); var entries = getAllEntriesTask.Result.ToList(); Assert.IsTrue(entries.Count > 0); }
public void CanGetEntry() { JournalService entryService = new JournalService(); var entryToInsert = new JournalEntry("UnitTestEntry", "test title", "Ttiamus"); entryService.CreateEntry(entryToInsert).Wait(); var entry = entryService.GetEntry(entryToInsert.Id).Result; Assert.IsTrue(string.Equals(entry.Id, entryToInsert.Id)); }
//Id of the post is added to the object after insertion public async Task<bool> CreateEntry(JournalEntry journalEntry) { try { await Entries.InsertOneAsync(journalEntry); } catch (Exception e) { //Log exception return false; } return true; //Success }
public void CanGetTopEntries() { var entryRepo = new JournalRepo(); var entryToInsert = new JournalEntry("CanGetTopEntriesTest", "test title", "Ttiamus"); for (var i = 0; i <= 5; i++) { entryRepo.CreateEntry(entryToInsert).Wait(); } var getTopEntriesTask = entryRepo.GetEntries("Ttiamus", 0); var entries = getTopEntriesTask.Result.ToList(); Assert.IsTrue(entries.Count == 5); }
public void CanGetEntry() { var entryRepo = new JournalRepo(); var entryToInsert = new JournalEntry("UnitTestEntry", "test title", "Ttiamus"); entryRepo.CreateEntry(entryToInsert).Wait(); var entry = entryRepo.GetEntry(entryToInsert.Id).Result; var id1 = entryToInsert.Id; var id2 = entry.Id; var test = string.Equals(id1, id2); Assert.IsTrue(string.Equals(entry.Id, entryToInsert.Id)); }
public void CanGetTopEntries() { JournalService entryService = new JournalService(); var entryToInsert = new JournalEntry("CanGetAllEntries", "test title", "Ttiamus"); for (var i = 0; i <= 5; i++) { entryService.CreateEntry(entryToInsert).Wait(); } var getAllEntryTask = entryService.GetEntries("Ttiamus", 0); var entries = getAllEntryTask.Result.ToList(); Assert.IsTrue(entries.Count == 5); }
public void CanUpdateEntry() { var entryRepo = new JournalRepo(); var entryToUpdate = new JournalEntry("Entry To Update", "test title", "Ttiamus"); entryRepo.CreateEntry(entryToUpdate).Wait(); var entry = new JournalEntry("CanUpdateEntryTest", "test title", "Ttiamus") {Id = entryToUpdate.Id}; var updateEntryTask = entryRepo.UpdateEntry(entry); updateEntryTask.Wait(); Assert.AreEqual("CanUpdateEntryTest", entryRepo.GetEntry(entryToUpdate.Id).Result.Body); }
public async Task<IHttpActionResult> UpdateEntry(JournalEntry journalEntry) { var success = await journalService.UpdateEntry(journalEntry); if (!success) { return NotFound(); } return Ok("Post was updated successfully"); }
/// <summary> /// Calls the repo to update the given entry with its new values /// </summary> /// <param name="journalEntry"></param> /// <returns></returns> public async Task<bool> UpdateEntry(JournalEntry journalEntry) { journalEntry.LastEdited = DateTime.Now; return await journalRepo.UpdateEntry(journalEntry); }