Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save johanvergeer/a0d88a8857827cdc7d7ff9c23d698beb to your computer and use it in GitHub Desktop.

Select an option

Save johanvergeer/a0d88a8857827cdc7d7ff9c23d698beb to your computer and use it in GitHub Desktop.

Revisions

  1. johanvergeer created this gist May 19, 2019.
    20 changes: 20 additions & 0 deletions PersonControllerSpec.Post_PersonWithoutName_PersonNotSaved.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    [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);
    }