Пример #1
0
        public void SavePalindrome(PalindromeModel palindrome)
        {
            Palindrome newPalindrome = new Palindrome()
            {
                Id             = palindrome.Id,
                PalindromeWord = palindrome.PalindromeWord
            };

            _repository.Insert(newPalindrome);
        }
Пример #2
0
 public IHttpActionResult SavePalindrome(PalindromeModel palindrome)
 {
     try
     {
         _palindromeManager.SavePalindrome(palindrome);
         return(Content(HttpStatusCode.OK, new { status = "Success", data = "Palindrome saved successfully." }));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "PalindromeController.SaveBidTracker :: Unhandled exception");
         return(Content(HttpStatusCode.InternalServerError, new { status = "Failed", error = ex.ToString() }));
     }
 }
        public IActionResult Solution(string input)
        {
            var pm = new PalindromeModel
            {
                Input   = input,
                Reverse = string.Join("", input.Reverse().ToArray()),
                Result  = ""
            };

            if (pm.Input == pm.Reverse)
            {
                pm.Result = "Palindrome!";
            }
            else
            {
                pm.Result = "Not a palindrome...";
            }
            return(RedirectToAction("Result", pm));
        }
Пример #4
0
        public IEnumerable <PalindromeModel> FindPalindromes(string inputText, int numberOfPalindromes)
        {
            IEnumerable <string> palindromsText = this.palindromeFinder.GetLongestPalindromes(inputText, numberOfPalindromes);

            IList <PalindromeModel> palindroms = new List <PalindromeModel>(numberOfPalindromes);

            foreach (string nextPalindrome in palindromsText)
            {
                PalindromeModel model = new PalindromeModel
                {
                    StartingIndex = inputText.GetStartingIndex(nextPalindrome),
                    Text          = nextPalindrome,
                    Length        = nextPalindrome.Length
                };
                palindroms.Add(model);
            }

            return(palindroms);
        }
Пример #5
0
        public ActionResult <bool> Palindrome([FromBody] PalindromeModel model)
        {
            if (model.PalindromeOrNot == null)
            {
                return(false);
            }

            bool isPalindrome = true;

            for (int i = 0; i < model.PalindromeOrNot.Length / 2; i++)
            {
                if (model.PalindromeOrNot[i] != model.PalindromeOrNot[model.PalindromeOrNot.Length - i - 1])
                {
                    isPalindrome = false;
                }
            }

            return(isPalindrome);
        }
        public async Task GivenAppService_WhenValidPhraseIsPassed_ThenViewModelValidated_And_PhraseAdded_And_IdRetrievedBack()
        {
            //Arrange
            var             expectedId  = Guid.NewGuid();
            var             mockAppRepo = new Mock <IAppRepository>();
            PalindromeModel model       = null;

            mockAppRepo.Setup(x => x.Create(It.IsAny <PalindromeModel>())).Callback((PalindromeModel x) => { model = x; }).Verifiable();
            mockAppRepo.Setup(x => x.SaveAsync()).Callback(() => { model.Id = expectedId; }).Returns(Task.FromResult <object>(null)).Verifiable();
            var mockModelValidator   = new Mock <IModelValidator>();
            var mockPaymentValidator = new Mock <PalindromeVmValidator>();
            var autoMapperConfig     = new MapperConfiguration(cfg => cfg.AddProfile(new AppProfile()));
            var objectMapper         = new ObjectMapper(autoMapperConfig.CreateMapper());
            var palindromeService    = new PalindromeService(mockAppRepo.Object, mockModelValidator.Object, objectMapper);

            //Act
            var receiptNum = await palindromeService.Add(new PalindromeVm());

            //Assert
            receiptNum.ShouldBe(expectedId);
            mockModelValidator.Verify(x => x.ValidateAsync <PalindromeVm, PalindromeVmValidator>(It.IsAny <PalindromeVm>()), Times.Once);
            mockAppRepo.Verify(x => x.SaveAsync(), Times.Once);
            mockAppRepo.Verify(x => x.Create(It.IsAny <PalindromeModel>()), Times.Once);
        }
 public IActionResult Result(PalindromeModel model)
 {
     return(View(model));
 }