Exemplo n.º 1
0
        public void Edit_IdInvalid_Returns404()
        {
            var mockAnswers = new Mock <DbSet <Answer> >().SetupData();
            var mockDb      = new Mock <IApplicationDBContext>();

            mockDb.SetupGet(d => d.Answers).Returns(mockAnswers.Object);

            var subject = new AnswerController(mockDb.Object, Mock.Of <ISurveyService>(), Mock.Of <IDateTimeService>(), Mock.Of <ISecurity>());

            var result = subject.Edit(3, null).Result;

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
        }
Exemplo n.º 2
0
        public void Edit_DetailsNull_Returns500()
        {
            var mockAnswers = new Mock <DbSet <Answer> >().SetupData(new[] { new Answer()
                                                                             {
                                                                                 Id = 3
                                                                             } });
            var mockDb = new Mock <IApplicationDBContext>();

            mockDb.SetupGet(d => d.Answers).Returns(mockAnswers.Object);

            var subject = new AnswerController(mockDb.Object, Mock.Of <ISurveyService>(), Mock.Of <IDateTimeService>(), Mock.Of <ISecurity>());

            var result = subject.Edit(3, null).Result;

            Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));
            Assert.AreEqual(500, (result as HttpStatusCodeResult).StatusCode);
        }
Exemplo n.º 3
0
        public void Edit_DetailsOK_SavesAndReturnsOK()
        {
            var answer = new Answer()
            {
                Id = 3
            };
            var mockAnswers = new Mock <DbSet <Answer> >().SetupData(new[] { answer });
            var mockDb      = new Mock <IApplicationDBContext>();

            mockDb.SetupGet(d => d.Answers).Returns(mockAnswers.Object);

            var subject = new AnswerController(mockDb.Object, Mock.Of <ISurveyService>(), Mock.Of <IDateTimeService>(), Mock.Of <ISecurity>());

            var result = subject.Edit(3, "details").Result;

            Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));
            Assert.AreEqual(200, (result as HttpStatusCodeResult).StatusCode);
            Assert.AreEqual("details", answer.Details);
            mockDb.Verify(d => d.SaveChangesAsync());
        }