Inheritance: IQuestionService
        public void GivenAnInValidQuestion_Create_ReturnsAResultView()
        {
            using (IDocumentSession documentSession = DocumentStore.OpenSession())
            {
                // Arrange.
                IQuestionService questionService = new QuestionService(documentSession);
                var questionsController = new QuestionsController(documentSession, questionService);
                ControllerUtilities.SetUpControllerContext(questionsController);
                var createInputModel = new CreateInputModel
                                           {
                                               Content = "Some content",
                                               Subject = null,
                                               // RuRoh - dat ist missin'
                                               Tags = "tag1 tag2 tag3-3-3"
                                           };

                // Now pretend the model binding raised an error with the input model.
                questionsController.ModelState.AddModelError("key", "error message");

                // Act.
                var result = questionsController.Create(createInputModel) as ViewResult;

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Create", result.ViewName);
            }
        }
Exemplo n.º 2
0
        public void GivenAnQuestionWithInvalidData_Create_StoresAQuestion()
        {
            // Arrange.
            Question question = new Question(); // Empty, invalid question
            var documentSession = new Mock<IDocumentSession>();
            IQuestionService questionService = new QuestionService(documentSession.Object);

            // Act & Assert.
            Assert.Throws<ValidationException>(() => questionService.Create(question));
        }
Exemplo n.º 3
0
        public void GivenAnQuestionWithInvalidData_Create_StoresAQuestion()
        {
            // Arrange.
            Question question = FakeQuestions.CreateAFakeQuestion(null, null); // No user created this question.
            var documentSession = new Mock<IDocumentSession>();
            IQuestionService questionService = new QuestionService(documentSession.Object);

            // Act & Assert.
            Assert.Throws<ValidationException>(() => questionService.Create(question));
        }
Exemplo n.º 4
0
            public void GivenAnQuestionWithInvalidData_Create_ThrowsAnException()
            {
                // Arrange.
                var question = Builder<Question>.CreateNew().Build();
                question.Subject = null; // Forces it to be invalid.
                var documentSession = new Mock<IDocumentSession>();
                IQuestionService questionService = new QuestionService(documentSession.Object);

                // Act & Assert.
                Assert.Throws<ArgumentNullException>(() => questionService.Store(question));
                documentSession.Verify(x => x.Store(It.IsAny<Question>()), Times.Never());
            }
Exemplo n.º 5
0
            public void GivenAnQuestionWithValidData_Create_StoresAQuestion()
            {
                // Arrange.
                var question = FakeQuestions.CreateAFakeQuestion("someUserId", null);
                var documentSession = new Mock<IDocumentSession>();
                IQuestionService questionService = new QuestionService(documentSession.Object);

                // Act.
                questionService.Store(question);

                // Assert.
                documentSession.Verify(x => x.Store(It.IsAny<Question>()), Times.Once());
            }
Exemplo n.º 6
0
        public void GivenAnQuestionWithValidData_Create_StoresAQuestion()
        {
            // Arrange.
            Question question = FakeQuestions.CreateAFakeQuestion("users/1", null);
            var documentSession = new Mock<IDocumentSession>();
            IQuestionService questionService = new QuestionService(documentSession.Object);

            // Act.
            questionService.Create(question);

            // Assert.
            documentSession.Verify(x => x.Store(question), Times.Once());
            documentSession.Verify(x => x.SaveChanges(), Times.Once());
        }
            public void GivenAValidQuestionAndNoOneIsLoggedIn_Create_ReturnsAResultView()
            {
                // Arrange.
                var questionService = new QuestionService(DocumentSession);
                var questionsController = new QuestionsController(DocumentSession, questionService);
                ControllerUtilities.SetUpControllerContext(questionsController);
                var createInputModel = new QuestionInputModel();

                // Act.
                var result = questionsController.Create(createInputModel) as ViewResult;

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Create", result.ViewName);
            }
            public void GivenAnInvalidQuestion_Create_ReturnsAResultView()
            {
                // Arrange.
                var questionService = new QuestionService(DocumentSession);
                var questionsController = new QuestionsController(DocumentSession, questionService);
                ControllerUtilities.SetUpControllerContext(questionsController);
                var createInputModel = new QuestionInputModel();

                // Now pretend the model binding raised an error with the input model.
                questionsController.ModelState.AddModelError("key", "error message");

                // Act.
                var result = questionsController.Create(createInputModel) as ViewResult;

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Create", result.ViewName);
            }
        public void GivenAValidQuestionAndNoOneIsLoggedIn_Create_ReturnsAResultView()
        {
            // Arrange.
            IQuestionService questionService = new QuestionService();
            var questionsController = new QuestionsController(DocumentStore, questionService);
            ControllerUtilities.SetUpControllerContext(questionsController);
            var createInputModel = new CreateInputModel
                                   {
                                       Content = "Some content",
                                       Subject = "Subject",
                                       Tags = "tag1 tag2 tag3-3-3"
                                   };
            // Act.
            var result = questionsController.Create(createInputModel) as ViewResult;

            // Assert.
            Assert.NotNull(result);
            Assert.Equal("Create", result.ViewName);
        }
        public void GivenAValidQuestionAndALoggedInUser_Create_AddsTheQuestionAndRedicects()
        {
            // Arrange.
            IQuestionService questionService = new QuestionService();
            var questionsController = new QuestionsController(DocumentStore, questionService);
            ControllerUtilities.SetUpControllerContext(questionsController, "users/1");
            var createInputModel = new CreateInputModel
                                   {
                                       Content = "Some content",
                                       Subject = "Subject",
                                       Tags = "tag1 tag2 tag3-3-3"
                                   };
            // Act.
            var result = questionsController.Create(createInputModel) as RedirectToRouteResult;

            // Assert.
            Assert.NotNull(result);
            Assert.Equal("Index", result.RouteValues["action"]);
        }
            public void GivenAValidQuestionAndALoggedInUser_Create_AddsTheQuestionAndRedicects()
            {
                // Arrange.
                var questionService = new QuestionService(DocumentSession);
                var questionsController = new QuestionsController(DocumentSession, questionService);
                ControllerUtilities.SetUpControllerContext(questionsController, "users/1");
                var createInputModel =
                    new QuestionInputModel
                    {
                        Subject = "aaaad fdds fsd ds",
                        Content = "sdhfskfhksd sd",
                        Tags = "ahdakjdh"
                    };

                // Act.
                var result = questionsController.Create(createInputModel) as RedirectToRouteResult;

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("Index", result.RouteValues["action"]);
            }