Created
May 19, 2019 14:57
-
-
Save johanvergeer/a0d88a8857827cdc7d7ff9c23d698beb to your computer and use it in GitHub Desktop.
Person with invalid state will not be added
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void Post_PersonWithoutName_PersonNotSaved() | |
{ | |
// Create new person, without a name, which will not be accepted by the controller | |
var person = new Person(); | |
// Create new controller with mock repository | |
var controller = new PersonController(this._repository.Object); | |
// Call controller to post person | |
var result = controller.Post(person); | |
// Assert | |
result.Should().BeOfType<BadRequestObjectResult>(); | |
result.As<BadRequestObjectResult>() | |
.Value.Should().Be("Person has invalid state"); | |
this._repository.Verify(r => r.Add(It.IsAny<Person>()), Times.Never); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment