Example #1
0
        public async Task ReturnsNotAcceptableForInvalidMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobProfileTasksSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);
            var viewModel      = GetBodyViewModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(viewModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Example #2
0
        public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = A.Fake <JobProfileTasksSegmentModel>();
            var controller     = BuildSegmentController(mediaTypeName);
            var viewModel      = GetBodyViewModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(viewModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Example #3
0
        public async Task ReturnsSuccessForJsonMediaType(string mediaTypeName)
        {
            // Arrange
            var expectedResult = new JobProfileTasksSegmentModel();
            var controller     = BuildSegmentController(mediaTypeName);
            var apiModel       = GetDummyApiModel();

            expectedResult.CanonicalName = ArticleName;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksDataSegmentModel> .Ignored)).Returns(apiModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksDataSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
        public async Task ReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            const int resultsCount = 0;
            IEnumerable <JobProfileTasksSegmentModel> expectedResults = null;
            var controller             = BuildSegmentController(mediaTypeName);
            var indexDocumentViewModel = new IndexDocumentViewModel {
                CanonicalName = "job-profile-1"
            };

            A.CallTo(() => FakeJobProfileSegmentService.GetAllAsync()).Returns(expectedResults);
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).Returns(indexDocumentViewModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetAllAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <IndexDocumentViewModel>(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappened(resultsCount, Times.Exactly);

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IndexViewModel>(viewResult.ViewData.Model);

            Assert.Null(model.Documents);

            controller.Dispose();
        }
        public async Task ReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var existingModel = new JobProfileTasksSegmentModel {
                SequenceNumber = 123
            };
            var modelToUpsert = new JobProfileTasksSegmentModel {
                SequenceNumber = 124
            };
            var controller             = BuildSegmentController(mediaTypeName);
            var expectedUpsertResponse = HttpStatusCode.OK;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel);
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).Returns(expectedUpsertResponse);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.OK, statusCodeResult.StatusCode);

            controller.Dispose();
        }
        public async Task SegmentControllerPatchLocationReturnsSuccessForSuccessfulResponse(HttpStatusCode expectedStatus)
        {
            // Arrange
            var controller = BuildSegmentController();
            var model      = new PatchLocationModel();

            A.CallTo(() => FakeJobProfileSegmentService.PatchLocationAsync(A <PatchLocationModel> .Ignored, A <Guid> .Ignored)).Returns(expectedStatus);

            // Act
            var result = await controller.PatchLocation(model, Guid.NewGuid()).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.PatchLocationAsync(A <PatchLocationModel> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

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

            controller.Dispose();
        }
        public async Task ReturnsNotFoundWhenDocumentDoesNotAlreadyExist()
        {
            // Arrange
            var jobProfileTasksSegmentModel = new JobProfileTasksSegmentModel();
            var controller = BuildSegmentController();

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns((JobProfileTasksSegmentModel)null);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustNotHaveHappened();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.NotFound, statusCodeResult.StatusCode);

            controller.Dispose();
        }
Example #8
0
        public async Task ReturnsSuccessForHtmlMediaType(string mediaTypeName)
        {
            // Arrange
            var controller = BuildSegmentController(mediaTypeName);
            var dbModels   = GetSegmentModels();

            A.CallTo(() => FakeJobProfileSegmentService.GetAllAsync()).Returns(dbModels);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentRefreshService.SendMessageListAsync(A <List <RefreshJobProfileSegmentServiceBusModel> > .Ignored)).MustHaveHappenedOnceExactly();
            var res = Assert.IsType <JsonResult>(result);

            Assert.Equal(dbModels.Count, (res.Value as List <RefreshJobProfileSegmentServiceBusModel>).Count);

            controller.Dispose();
        }
Example #9
0
        public async Task ReturnsNoContentWhenDocumentDoesNotExist()
        {
            // Arrange
            var controller = BuildSegmentController();

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored))
            .Returns((JobProfileTasksSegmentModel)null);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <WhatYouWillDoApiModel>(A <JobProfileTasksSegmentModel> .Ignored))
            .MustNotHaveHappened();

            Assert.IsType <NoContentResult>(result);

            controller.Dispose();
        }
        public async Task ReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            JobProfileTasksSegmentModel expectedResult = null;
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeJobProfileSegmentService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Document(Article).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var statusResult = Assert.IsType <NoContentResult>(result);

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

            controller.Dispose();
        }
        public async Task ReturnsNotFoundWhenDocumentIdDoesNotExist(string mediaTypeName)
        {
            // Arrange
            const bool documentExists = false;
            var        documentId     = Guid.NewGuid();
            var        controller     = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeJobProfileSegmentService.DeleteAsync(documentId)).Returns(documentExists);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.DeleteAsync(documentId)).MustHaveHappenedOnceExactly();
            var statusResult = Assert.IsType <NotFoundResult>(result);

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

            controller.Dispose();
        }
Example #12
0
        public async Task ReturnsNoContentWhenNoData(string mediaTypeName)
        {
            // Arrange
            List <JobProfileTasksSegmentModel> expectedResult = null;
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeJobProfileSegmentService.GetAllAsync()).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentRefreshService.SendMessageListAsync(A <List <RefreshJobProfileSegmentServiceBusModel> > .Ignored)).MustNotHaveHappened();
            var statusResult = Assert.IsType <NoContentResult>(result);

            A.CallTo(() => FakeLogger.LogWarning(A <string> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal((int)HttpStatusCode.NoContent, statusResult.StatusCode);

            controller.Dispose();
        }
Example #13
0
        public async Task ReturnsAlreadyReportedIfEntityExists(string mediaTypeName)
        {
            // Arrange
            var tasksSegmentModel      = A.Fake <JobProfileTasksSegmentModel>();
            var controller             = BuildSegmentController(mediaTypeName);
            var expectedUpsertResponse = HttpStatusCode.AlreadyReported;

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(tasksSegmentModel);
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).Returns(expectedUpsertResponse);

            // Act
            var result = await controller.Post(tasksSegmentModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustNotHaveHappened();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.AlreadyReported, statusCodeResult.StatusCode);

            controller.Dispose();
        }
        public async Task ReturnsAlreadyReportedWhenExistingSequenceNumberIsHigher()
        {
            // Arrange
            var existingModel = new JobProfileTasksSegmentModel {
                SequenceNumber = 999
            };
            var modelToUpsert = new JobProfileTasksSegmentModel {
                SequenceNumber = 124
            };
            var controller = BuildSegmentController();

            A.CallTo(() => FakeJobProfileSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel);

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

            // Assert
            A.CallTo(() => FakeJobProfileSegmentService.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustNotHaveHappened();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.AlreadyReported, statusCodeResult.StatusCode);

            controller.Dispose();
        }