コード例 #1
0
        public void SurveyController_SubmitAction_ReturnSubmitView()
        {
            //string conn = @"Data Source=.\SQLEXPRESS;Initial Catalog=npgeek;User ID=te_student;Password=sqlserver1";
            //Arrange
            //ParkListSqlDAL parkDal = new ParkListSqlDAL(conn);
            SurveyController controller = new SurveyController(null);

            //Act
            ViewResult result = controller.Submit() as ViewResult;

            //Assert

            Assert.AreEqual("Submit", result.ViewName);
        }
        public void AndTheSurveyIsValidThenConsoleIsCalledWithTheDetails()
        {
            // Arrange
            var repo = new MockRepository(MockBehavior.Default);
            var mockConsoleAdapter = repo.Create <IConsoleAdapter>();
            var surveyController   = new SurveyController(mockConsoleAdapter.Object);

            var survey = SurveBuilderWithValidDefaults()
                         .Build();

            // Act
            surveyController.Submit(survey);

            // Assert
            mockConsoleAdapter.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Exactly(7));
            mockConsoleAdapter.Verify(x => x.WriteLine("Survey Received:"), Times.Once);
            mockConsoleAdapter.Verify(x => x.WriteLine("  Title: " + survey.Title.ToString()), Times.Once);
            mockConsoleAdapter.Verify(x => x.WriteLine("  Name: " + survey.Name), Times.Once);
            mockConsoleAdapter.Verify(x => x.WriteLine("  Date Of Birth: " + survey.DateOfBirth), Times.Once);
            mockConsoleAdapter.Verify(x => x.WriteLine("  Location: " + survey.Location), Times.Once);
            mockConsoleAdapter.Verify(x => x.WriteLine("  Now: " + survey.Now), Times.Once);
            mockConsoleAdapter.Verify(x => x.WriteLine("  Feedback: " + survey.Feedback), Times.Once);
        }