public void ShouldGetQuestions() { //Arrange var expectedTitle = "My expected questions"; var mockedHttpClientWrapper = new Mock <IHttpClientWrapper>(); var questions = new List <string>() { "Question 1", "Question 2" }; var questionnaire = new Questionnaire { QuestionnaireTitle = expectedTitle, QuestionsText = questions }; var serialisedQuestionnaire = new JavaScriptSerializer().Serialize(questionnaire); mockedHttpClientWrapper.Setup(client => client.Get(It.IsAny <string>())).Returns(serialisedQuestionnaire); var questionnaireController = new QuestionnaireController(mockedHttpClientWrapper.Object); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedTitle)); Assert.That(result.QuestionsText.Count, Is.EqualTo(2)); Assert.That(result.QuestionsText[0], Is.EqualTo(questions[0])); Assert.That(result.QuestionsText[1], Is.EqualTo(questions[1])); }
public void Given_GetQuestionnaireRequest_When_Returns_Then_ResultIsEqualToExpected() { const string expectedTitle = "My expected quesitons"; var questionsText = new List <string> { "Question #1", "Question #2", "Question #3" }; var questionnaireModel = new QuestionnaireModel { Title = expectedTitle, QuestionsText = questionsText }; _service.Setup(x => x.GetQuestionnaires("http://localhost:50014/api/Questions")) .Returns(Task.FromResult(questionnaireModel)).Verifiable(); var questionnaireViewModel = new QuestionnaireViewModel { QuestionnaireTitle = expectedTitle, QuestionsText = questionsText }; _typeMapper.Setup(x => x.Convert <QuestionnaireModel, QuestionnaireViewModel>(questionnaireModel)) .Returns(questionnaireViewModel).Verifiable(); var result = (QuestionnaireViewModel)_sut.Index().Result.Model; Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedTitle)); Assert.True(result.QuestionsText.Count == questionsText.Count); Assert.True(result.QuestionsText.SequenceEqual(questionsText)); _service.VerifyAll(); _typeMapper.VerifyAll(); }
public async void When_ServiceThrowsAnException_Then_ItRaisesIt() { // Setup _service.Setup(x => x.GetQuestionnaireAsync()).Throws(new ServiceException("testEx")); // Act try { await _controller.Index(); } catch (Exception ex) { Assert.AreEqual(typeof(ServiceException), ex.GetType()); Assert.AreEqual("testEx", ex.Message); } }
public async Task ShouldGetQuestions() { //Arrange string expectedTitle = "My expected questions"; string expectedQuestion1Text = "Question 1 Text"; string expectedQuestion2Text = "Question 2 Text"; string expectedQuestion3Text = "Question 3 Text"; string expectedQuestion4Text = "Question 4 Text"; QuestionnaireViewModel expectedQuestions = new QuestionnaireViewModel { QuestionnaireTitle = expectedTitle, Questions = new List <QuestionnaireViewModel.QuestionViewModel> { new QuestionnaireViewModel.QuestionViewModel { Question = expectedQuestion1Text }, new QuestionnaireViewModel.QuestionViewModel { Question = expectedQuestion2Text }, new QuestionnaireViewModel.QuestionViewModel { Question = expectedQuestion3Text }, new QuestionnaireViewModel.QuestionViewModel { Question = expectedQuestion4Text } } }; IQuestionService questionService = Mock.Of <IQuestionService>(); Mock.Get(questionService).Setup(s => s.Get()).Returns(Task.FromResult(expectedQuestions)); QuestionnaireController questionnaireController = new QuestionnaireController(questionService); //Act ActionResult actionResult = await questionnaireController.Index(); //Assert Assert.IsInstanceOf <ViewResult>(actionResult); Assert.IsNotNull((actionResult as ViewResult).ViewData.Model); Assert.IsInstanceOf <QuestionnaireViewModel>((actionResult as ViewResult).ViewData.Model); QuestionnaireViewModel model = (actionResult as ViewResult).ViewData.Model as QuestionnaireViewModel; Assert.That(model.QuestionnaireTitle, Is.EqualTo(expectedTitle)); Assert.That(model.Questions.Count, Is.EqualTo(expectedQuestions.Questions.Count)); Assert.That(model.Questions[0].Question, Is.EqualTo(expectedQuestion1Text)); Assert.That(model.Questions[1].Question, Is.EqualTo(expectedQuestion2Text)); Assert.That(model.Questions[2].Question, Is.EqualTo(expectedQuestion3Text)); Assert.That(model.Questions[3].Question, Is.EqualTo(expectedQuestion4Text)); }
public void ShouldGetQuestions() { //Arrange var expectedTitle = "My expected quesitons"; //Act var result = (QuestionnaireViewModel)_questionnaireController.Index().ViewData.Model; //Assert Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedTitle)); }
public void ViewModelGetsQuestionnaireTitleFromExternalService() { // Arrange var questionnaireController = new QuestionnaireController(StubFactory.GetHttpClientContainer()); // Act var result = (QuestionnaireViewModel)questionnaireController.Index().Result.ViewData.Model; // Assert Assert.That(result.QuestionnaireTitle, Is.EqualTo("Test questionnaire title")); }
public void ShouldGetQuestions() { //Arrange var questionnaireController = new QuestionnaireController(); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert Assert.IsTrue(result.QuestionsText.Count > 0); }
public void Index() { // Arrange QuestionnaireController controller = new QuestionnaireController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public void ActionReturnTypeShouldBeQuestionnaireViewModel() { //Arrange var questionnaireController = new QuestionnaireController(); //Act var typeOfIndexActionName = questionnaireController.Index().ViewData.Model.GetType().Name; //Assert -Check if return type is correct typeOfIndexActionName.Should().Be("QuestionnaireViewModel"); }
public void ShouldGetQuestions() { //Arrange var expectedTitle = "Geography Questions"; var questionnaireController = new QuestionnaireController(new QuestionServiceClient(new HttpClientHandler())); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().Result.ViewData.Model; //Assert Assert.AreEqual <string>(expectedTitle, result.QuestionnaireTitle); }
public void ShouldGetQuestionsTitle() { //Arrange var expectedTitle = "Geography Questions"; var questionnaireController = new QuestionnaireController(); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedTitle)); }
public void ShouldGetIndexView() { //Arrange _questionnaireServiceMock.Setup(x => x.GetQuestions()).ReturnsAsync(new QuestionnaireViewModel()); var questionnaireController = new QuestionnaireController(_questionnaireServiceMock.Object); //Act var result = questionnaireController.Index().Result; //Assert Assert.That(result.ViewName, Is.EqualTo("Index")); }
public void ViewModelGetsQuestionsFromExternalService() { // Arrange var questionnaireController = new QuestionnaireController(StubFactory.GetHttpClientContainer()); // Act var result = (QuestionnaireViewModel)questionnaireController.Index().Result.ViewData.Model; // Assert Assert.That(result.QuestionsText.Count, Is.EqualTo(2)); Assert.That(result.QuestionsText[0], Is.EqualTo("Question 1")); Assert.That(result.QuestionsText[1], Is.EqualTo("Question 2")); }
public void ShouldGetQuestions() { //Arrange var expectedTitle = "My expected questions"; var questionnaireController = new QuestionnaireController(); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().AsyncState; //Assert Assert.IsNotNull(result); Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedTitle)); }
public void ErrorResponseInApiThrows503() { // Arrange var httpResponseMessage = StubFactory.GetStatusCodeResponseMessage(HttpStatusCode.NotFound); var questionnaireController = new QuestionnaireController(StubFactory.GetHttpClientContainer(httpResponseMessage)); // Act var result = (ErrorViewModel)questionnaireController.Index().Result.ViewData.Model; // Assert Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.ServiceUnavailable)); Assert.That(result.Message, Is.EqualTo("An underlying service is now unavailable. Please try again later.")); }
public void ShouldGetQuestions() { //Arrange var expectedTitle = _titleHeader; var questionnaireController = new QuestionnaireController(); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert result.Should().NotBeNull(); result.QuestionnaireTitle.ShouldBeEquivalentTo(expectedTitle); }
public void QuestionShouldHaveCountGreaterThan0() { var questionnaireController = new QuestionnaireController(); AddKey(); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert Assert.That(result.QuestionsText.Count, Is.GreaterThan(0)); }
public void ShouldGetQuestions() { //Arrange var expectedTitle = "Geography Questions"; var mock = new Mock <IConfiguration>(); mock.Setup(x => x.Url).Returns("http://localhost:50014/api/Questions"); var questionnaireController = new QuestionnaireController(mock.Object); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedTitle)); }
public void GetQuestionnairQuestions() { //Arrange var questionnaireController = new QuestionnaireController(); //Act var result = questionnaireController.Index().Result; var questionnaire = (QuestionnaireViewModel)result.ViewData.Model; //Assert Assert.That(questionnaire.QuestionsText[0], Is.EqualTo("What is the capital of Cuba?")); Assert.That(questionnaire.QuestionsText[1], Is.EqualTo("What is the capital of France?")); Assert.That(questionnaire.QuestionsText[2], Is.EqualTo("What is the capital of Poland?")); Assert.That(questionnaire.QuestionsText[3], Is.EqualTo("What is the capital of Germany?")); }
public void IndexActionShouldHaveFourQuestionsAndOneTitle() { //Arrange var questionnaireController = new QuestionnaireController(); //Act var returnedModel = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert -Check if return type is correct returnedModel.Questions.Should().NotBeNullOrEmpty(); returnedModel.Questions.Count.ShouldBeEquivalentTo(4); returnedModel.QuestionnaireTitle.Should().NotBeNull(); returnedModel.QuestionnaireTitle.Should().NotBeEmpty(); //this would fail if it was a list so title is only one entity returnedModel.QuestionnaireTitle.Should().BeOfType <string>(); }
public void ShouldGetQuestions() { //Arrange var expectedTitle = "Geography Questions"; var questionnaireController = new QuestionnaireController(); //Act var request = questionnaireController.Index(); //Assert Assert.IsNotNull(request); var result = request as ViewResult; var model = (QuestionnaireViewModel)result.ViewData.Model; Assert.That(model.QuestionnaireTitle, Is.EqualTo(expectedTitle)); }
public void ShouldGetRightOfQuestion() { //Arrange var expectedTitle = "My expected quesitons"; var expectedQuestions = new List <string> { "Question 1?" }; var fakeQuestionnaireManager = new FakeQuestionnaireManager(expectedTitle, expectedQuestions); var questionnaireController = new QuestionnaireController(fakeQuestionnaireManager); //Act var result = (QuestionnaireViewModel)questionnaireController.Index().ViewData.Model; //Assert Assert.That(result.QuestionsText, Is.EqualTo(expectedQuestions)); }
public void ShouldGetExpectedQuestionnaire() { //Arrange var questionnaireController = new QuestionnaireController(); //Act var viewResult = questionnaireController.Index() as ViewResult; var viewModel = (QuestionnaireViewModel)viewResult.Model; //Assert Assert.That(viewModel.QuestionnaireTitle, Is.EqualTo("Geography Questions")); Assert.That(viewModel.QuestionsText[0], Is.EqualTo("What is the capital of Cuba?")); Assert.That(viewModel.QuestionsText[1], Is.EqualTo("What is the capital of France?")); Assert.That(viewModel.QuestionsText[2], Is.EqualTo("What is the capital of Poland?")); Assert.That(viewModel.QuestionsText[3], Is.EqualTo("What is the capital of Germany?")); }
public void Index_WhenCalled_ReturnsViewWithQuestionnaireViewModel() { //Arrange SetupQuestionnaireController(); var expectedQuestionnaire = new QuestionnaireViewModel() { QuestionnaireTitle = "My expected quesitons" }; _httpClientWrapperMock.Setup(m => m.GetAsync <QuestionnaireViewModel>("Questions/Get")).Returns(expectedQuestionnaire); //Act var result = (QuestionnaireViewModel)_questionnaireController.Index().Result.ViewData.Model; //Assert Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedQuestionnaire.QuestionnaireTitle)); }
public async void ShouldGetQuestionnaire() { //Arrange var expectedTitle = "My expected quesitons"; Mock <IQuestionnaireService> mockQuestionnaireService = new Mock <IQuestionnaireService>(); var questionnaire = new QuestionnaireViewModel { QuestionnaireTitle = expectedTitle }; mockQuestionnaireService.Setup(t => t.GetAsync()).ReturnsAsync(questionnaire); var questionnaireController = new QuestionnaireController(mockQuestionnaireService.Object); //Act var viewResult = await questionnaireController.Index(); var result = (QuestionnaireViewModel)viewResult.ViewData.Model; //Assert Assert.That(result.QuestionnaireTitle, Is.EqualTo(expectedTitle)); }