/// <summary> /// This view will be rendered if answer is in the URL string. /// </summary> /// <returns></returns> public async Task <IActionResult> MyContent() { var culture = this.Culture; var requestPath = this.RequestPathNoCulture; // Now try to parse the request path into known words. var commonStrings = _resourcesService.GetCommonStrings(culture); var answer = LinkingHelper.ParseUrlToAnswer(commonStrings, requestPath); // Were we able to parse? if (answer == null) { return(RedirectToAction("Index")); } // Let's try to find that answer answer = await _answerService.FindExact(answer.LeftWord, answer.RightWord, answer.Phrase); // Go to home index if not found if (answer == null) { return(RedirectToAction("Index")); } // Get data var answerDetails = FillInDetails(answer, _answerDescriptionService, _userService, _voteService, _resourcesService, culture, _appSettings.Value.FullDomainAddress); // Do a bit more playing with data answerDetails.EnableFacebookSharing = _appSettings.Value.EnableFacebookSharing; answerDetails.DebugReactControls = ReadUrlParameterAsBoolean(DEBUG_REACTJS_URL_PARAMETER_NAME); return(View(answerDetails)); }
public void LinkingHelperTests_Nulls_ReturnsNull() { var answerDto = new AnswerDto() { LeftWord = "a", RightWord = "b", Phrase = "c" }; var result = LinkingHelper.ParseUrlToAnswer(null); Assert.Null(result); result = LinkingHelper.ParseUrlToAnswer(" "); Assert.Null(result); result = LinkingHelper.ParseUrlToAnswer("random"); Assert.Null(result); result = LinkingHelper.ParseUrlToAnswer(null, null); Assert.Null(result); result = LinkingHelper.ParseUrlToAnswer(null, " "); Assert.Null(result); var commonStrings = new CommonStringsDto() { Best = "x", For = "y", Is = "z" }; result = LinkingHelper.ParseUrlToAnswer(commonStrings, "random"); Assert.Null(result); }
public void LinkingHelperTests_ParseUrlToAnswer_Parses() { var answerDto = new AnswerDto() { LeftWord = "a", RightWord = "b", Phrase = "c" }; var url = "/best-a-for-b-is-c"; var result = LinkingHelper.ParseUrlToAnswer(url); Assert.Equal(result.LeftWord, answerDto.LeftWord); Assert.Equal(result.RightWord, answerDto.RightWord); Assert.Equal(result.Phrase, answerDto.Phrase); var commonStrings = new CommonStringsDto() { Best = "x", For = "y", Is = "z" }; url = "/x-a-y-b-z-c"; result = result = LinkingHelper.ParseUrlToAnswer(commonStrings, url); Assert.Equal(result.LeftWord, answerDto.LeftWord); Assert.Equal(result.RightWord, answerDto.RightWord); Assert.Equal(result.Phrase, answerDto.Phrase); }
public void LinkingHelper_ParseAnswerUrl_Fail() { string data = "/best-girl-f or-the-dance-is-alice"; var answer = LinkingHelper.ParseUrlToAnswer(data); Assert.Null(answer); }
public void LinkingHelper_ParseAnswerUrl_Success() { string data = "/best-girl-for-the-dance-is-alice"; var answer = LinkingHelper.ParseUrlToAnswer(data); Assert.Equal(answer.LeftWord, "girl"); Assert.Equal(answer.RightWord, "the dance"); Assert.Equal(answer.Phrase, "alice"); }