public UpdateBookCommandHandlerTests() { _publication = new PublicationCommand { Edition = 1, Year = DateTime.Now.Year }; _bookRepository = new Mock <IBookRepository>(); var publicationValidator = new PublicationCommandValidator(); var updateBookCommandValidator = new UpdateBookCommandValidator(_bookRepository.Object, publicationValidator); _eventPublisher = new Mock <IEventPublisher <BookEvent> >(); _updateBookCommandHandler = new UpdateBookCommandHandler(updateBookCommandValidator, _bookRepository.Object, _eventPublisher.Object); }
public async Task Update_Book() { using (var context = GetContextWithData()) { var handler = new UpdateBookCommandHandler(context); var categoryId = Guid.NewGuid(); await AddCategory(context, categoryId, "nothing"); var command = new UpdateBookCommand { Id = (await context.Books.FirstOrDefaultAsync()).Id, Title = "Title2", Categories = new List <GetBookModelCategory> { new GetBookModelCategory { Id = categoryId, Name = "nothing" } } }; await handler.Handle(command, CancellationToken.None); var book = await context.Books .Include(c => c.BookCategories) .ThenInclude(c => c.Category) .Where(b => b.Id == command.Id) .FirstOrDefaultAsync(); var bookCategories = book.BookCategories.Select(b => new GetBookModelCategory { Id = b.CategoryId, Name = b.Category.Name }) .ToList(); Assert.Equal(command.Title, book.Title); Assert.Equal(command.Categories.Count, book.BookCategories.Count); Assert.Equal(command.Categories.ToList().FirstOrDefault()?.Id, bookCategories.FirstOrDefault()?.Id); Assert.Equal(command.Categories.ToList().FirstOrDefault()?.Name, bookCategories.FirstOrDefault()?.Name); } }
public UpdateBookCommandTests() { _repository = A.Fake <IBooksRepository>(); _mapper = Helpers.CreateMapper(); _handler = new UpdateBookCommandHandler(_repository, _mapper, A.Fake <ILogger <UpdateBookCommandHandler> >()); }