public void Resolve_GetsQuestionById() { var mockQuestionsRepository = MockRepository.GenerateStub <QuestionsRepository>(); var stubViewQuestionMapper = MockRepository.GenerateStub <ViewQuestionMapper>(); var controller = new ExamsController(mockQuestionsRepository, null, stubViewQuestionMapper); controller.Resolve(1); mockQuestionsRepository.AssertWasCalled(m => m.GetById(1)); }
public void Resolve_ReturnsQuestionView() { var stubQuestionsRepository = MockRepository.GenerateStub <QuestionsRepository>(); var stubViewQuestionMapper = MockRepository.GenerateMock <ViewQuestionMapper>(); var mockViewQuestion = MockRepository.GenerateMock <ViewQuestion>(); stubViewQuestionMapper.Stub(s => s.GetViewQuestion(Arg <Question> .Is.Anything)).Return(mockViewQuestion); var controller = new ExamsController(stubQuestionsRepository, null, stubViewQuestionMapper); var result = controller.Resolve(0) as ViewResult; Assert.AreEqual(mockViewQuestion, result.ViewData.Model); }
public void Resolve_GetsAViewModelObject() { var mockViewQuestionMapper = MockRepository.GenerateMock <ViewQuestionMapper>(); var stubQuestionsRepository = MockRepository.GenerateStub <QuestionsRepository>(); var stubQuestion = MockRepository.GenerateStub <Question>(); stubQuestionsRepository.Stub(s => s.GetById(Arg <int> .Is.Anything)).Return(stubQuestion); var controller = new ExamsController(stubQuestionsRepository, null, mockViewQuestionMapper); controller.Resolve(0); mockViewQuestionMapper.AssertWasCalled(m => m.GetViewQuestion(stubQuestion)); }
public void ResolvePost_GetsQuestionWithViewQuestionMapper() { var mockViewQuestionMapper = MockRepository.GenerateMock <ViewQuestionMapper>(); var stubViewQuestion = MockRepository.GenerateStub <ViewQuestion>(); var stubCorrectionProcess = MockRepository.GenerateStub <CorrectionProcess>(); stubCorrectionProcess.Stub(s => s.CheckAnswer(Arg <Question> .Is.Anything)).Return( MockRepository.GenerateStub <CorrectionResult>()); var controller = new ExamsController(null, stubCorrectionProcess, mockViewQuestionMapper); controller.Resolve(stubViewQuestion); mockViewQuestionMapper.AssertWasCalled(m => m.GetQuestion(stubViewQuestion)); }
public void ResolvePost_WhenThereAreNoErrors_ReturnsRedirectOnSuccess() { var stubCorrectionProcess = MockRepository.GenerateStub <CorrectionProcess>(); var stubCorrectionResult = MockRepository.GenerateStub <CorrectionResult>(); stubCorrectionProcess.Stub(s => s.CheckAnswer(Arg <Question> .Is.Anything)).Return(stubCorrectionResult); var stubViewQuestionMapper = MockRepository.GenerateStub <ViewQuestionMapper>(); var controller = new ExamsController(null, stubCorrectionProcess, stubViewQuestionMapper); ActionResult result = controller.Resolve(null); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); var redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Result", redirectResult.RouteValues["action"]); }
public void ResolvePost_WhenSourceCodeCannotBeExecuted_ShowsTheErrorList() { var mockCorrectionProcess = MockRepository.GenerateStub <CorrectionProcess>(); mockCorrectionProcess.Stub(s => s.CheckAnswer(Arg <Question> .Is.Anything)).Return(new CorrectionResult { Errors = new List <string> { "Error1", "Error2" } }); var stubViewQuestionMapper = MockRepository.GenerateStub <ViewQuestionMapper>(); var controller = new ExamsController(null, mockCorrectionProcess, stubViewQuestionMapper); controller.Resolve(null); Assert.AreEqual("Error1", controller.ModelState[""].Errors[0].ErrorMessage); Assert.AreEqual("Error2", controller.ModelState[""].Errors[1].ErrorMessage); }
public void Resolve_ReturnsQuestionView() { var stubQuestionsRepository = MockRepository.GenerateStub<QuestionsRepository>(); var stubViewQuestionMapper = MockRepository.GenerateMock<ViewQuestionMapper>(); var mockViewQuestion = MockRepository.GenerateMock<ViewQuestion>(); stubViewQuestionMapper.Stub(s => s.GetViewQuestion(Arg<Question>.Is.Anything)).Return(mockViewQuestion); var controller = new ExamsController(stubQuestionsRepository, null, stubViewQuestionMapper); var result = controller.Resolve(0) as ViewResult; Assert.AreEqual(mockViewQuestion, result.ViewData.Model); }
public void Resolve_GetsQuestionById() { var mockQuestionsRepository = MockRepository.GenerateStub<QuestionsRepository>(); var stubViewQuestionMapper = MockRepository.GenerateStub<ViewQuestionMapper>(); var controller = new ExamsController(mockQuestionsRepository, null, stubViewQuestionMapper); controller.Resolve(1); mockQuestionsRepository.AssertWasCalled(m => m.GetById(1)); }
public void Resolve_GetsAViewModelObject() { var mockViewQuestionMapper = MockRepository.GenerateMock<ViewQuestionMapper>(); var stubQuestionsRepository = MockRepository.GenerateStub<QuestionsRepository>(); var stubQuestion = MockRepository.GenerateStub<Question>(); stubQuestionsRepository.Stub(s => s.GetById(Arg<int>.Is.Anything)).Return(stubQuestion); var controller = new ExamsController(stubQuestionsRepository, null, mockViewQuestionMapper); controller.Resolve(0); mockViewQuestionMapper.AssertWasCalled(m=>m.GetViewQuestion(stubQuestion)); }
public void ResolvePost_WhenThereAreNoErrors_ReturnsRedirectOnSuccess() { var stubCorrectionProcess = MockRepository.GenerateStub<CorrectionProcess>(); var stubCorrectionResult = MockRepository.GenerateStub<CorrectionResult>(); stubCorrectionProcess.Stub(s => s.CheckAnswer(Arg<Question>.Is.Anything)).Return(stubCorrectionResult); var stubViewQuestionMapper = MockRepository.GenerateStub<ViewQuestionMapper>(); var controller = new ExamsController(null, stubCorrectionProcess, stubViewQuestionMapper); ActionResult result = controller.Resolve(null); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); var redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Result", redirectResult.RouteValues["action"]); }
public void ResolvePost_WhenSourceCodeCannotBeExecuted_ShowsTheErrorList() { var mockCorrectionProcess = MockRepository.GenerateStub<CorrectionProcess>(); mockCorrectionProcess.Stub(s => s.CheckAnswer(Arg<Question>.Is.Anything)).Return(new CorrectionResult { Errors = new List <string> { "Error1", "Error2" } }); var stubViewQuestionMapper = MockRepository.GenerateStub<ViewQuestionMapper>(); var controller = new ExamsController(null, mockCorrectionProcess, stubViewQuestionMapper); controller.Resolve(null); Assert.AreEqual("Error1", controller.ModelState[""].Errors[0].ErrorMessage); Assert.AreEqual("Error2", controller.ModelState[""].Errors[1].ErrorMessage); }
public void ResolvePost_GetsQuestionWithViewQuestionMapper() { var mockViewQuestionMapper = MockRepository.GenerateMock<ViewQuestionMapper>(); var stubViewQuestion = MockRepository.GenerateStub<ViewQuestion>(); var stubCorrectionProcess = MockRepository.GenerateStub<CorrectionProcess>(); stubCorrectionProcess.Stub(s => s.CheckAnswer(Arg<Question>.Is.Anything)).Return( MockRepository.GenerateStub<CorrectionResult>()); var controller = new ExamsController(null, stubCorrectionProcess, mockViewQuestionMapper); controller.Resolve(stubViewQuestion); mockViewQuestionMapper.AssertWasCalled(m=>m.GetQuestion(stubViewQuestion)); }