public ActionResult Edit(Note noteToEdit, string[] newCategories) { var categories = Repository.GetAllCategories(newCategories); Repository.Update(noteToEdit, categories); return RedirectToAction("Details", new { id = noteToEdit.Id }); }
public ActionResult Create(Note noteToAdd, string[] newCategories) { if (ModelState.IsValid) { var categories = Repository.GetAllCategories(newCategories); Repository.Create(noteToAdd, categories); return RedirectToAction("Index"); } return View(noteToAdd); }
public static NoteWithCategories Convert(Note note, IEnumerable<Category> categories) { return new NoteWithCategories { Id = note.Id, Title = note.Title, Message = note.Message, Added = note.Added, Categories = categories }; }
public void ShouldCreateANoteAndAddTheDate() { // Arrange const string id = "id"; var today = DateTime.Now; var note = new Note { Id = id, Message = "Message" }; var categories = new[] { new Category { Name = "Important" } }; // Depedent-On Component var session = Substitute.For<IDocumentSession>(); // System under Test var repository = new RavenDbRepository(session); // Act repository.Create(note, categories); // Assert / Indirect Output session.Received().Store(Arg.Is<Note>(n => n.Id == id && n.Added.Date == today.Date)); session.Received().SaveChanges(); }
public void CreateACollectionWithSomeData() { CreateCollectionIfNecessary(database); MongoCollection<Note> notes = database.GetCollection<Note>(CollectionName); // Let's create a couple of documents! var note = new Note { Title = "MongoDB is fun for developers!", Message = "With Mongo Documents, there is hardly any need for excessive OR Mapping, since documents resemble objects closer that relations do!" }; var note2 = new Note { Title = "Hello", Message = "Welcome to MongoDB!" }; var noteWithCategories = new NoteWithCategories { Title = "RavenDb", Message = "RavenDb is also pretty cool, too!", Categories = new[] { new Category { Name = "Very Important" } } }; // Insert notes.Insert(note); notes.Insert(note2); notes.Insert(noteWithCategories); // Let's find them List<Note> allNotes = notes.FindAllAs<Note>().ToList(); Assert.That(allNotes.Count, Is.EqualTo(3)); // You can also marshal them as the subclass, but for this example only one will have the cargories set! List<NoteWithCategories> allNotesWithcategories = notes.FindAllAs<NoteWithCategories>().ToList(); Assert.That(allNotesWithcategories.Count, Is.EqualTo(3)); Assert.That(allNotesWithcategories.Count(n => n.Categories != null && n.Categories.Any()), Is.EqualTo(1)); }
public void ShouldUpdateANote() { // Arrange const string id = "123"; var note = new Note { Id = id, Message = "Message" }; var categories = new[] { new Category { Name = "Important" } }; // Depedent-On Component var session = Substitute.For<IDocumentSession>(); // System under Test var repository = new RavenDbRepository(session); repository.Update(note, categories); // Assert / Indirect Output session.Received().Store(Arg.Is<Note>(n => n.Id == id)); session.Received().SaveChanges(); }