Exemple #1
0
        public void IndexReturnsAnagramsViewModel_WithAllData()
        {
            string testWord = "Viedas";
            var    testIp   = _homeController.HttpContext.Connection.RemoteIpAddress.ToString();

            _anagramsService
            .GetAnagrams(Arg.Is(testWord), Arg.Is(testIp))
            .Returns(GetTestAnagrams());

            var result = _homeController.Index(testWord) as ViewResult;

            _anagramsService.Received(1).GetAnagrams(testWord, testIp);

            result.ShouldBeOfType <ViewResult>();
            result.ViewData.Model.ShouldBeOfType <AnagramsViewModel>();

            var anagramsViewModel = result.Model as AnagramsViewModel;

            anagramsViewModel.Anagrams.ShouldNotBeNull();
            anagramsViewModel.Anagrams.Count.ShouldNotBeNull();
            anagramsViewModel.Anagrams.Count.ShouldBe(3);

            anagramsViewModel.Anagrams.First().ShouldNotBeNull();
            anagramsViewModel.Anagrams.First().ShouldBeOfType <Anagram>();
            anagramsViewModel.Anagrams.First().Text.ShouldBe("deivas");

            anagramsViewModel.Phrase.ShouldNotBeNull();
            anagramsViewModel.Phrase.Text.ShouldBe(testWord);

            anagramsViewModel.ErrorMessage.ShouldBeNull();
        }
Exemple #2
0
        public void GetAnagramsReturnsBadRequest_WhenWordIsNullOrWhitespace()
        {
            string testWord = "  ";
            var    testIp   = _anagramsController.HttpContext.Connection.RemoteIpAddress.ToString();

            _anagramsService
            .GetAnagrams(Arg.Is(testWord), Arg.Is(testIp))
            .Returns(GetTestAnagrams());

            var result = _anagramsController.GetAnagrams(testWord);

            _anagramsService.Received(0).GetAnagrams(testWord, testIp);

            result.ShouldBeOfType <ActionResult <List <string> > >();
            var badRequestResult = result.Result as BadRequestResult;

            badRequestResult.ShouldNotBeNull();
        }