Beispiel #1
0
        public async Task SendCommandWithDefaultFields_ShouldReturnValidationError()
        {
            var command = new AddBookToLibraryCommand()
            {
                Title   = string.Empty,
                Authors = new List <string>()
            };

            var result = await SendAsync(command);

            result.Succeeded.Should().BeFalse();
            result.ErrorType.Should().Be(RequestError.ValidationError);
        }
Beispiel #2
0
        public async Task SendValidCommand_ShouldAddBookToLibrary()
        {
            var command = new AddBookToLibraryCommand()
            {
                Authors = new List <string>()
                {
                    Arrange.Author_1, Arrange.Author_2
                },
                Title = Arrange.Title
            };

            var result = await SendAsync(command);

            var book = await GetBookAsync(Arrange.Title);

            result.Succeeded.Should().BeTrue();
            book.Authors.Should().OnlyContain(a => a.Name == Arrange.Author_1 || a.Name == Arrange.Author_2);
        }
Beispiel #3
0
        public async Task SendDuplicateBook_ShouldReturnAlreadyExistsError()
        {
            var command = new AddBookToLibraryCommand()
            {
                Authors = new List <string>()
                {
                    _duplicateAuthor
                },
                Title = _duplicateTitle
            };

            await SendAsync(command);

            var result = await SendAsync(command); // Sending same data

            result.Succeeded.Should().BeFalse();
            result.ErrorType.Should().Equals(RequestError.AlreadyExists);
        }
Beispiel #4
0
        public async Task Add_Book_ToLibrary_Test()
        {
            AddBookToLibraryCommand command =
                new AddBookToLibraryCommand(_authorRepoMock.Object, _mybookRepoMock.Object, _bookRepoMock.Object);

            var parameters = new AddBookParameters
            {
                UserId          = Guid.NewGuid(),
                Title           = "test title",
                AuthorFirstName = "firstname",
                AuthorLastName  = "lastname",
                Isbn            = "test"
            };

            CommandResult <AddBookResult> result = await command.HandleAsync(parameters);

            Assert.True(result.Succeeded);
            Assert.IsType <AddBookResult>(result.Data);
            Assert.Equal("test", result.Data.ISBN);
        }
        public async Task <ActionResult> AddToLibrary(AddBookToLibraryCommand request)
        {
            var result = await Mediator.Send(request);

            return(result.Succeeded ? NoContent() : StatusCode(_errorToStatusCode.Convert(result.ErrorType)));
        }