Пример #1
0
        public async Task SegmentControllerUpdateReturnsSuccessForExistingItem(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.OK;
            var controller = BuildSegmentController(mediaTypeName);

            var existingModel = A.Fake <CurrentOpportunitiesSegmentModel>();
            var modelToUpsert = A.Fake <CurrentOpportunitiesSegmentModel>();

            existingModel.SequenceNumber = 123;
            modelToUpsert.SequenceNumber = existingModel.SequenceNumber + 1;

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel);
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(expectedResponse);

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
        public async Task SegmentControllerBodyReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var documentId         = Guid.NewGuid();
            var expectedResult     = A.Fake <CurrentOpportunitiesSegmentModel>();
            var dummyBodyViewModel = A.Dummy <BodyViewModel>();

            dummyBodyViewModel.Data         = A.Dummy <BodyDataViewModel>();
            dummyBodyViewModel.Data.Courses = A.Dummy <BodyCoursesViewModel>();

            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(dummyBodyViewModel);

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

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

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

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

            controller.Dispose();
        }
        public async Task SegmentControllerBodyJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var documentId     = Guid.NewGuid();
            var expectedResult = A.Fake <CurrentOpportunitiesSegmentModel>();

            expectedResult.Data = A.Dummy <CurrentOpportunitiesSegmentDataModel>();
            var dummyBodyViewModel = A.Dummy <BodyViewModel>();

            dummyBodyViewModel.Data         = A.Dummy <BodyDataViewModel>();
            dummyBodyViewModel.Data.Courses = A.Dummy <BodyCoursesViewModel>();

            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(dummyBodyViewModel);

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

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

            var jsonResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsAssignableFrom <CurrentOpportunitiesSegmentDataModel>(jsonResult.Value);

            controller.Dispose();
        }
Пример #4
0
        public async Task SegmentControllerCreateReturnsAlreadyReportedForExisting(string mediaTypeName)
        {
            // Arrange
            var currentOpportunitiesSegmentModel = A.Fake <CurrentOpportunitiesSegmentModel>();
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(A.Fake <CurrentOpportunitiesSegmentModel>());

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Пример #5
0
        public async Task SegmentControllerDeleteReturnsNotFound(string mediaTypeName)
        {
            // Arrange
            Guid documentId = Guid.NewGuid();
            CurrentOpportunitiesSegmentModel expectedResult = null;
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(expectedResult);

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
Пример #6
0
        public async Task SegmentControllerUpdateReturnsNotFoundForNonExisting(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.NotFound;
            var currentOpportunitiesSegmentModel  = A.Fake <CurrentOpportunitiesSegmentModel>();
            var controller = BuildSegmentController(mediaTypeName);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns((CurrentOpportunitiesSegmentModel)null);

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

            // Assert
            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();

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

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

            controller.Dispose();
        }
        public async Task JobTitlePrefixDefaultTests(string jobTitle, string titlePrefix, string expectedTitle)
        {
            //Arrange
            var documentId = Guid.NewGuid();

            testSegmentModel.Data.JobTitle    = jobTitle;
            testSegmentModel.Data.TitlePrefix = titlePrefix;

            var controller = BuildSegmentController(MediaTypeNames.Text.Html);

            A.CallTo(() => FakeCurrentOpportunitiesSegmentService.GetByIdAsync(A <Guid> .Ignored)).Returns(testSegmentModel);
            A.CallTo(() => FakeMapper.Map <BodyViewModel>(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(testBodyViewModel);

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

            //Asserts
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = viewResult.Model as BodyViewModel;

            model.Data.JobTitleWithPrefix.Should().Be(expectedTitle);
            controller.Dispose();
        }