Ejemplo n.º 1
0
        public void SutIsController()
        {
            var repoDummy = new QuestionRepoDouble();
            var sut       = new HomeController(repoDummy);

            Assert.IsAssignableFrom <IController>(sut);
        }
Ejemplo n.º 2
0
        public void AddQuestionRendersDefaultView()
        {
            var repoDummy = new QuestionRepoDouble();
            var sut       = new HomeController(repoDummy);

            sut.WithCallTo(c => c.AddQuestion())
            .ShouldRenderDefaultView();
        }
Ejemplo n.º 3
0
        public void SearchTagsReturnsCorrectModelType()
        {
            var repoDummy = new QuestionRepoDouble();
            var sut       = new HomeController(repoDummy);
            var actual    = sut.SearchTags("").JsonRequestBehavior;

            Assert.Equal(JsonRequestBehavior.AllowGet, actual);
        }
Ejemplo n.º 4
0
        public void AddQuestionRedirectsToIndexIfSuccessful()
        {
            var repoSpy       = new QuestionRepoDouble();
            var questionDummy = new QuestionInput();
            var sut           = new HomeController(repoSpy);

            sut.WithCallTo(c => c.AddQuestion(questionDummy))
            .ShouldRedirectTo(c => c.Index());
        }
Ejemplo n.º 5
0
        public void IndexReturnsModelWithCorrectRecordCount()
        {
            var repoStub = new QuestionRepoDouble();
            var sut      = new HomeController(repoStub);

            sut.WithCallTo(c => c.Index())
            .ShouldRenderDefaultView()
            .WithModel <IEnumerable <Question> >(actual => actual.Count() == 1);
        }
Ejemplo n.º 6
0
        public void IndexReturnsCorrectModelType()
        {
            var repoDummy = new QuestionRepoDouble();
            var sut       = new HomeController(repoDummy);

            sut.WithCallTo(c => c.Index())
            .ShouldRenderDefaultView()
            .WithModel <IEnumerable <Question> >();
        }
Ejemplo n.º 7
0
        public void AddQuestionInteractsWithQuestionRepo()
        {
            var repoDummy     = new QuestionRepoDouble();
            var questionDummy = new QuestionInput();
            var sut           = new HomeController(repoDummy);

            sut.WithCallTo(c => c.AddQuestion(questionDummy))
            .ShouldRedirectTo(c => c.Index());
            Assert.Equal(1, repoDummy.AddCallCount);
        }
Ejemplo n.º 8
0
        public void IndexReturnsModelWithLatestRecordFirst()
        {
            var repoStub = new QuestionRepoDouble();

            repoStub.Questions.Add(new Question {
                Title = "Foo"
            });
            repoStub.Questions.Add(new Question {
                Title = "Bar"
            });
            var sut = new HomeController(repoStub);

            sut.WithCallTo(c => c.Index())
            .ShouldRenderDefaultView()
            .WithModel <IEnumerable <Question> >(actual => actual.First().Title == "Bar");
        }
Ejemplo n.º 9
0
        public void AddInvalidQuestionReturnsError()
        {
            var repoDummy     = new QuestionRepoDouble();
            var questionDummy = new QuestionInput();
            var sut           = new HomeController(repoDummy);

            sut.ViewData.ModelState.AddModelError("Title", "");
            sut.ViewData.ModelState.AddModelError("Body", "");
            sut.ViewData.ModelState.AddModelError("Tags", "");
            sut.WithCallTo(c => c.AddQuestion(questionDummy))
            .ShouldRenderDefaultView()
            .WithModel <QuestionInput>()
            .AndModelErrorFor(m => m.Title)
            .AndModelErrorFor(m => m.Body)
            .AndModelErrorFor(m => m.Tags);
        }
Ejemplo n.º 10
0
        public void SearchTagsReturnsCorrectResult(
            string searchTerm,
            int expectedTagCount)
        {
            var repoStub = new QuestionRepoDouble();

            repoStub.Questions.Add(
                new Question {
                Tags = new[] { "wibble", "wobble" }
            });
            repoStub.Questions.Add(
                new Question {
                Tags = new[] { "wibble", "fred" }
            });
            var sut    = new HomeController(repoStub);
            var actual = ((IEnumerable <string>)sut.SearchTags(searchTerm).Data).Count();

            Assert.Equal(expectedTagCount, actual);
        }