public async Task <Unit> Handle(CreateAuthorCommand request, CancellationToken cancellationToken) { var result = await _context.Authors.AddAsync(new Domain.Entities.Authors { AuthorName = request.AuthorName, AuthorLastName = request.AuthorLastName }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); await TryInitializeBooksAsync(request, result, cancellationToken); await _mediator.Publish(new AuthorCreated { AuthorId = result.Entity.AuthorId }, cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(CreateBookCommand request, CancellationToken cancellationToken) { var result = await _context.Books.AddAsync(new Domain.Entities.Books { BookName = request.BookName, PublishYear = request.PublishYear }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); await TryInitializeAuthorsAsync(request, result, cancellationToken); await _mediator.Publish(new BookCreated { BookId = result.Entity.BookId }, cancellationToken); return(Unit.Value); }
private async Task SeedTestData(ILibraryContext context) { context.Users.Add(new User("FirstName", "LastName", new Email("*****@*****.**"), UserRolesConsts.Reader)); context.Users.Add(new User("FirstName", "LastName", new Email("*****@*****.**"), UserRolesConsts.Reader)); context.Users.Add(new User("FirstName", "LastName", new Email("*****@*****.**"), UserRolesConsts.Librarian)); await context.SaveChangesAsync(); }
private async Task SeedTestData(ILibraryContext context) { context.Books.Add(new Book("To Kill a Mockingbird", new Author("Harper", "Lee"), 1960, "Beautiful story about how humans treat each other.")); context.Books.Add(new Book("The Great Gatsby", new Author("Scott", "Fitzgerald"), 1925, "The greatest, most scathing dissection of the hollowness at the heart of the American dream.")); context.Books.Add(new Book("One Hundred Years of Solitude", new Author("Gabriel", "Marquez"), 1813, "Both funny and moving.")); context.Books.Add(new Book("In Cold Blood", new Author("Truman", "Capote"), 1965, "The true crime TV show.")); context.Books.Add(new Book("Go Set a Watchman", new Author("Harper", "Lee"), 2015, "Stunning novel that is worth reading.")); await context.SaveChangesAsync(); }
public async Task Handle_UserExists_UserDetails() { // Arrange var user = new User("FirstName", "LastName", new Email("*****@*****.**"), UserRolesConsts.Reader); _libraryContext.Users.Add(user); await _libraryContext.SaveChangesAsync(); var query = new GetReaderDetailsQuery() { UserId = user.Id }; // Act var userDetailsDto = await _sut.Handle(query, CancellationToken.None); // Assert userDetailsDto.Should().NotBeNull(); userDetailsDto.Id.Should().Be(user.Id); }
public async Task Handle_BookExists_BookDetails() { // Arrange var book = new Book("Title", new Author("FirstName", "LastName"), 2020, "Description"); _libraryContext.Books.Add(book); await _libraryContext.SaveChangesAsync(); var query = new GetBookDetailsQuery() { BookId = book.Id }; // Act var bookDetailsDto = await _sut.Handle(query, CancellationToken.None); // Assert bookDetailsDto.Should().NotBeNull(); bookDetailsDto.Id.Should().Be(book.Id); }