public static NoteDto FromNote(Note note, bool includeTags = true) { var model = new NoteDto { NoteId = note.NoteId, Title = note.Title, Slug = note.Slug, Body = note.Body, LastModifiedOn = $"{note.LastModifiedOn.ToLocalTime()}" }; if (includeTags) { model.Tags = note.NoteTags.Select(x => TagDto.FromTag(x.Tag)).ToList(); } return(model); }
public async Task ShouldHandleSaveNoteCommandRequest() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "ShouldHandleSaveNoteCommandRequest") .Options; var mediator = new Mock <IMediator>(); mediator.Setup(m => m.Publish(It.IsAny <NoteSaved>(), It.IsAny <CancellationToken>())) .Verifiable(); using (var context = new AppDbContext(options, mediator.Object)) { var handler = new SaveNoteCommand.Handler(context); var tag = new Tag() { Name = "Angular" }; context.Tags.Add(tag); context.SaveChanges(); var response = await handler.Handle(new SaveNoteCommand.Request() { Note = new NoteDto() { Title = "Quinntyne", Tags = new List <TagDto>() { TagDto.FromTag(tag) } } }, default(CancellationToken)); Assert.NotEqual(default(Guid), response.NoteId); } }