public async Task SegmentControllerPutReturnsSuccessForUpdate(string mediaTypeName) { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.OK; var existingModel = A.Fake <HowToBecomeSegmentModel>(); existingModel.SequenceNumber = 123; var modelToUpsert = A.Fake <HowToBecomeSegmentModel>(); modelToUpsert.SequenceNumber = existingModel.SequenceNumber + 1; var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel); A.CallTo(() => FakeHowToBecomeSegmentService.UpsertAsync(A <HowToBecomeSegmentModel> .Ignored)).Returns(expectedResponse); // Act var result = await controller.Put(modelToUpsert).ConfigureAwait(false); // Assert A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeHowToBecomeSegmentService.UpsertAsync(A <HowToBecomeSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); var statusCodeResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)expectedResponse, statusCodeResult.StatusCode); controller.Dispose(); }
public async Task SegmentControllerPostReturnsSuccessForCreate(string mediaTypeName) { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.Created; var howToBecomeSegmentModel = A.Fake <HowToBecomeSegmentModel>(); var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns((HowToBecomeSegmentModel)null); A.CallTo(() => FakeHowToBecomeSegmentService.UpsertAsync(A <HowToBecomeSegmentModel> .Ignored)).Returns(expectedResponse); // Act var result = await controller.Post(howToBecomeSegmentModel).ConfigureAwait(false); // Assert A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeHowToBecomeSegmentService.UpsertAsync(A <HowToBecomeSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); var statusCodeResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal((int)expectedResponse, statusCodeResult.StatusCode); controller.Dispose(); }