Exemplo n.º 1
0
        public async Task SegmentControllerGetBodyJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var howToBecomeSegmentModel = new HowToBecomeSegmentModel {
                CanonicalName = "SomeCanonicalName"
            };
            var fakeHowToBecomeApiModel = A.Dummy <HowToBecomeApiModel>();

            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(howToBecomeSegmentModel);
            A.CallTo(() => FakeMapper.Map <HowToBecomeApiModel>(A <HowToBecomeSegmentDataModel> .Ignored)).Returns(fakeHowToBecomeApiModel);

            // Act
            var result = await controller.Body(documentId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <HowToBecomeApiModel>(A <HowToBecomeSegmentDataModel> .Ignored)).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);

            Assert.IsAssignableFrom <HowToBecomeApiModel>(jsonResult.Value);

            controller.Dispose();
        }
Exemplo n.º 2
0
        public async Task SegmentControllerPutReturnsAlreadyReportedForUpdate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.AlreadyReported;
            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);

            // Act
            var result = await controller.Put(modelToUpsert).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)expectedResponse, statusCodeResult.StatusCode);

            controller.Dispose();
        }
Exemplo n.º 3
0
        public async Task SegmentControllerGetBodyHtmlReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns((HowToBecomeSegmentModel)null);

            // Act
            var result = await controller.Body(documentId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            var statusResult = Assert.IsType <NoContentResult>(result);

            Assert.Equal((int)HttpStatusCode.NoContent, statusResult.StatusCode);

            controller.Dispose();
        }
Exemplo n.º 4
0
        public async Task SegmentControllerGetBodyPlainMediaTypeReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <HowToBecomeSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <HowToBecomeSegmentModel> .Ignored)).Returns(A.Fake <DocumentViewModel>());

            // Act
            var result = await controller.Body(documentId).ConfigureAwait(false);

            var viewResult = Assert.IsType <StatusCodeResult>(result);

            // Assert
            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <HowToBecomeSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.Equal((int)HttpStatusCode.NotAcceptable, viewResult.StatusCode);
            controller.Dispose();
        }
Exemplo n.º 5
0
        public async Task SegmentControllerGetBodyHtmlReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <HowToBecomeSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <HowToBecomeSegmentModel> .Ignored)).Returns(A.Fake <DocumentViewModel>());

            // Act
            var result = await controller.Body(documentId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeHowToBecomeSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <HowToBecomeSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model);

            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();
        }