예제 #1
0
            public async void Should_return_error_with_message()
            {
                // Arrange
                var duplicateAuthor = new Author
                {
                    Name        = "Katherine Man",
                    Nationality = new Nationality {
                        Name = "Mountains"
                    }
                };
                var result = new Result();

                result.AddError("there was an error");
                AuthorServiceMock
                .Setup(x => x.AddAuthorAsync(duplicateAuthor))
                .ReturnsAsync(result);

                // Act
                var requestResult = await ControllerUnderTest.AddAuthor(duplicateAuthor);

                // Assert
                var okResult = Assert.IsType <OkObjectResult>(requestResult);

                Assert.Same(result, okResult.Value);
            }
예제 #2
0
            public async void Should_return_bad_request()
            {
                // Arrange
                var author = new Author
                {
                    Name        = "Matherine Kan",
                    Nationality = new Nationality {
                        Name = "Springwood"
                    }
                };

                ControllerUnderTest.ModelState.AddModelError("Key", "This doesn't look right");

                // Act
                var result = await ControllerUnderTest.AddAuthor(author);

                // Assert
                var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

                Assert.IsType <SerializableError>(badRequestResult.Value);
            }
예제 #3
0
            public async void Should_return_OK_with_author()
            {
                // Arrange
                var expectedAuthor = new Author
                {
                    Name        = "Katherine Man",
                    Nationality = new Nationality {
                        Name = "Mountains"
                    }
                };
                var result = new Result();

                AuthorServiceMock
                .Setup(x => x.AddAuthorAsync(expectedAuthor))
                .ReturnsAsync(result);

                // Act
                var requestResult = await ControllerUnderTest.AddAuthor(expectedAuthor);

                // Assert
                var okResult = Assert.IsType <OkObjectResult>(requestResult);

                Assert.Same(result, okResult.Value);
            }