예제 #1
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);
        }
        public void ReturnBadRequestIfNotValidGuidId()
        {
            var repository = new Mock <IRepository>();

            var responsesController = new ResponsesController(repository.Object);
            var result = responsesController.Get(null);

            Assert.IsType <BadRequestObjectResult>(result);
        }
        public void EmptyResponsesReturnNotFound()
        {
            var repository = new Mock <IRepository>();

            var responsesController = new ResponsesController(repository.Object);
            var result = responsesController.Get();

            Assert.IsType <NoContentResult>(result);
        }
        public void NotFoundReturnedWhenResponseNotInDatabase()
        {
            var repository = new Mock <IRepository>();

            repository.Setup(r => r.GetResponse(It.IsAny <string>(), It.IsAny <string>())).Returns((Response)null);

            var responsesController = new ResponsesController(repository.Object);
            var result = responsesController.Get(Guid.NewGuid().ToString());

            Assert.IsType <NotFoundResult>(result);
        }
        public void RepositoryReturnsAResponseWhenValidIdIsGiven()
        {
            var repository = new Mock <IRepository>();

            repository.Setup(r => r.GetResponse(It.IsAny <string>(), It.IsAny <string>())).Returns(new Response());

            var responsesController = new ResponsesController(repository.Object);
            var result = responsesController.Get(Guid.NewGuid().ToString());

            repository.Verify(r => r.GetResponse(It.IsAny <string>(), It.IsAny <string>()));
            Assert.IsType <OkObjectResult>(result);
            Assert.IsType <Response>(((OkObjectResult)result).Value);
        }
        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);
        }