示例#1
0
        public void ProfileServiceGetByAlternativeNameReturnsSuccess()
        {
            // arrange
            const string alternativeName = "name1";
            var          expectedResult  = A.Fake <JobProfileModel>();

            A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).Returns(expectedResult);

            // act
            var result = jobProfileService.GetByAlternativeNameAsync(alternativeName).Result;

            // assert
            A.CallTo(() => repository.GetAsync(A <Expression <Func <JobProfileModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            A.Equals(result, expectedResult);
        }
示例#2
0
        public async Task <IActionResult> Body(string article)
        {
            logService.LogInformation($"{nameof(Body)} has been called");
            var host = Request.GetBaseAddress();

            if (!redirectionSecurityService.IsValidHost(host))
            {
                logService.LogWarning($"Invalid host {host}.");
                return(BadRequest($"Invalid host {host}."));
            }

            var jobProfileModel = await jobProfileService.GetByNameAsync(article).ConfigureAwait(false);

            if (jobProfileModel != null)
            {
                var viewModel = mapper.Map <BodyViewModel>(jobProfileModel);
                logService.LogInformation($"{nameof(Body)} has returned content for: {article}");
                viewModel.SmartSurveyJP = this.feedbackLinks.SmartSurveyJP;

                return(ValidateJobProfile(viewModel, jobProfileModel));
            }

            var alternateJobProfileModel = await jobProfileService.GetByAlternativeNameAsync(article).ConfigureAwait(false);

            if (alternateJobProfileModel != null)
            {
                var alternateUrl = $"{host}{ProfilePathRoot}/{alternateJobProfileModel.CanonicalName}";
                logService.LogWarning($"{nameof(Body)} has been redirected for: {article} to {alternateUrl}");

                return(RedirectPermanentPreserveMethod(alternateUrl));
            }

            logService.LogWarning($"{nameof(Body)} has not returned any content for: {article}");
            return(NotFound());
        }