Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanvergeer/a0d88a8857827cdc7d7ff9c23d698beb to your computer and use it in GitHub Desktop.
Save johanvergeer/a0d88a8857827cdc7d7ff9c23d698beb to your computer and use it in GitHub Desktop.
Person with invalid state will not be added
[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