コード例 #1
0
        public void PollPassedToPollResultView()
        {
            // Arrange
            var fakeDB = new FakePollContext();
            fakeDB.Polls = new FakePollSet();
            fakeDB.Questions = new FakeDbSet<Question>();
            fakeDB.Answers = new FakeDbSet<Answer>();
            fakeDB.Responses = new FakeResponseSet();
            fakeDB.Selections = new FakeDbSet<Selection>();

            var poll1 = new Poll { ID = 1, Title = "Hello" };
            fakeDB.Polls.Add(poll1);
            var answer1 = new Answer { ID = 1, Text = "Answer1", QuestionID = 1 };
            fakeDB.Answers.Add(answer1);
            var question1 = new Question { ID = 1, Poll = poll1, Text = "Question1", Answers = new List<Answer> { answer1 } };
            fakeDB.Questions.Add(question1);
            var selection1 = new Selection { ID = 1, Answer = answer1, AnswerID = 1 };
            fakeDB.Selections.Add(selection1);
            var response1 = new Response { ID = 1, Poll = poll1, Selections = new List<Selection> { selection1 } };
            fakeDB.Responses.Add(response1);

            PollsController controller = new PollsController(fakeDB);

            // Act
            ViewResult result = controller.Results(1) as ViewResult;
            PollResultsViewModel viewmodel = result.ViewData.Model as PollResultsViewModel;

            // Assert
            Assert.AreEqual(viewmodel.Poll.Title, "Hello");
        }
コード例 #2
0
        public void PollPassedToDetailsView()
        {
            // Arrange
            var fakeDB = new FakePollContext();
            fakeDB.Polls = new FakePollSet();

            var poll = new Poll { ID = 1, Title = "Hello" };
            fakeDB.Polls.Add(poll);
            var poll2 = new Poll { ID = 2, Title = "world" };
            fakeDB.Polls.Add(poll2);

            PollsController controller = new PollsController(fakeDB);

            // Act
            ViewResult result = controller.Details(1) as ViewResult;
            DetailsPollViewModel resultPoll = result.ViewData.Model as DetailsPollViewModel;

            // Assert
            Assert.AreEqual(resultPoll.Poll.Title, "Hello");

            // Act
            ViewResult result2 = controller.Details(2) as ViewResult;
            DetailsPollViewModel resultPoll2 = result2.ViewData.Model as DetailsPollViewModel;

            // Assert
            Assert.AreEqual(resultPoll2.Poll.Title, "world");
        }
コード例 #3
0
        public void PollPassedToQuestionCreateView()
        {
            // Arrange
            var fakeDB = new FakePollContext();
            fakeDB.Polls = new FakePollSet();
            fakeDB.Questions = new FakeDbSet<Question>();

            var poll = new Poll { ID = 1, Title = "Hello" };
            fakeDB.Polls.Add(poll);
            var poll2 = new Poll { ID = 2, Title = "world" };
            fakeDB.Polls.Add(poll2);

            QuestionsController controller = new QuestionsController(fakeDB);

            // Act
            ViewResult result = controller.Create("1") as ViewResult;
            CreateQuestionViewModel generatedViewModel = result.ViewData.Model as CreateQuestionViewModel;

            // Assert
            Assert.AreEqual(generatedViewModel.PollTitle, "Hello");
        }
コード例 #4
0
        public void ResponseCreated()
        {
            // Arrange
            // Arrange
            var fakeDB = new FakePollContext();
            fakeDB.Polls = new FakePollSet();
            fakeDB.Questions = new FakeDbSet<Question>();
            fakeDB.Answers = new FakeDbSet<Answer>();
            fakeDB.Responses = new FakeResponseSet();
            fakeDB.Selections = new FakeDbSet<Selection>();

            var poll1 = new Poll { ID = 1, Title = "Hello" };
            fakeDB.Polls.Add(poll1);
            var answer1 = new Answer { ID = 1, Text = "Answer1", QuestionID = 1 };
            fakeDB.Answers.Add(answer1);
            var question1 = new Question { ID = 1, Poll = poll1, Text = "Question1", Answers = new List<Answer> { answer1 } };
            fakeDB.Questions.Add(question1);
            var selection1 = new Selection { ID = 1, Answer = answer1, AnswerID = 1 };
            fakeDB.Selections.Add(selection1);
            var response1 = new Response { ID = 1, Poll = poll1, Selections = new List<Selection> { selection1 } };
            fakeDB.Responses.Add(response1);

            ResponsesController controller = new ResponsesController(fakeDB);

            CreateResponseViewModel viewmodel = new CreateResponseViewModel
            {
                Poll = poll1,
                Selections = new List<int> { 1 }
            };
            // Act
            ViewResult result = controller.Create(viewmodel) as ViewResult;

            // Assert
            //
            Assert.AreEqual(fakeDB.Responses.Find(1).Selections.First().AnswerID, 1);
        }
コード例 #5
0
 public DetailsPollViewModel(Poll poll)
 {
     Poll = poll;
     Questions = poll.Questions;
 }
コード例 #6
0
 public CreateResponseViewModel(Poll poll)
 {
     Poll = poll;
 }
コード例 #7
0
 public CreateQuestionViewModel(Poll poll)
 {
     PollID = poll.ID;
     PollTitle = poll.Title;
 }
コード例 #8
0
 public PollResultsViewModel(Poll poll)
 {
     Poll = poll;
     numOfResponses = Poll.Responses.Count();
     AnswerCounts = new Dictionary<int, int>();
     foreach (Question question in Poll.Questions)
     {
         foreach (Answer answer in question.Answers)
         {
             int count = 0;
             foreach (Response response in Poll.Responses)
             {
                 if (response.Selections != null)
                 {
                     foreach (Selection selection in response.Selections)
                     {
                         if (selection.AnswerID == answer.ID)
                         {
                             count++;
                         }
                     }
                 }
             }
             AnswerCounts.Add(answer.ID, count);
         }
     }
 }
コード例 #9
0
 public EditPollViewModel(Poll poll)
 {
     Poll = poll;
     Questions = poll.Questions;
 }
コード例 #10
0
ファイル: Response.cs プロジェクト: jcfocken/PollProject
 public Response(Poll poll)
 {
     Poll = poll;
 }
コード例 #11
0
ファイル: Response.cs プロジェクト: jcfocken/PollProject
 public Response(Poll poll)
 {
     Poll = poll;
 }
コード例 #12
0
        public void PollsPassedToIndexView()
        {
            // Arrange
            var fakeDB = new FakePollContext();
            fakeDB.Polls = new FakePollSet();

            var poll = new Poll { ID = 1, Title = "Hello" };
            fakeDB.Polls.Add(poll);
            var poll2 = new Poll { ID = 2, Title = "world" };
            fakeDB.Polls.Add(poll2);

            PollsController controller = new PollsController(fakeDB);

            // Act
            ViewResult result = controller.Index() as ViewResult;
            IEnumerable<Poll> polls = result.ViewData.Model as IEnumerable<Poll>;

            // Assert
            Assert.AreEqual(polls.ElementAt(0).Title , "Hello");
            Assert.AreEqual(polls.ElementAt(1).Title, "world");
        }