예제 #1
0
        public void EditGet_CanEdit_ValidHoliday()
        {
            // Arrange - create the controller
            HolidayController target = new HolidayController(mock.Object);

            // Act - call the action method
            var result = target.Edit(2) as ViewResult;

            // Assert - check the result
            Assert.IsInstanceOf(typeof(ViewResult), result);
            Assert.AreEqual("", result.ViewName);
            Assert.IsNotNull(result.ViewData.Model);
        }
예제 #2
0
        public void EditGet_CannotEdit_InvalidHoliday()
        {
            // Arrange - create the controller
            HolidayController target = new HolidayController(mock.Object);

            // Act - call the action method
            var     result  = (HttpNotFoundResult)target.Edit(150);
            Holiday Holiday = mock.Object.Holidays.Where(m => m.HolidayID == 1500).FirstOrDefault();

            // Assert - check the result
            Assert.IsInstanceOf(typeof(HttpNotFoundResult), result);
            Assert.IsNull(Holiday);
            Assert.AreEqual(404, result.StatusCode);
        }
예제 #3
0
        public void EditPost_CannotEdit_InvalidHolidayCheckboxFalse()
        {
            // Arrange - create the controller
            Holiday holiday = new Holiday {
                HolidayDate = new DateTime(2014, 01, 01), IsPostponed = true, CountryID = 1, Title = "TEST"
            }; HolidayController target = new HolidayController(mock.Object);

            // Act - call the action method
            target.ModelState.AddModelError("error", "error");
            var result = (ViewResult)target.Edit(holiday);

            // Assert - check the result
            mock.Verify(m => m.SaveHoliday(holiday), Times.Never);
            Assert.IsInstanceOf(typeof(ViewResult), result);
            Assert.IsInstanceOf(typeof(Holiday), result.ViewData.Model);
        }
예제 #4
0
        public void EditPost_CannotEdit_InvalidHolidayCheckboxTrue()
        {
            // Arrange - create the controller
            Holiday holiday          = new Holiday {
            };
            HolidayController target = new HolidayController(mock.Object);

            // Act - call the action method
            target.ModelState.AddModelError("error", "error");
            var    result = target.Edit(holiday, "2014.01.01", 1, true);
            string data   = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(((JsonResult)result).Data, "error")).Target;

            // Assert - check the result
            mock.Verify(m => m.SaveHoliday(holiday, new DateTime(2014, 04, 04), 1, true), Times.Never);
            Assert.IsInstanceOf(typeof(JsonResult), result);
            Assert.AreEqual("", data);
        }
예제 #5
0
        public void EditPost_CanEdit_ValidHolidayTrue()
        {
            // Arrange - create the controller
            HolidayController target  = new HolidayController(mock.Object);
            Holiday           holiday = new Holiday {
                HolidayID = 1, CountryID = 1, HolidayComment = "Test Comment", HolidayDate = new DateTime(2014, 05, 05), Title = "New Year", IsPostponed = true
            };


            // Act - call the action method
            var result = (ViewResult)target.Edit(holiday);

            // Assert - check the result
            Assert.IsInstanceOf(typeof(ViewResult), result);
            Assert.IsInstanceOf(typeof(List <Holiday>), result.ViewData.Model);
            mock.Verify(m => m.SaveHoliday(holiday), Times.Once);
        }
예제 #6
0
        public void EditPost_ValidModelConcurrency_ErrorReturned()
        {
            //Arrange
            HolidayController controller = new HolidayController(mock.Object);

            mock.Setup(m => m.SaveHoliday(It.IsAny <Holiday>(), new DateTime(2014, 01, 01), 1, false)).Throws(new DbUpdateConcurrencyException());
            string modelError = "The record you attempted to edit "
                                + "was modified by another user after you got the original value. The "
                                + "edit operation was canceled.";

            //Act
            JsonResult result = (JsonResult)controller.Edit(mock.Object.Holidays.FirstOrDefault(), "2014.01.01", 1, false);
            string     data   = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(result.Data, "error")).Target;

            //Assert
            mock.Verify(d => d.SaveHoliday(It.IsAny <Holiday>(), new DateTime(2014, 01, 01), 1, false), Times.Once());
            Assert.AreEqual(typeof(JsonResult), result.GetType());
            Assert.AreEqual(modelError, data);
        }
예제 #7
0
        public void EditPost_CanEdit_ValidHolidayTrue()
        {
            // Arrange - create the controller
            HolidayController target  = new HolidayController(mock.Object);
            Holiday           holiday = new Holiday {
                HolidayID = 1, CountryID = 1, HolidayComment = "Test Comment", HolidayDate = new DateTime(2014, 01, 01), Title = "New Year"
            };


            // Act - call the action method
            var result = (RedirectToRouteResult)target.Edit(holiday, "2014.05.05", 1, true);

            // Assert - check the result
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
            Assert.IsFalse(result.Permanent);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("ABMView", result.RouteValues["action"]);
            mock.Verify(m => m.SaveHoliday(holiday, new DateTime(2014, 05, 05), 1, true), Times.Once);
        }