コード例 #1
0
        public void Details_Controller_Test_On_EditModel_With_Invalid_Id()
        {
            //Arrange
            Guid     id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string   feedBackMessage = "TestT";
            int      noOfPages       = 10;
            int      rating          = 10;
            DateTime checkIn         = DateTime.Now;
            DateTime checkOut        = DateTime.Now.AddDays(1);

            Detail expectaDetail = new Detail(checkIn, checkOut, feedBackMessage, noOfPages, rating);

            expectaDetail.Id = id;

            Guid faultId = new Guid("1e4966f0-68f7-4f24-9f4f-53d528787be5");

            var repo = Substitute.For <IRepository>();
            var sut  = new DetailsController(repo);

            repo.Update(expectaDetail);

            //Act
            var actual = sut.Edit(faultId, expectaDetail).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(NotFoundResult));
        }
コード例 #2
0
        public void Details_Controller_Test_On_Edit_With_Existent_Id()
        {
            //Arrange
            Guid     id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string   feedBackMessage = "TestT";
            int      noOfPages       = 10;
            int      rating          = 10;
            DateTime checkIn         = DateTime.Now;
            DateTime checkOut        = DateTime.Now.AddDays(1);

            Detail expectaDetail = new Detail(checkIn, checkOut, feedBackMessage, noOfPages, rating);

            expectaDetail.Id = id;

            var repo = Substitute.For <IRepository>();
            var sut  = new DetailsController(repo);

            repo.GetById <Detail>(id).Returns(expectaDetail);
            //Act
            var actual = sut.Edit(id).Result as ViewResult;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
            var viewResult = actual;

            Assert.AreEqual(expectaDetail, viewResult.Model);
        }
コード例 #3
0
        public void Details_Controller_Test_On_EditModel_With_Invalid_Model()
        {
            //Arrange
            Guid     id = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string   feedBackMessage = "TestT";
            int      noOfPages       = 10;
            int      rating          = 10;
            DateTime checkIn         = DateTime.Now;
            DateTime checkOut        = DateTime.Now.AddDays(1);

            Detail expectaDetail = new Detail(checkIn, checkOut, feedBackMessage, noOfPages, rating);

            expectaDetail.Id = id;

            DetailModel expectedModel = new DetailModel();

            expectedModel.FeedbackMessage = " ";

            var repo = Substitute.For <IRepository>();
            var sut  = new DetailsController(repo);

            repo.Update(expectaDetail);

            //Act
            sut.ModelState.AddModelError("FirstName", "Firstname Required");
            var actual = sut.Edit(id, expectaDetail).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
        }
コード例 #4
0
        public void Details_Controller_Test_On_Edit_With_NonExistent_Id()
        {
            //Arrange
            Guid id   = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            var  repo = Substitute.For <IRepository>();
            var  sut  = new DetailsController(repo);

            repo.GetById <Detail>(id);

            //Act
            var actual = sut.Edit(id).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(NotFoundResult));
        }