Esempio n. 1
0
        public void CreatePost_CannotCreate_InvalidHolidayChekboxTrue()
        {
            // Arrange - create the controller
            Holiday           holiday = new Holiday();
            HolidayController target  = new HolidayController(mock.Object);

            // Act - call the action method
            target.ModelState.AddModelError("error", "error");
            ViewResult result = target.Create(holiday, "", 1, true) as ViewResult;

            // Assert - check the result
            mock.Verify(m => m.SaveHoliday(It.IsAny <Holiday>(), new DateTime(2014, 01, 01), 1, true), Times.Never);
            Assert.IsInstanceOf(typeof(Holiday), result.ViewData.Model);
            Assert.IsInstanceOf(typeof(ViewResult), result);
        }
Esempio n. 2
0
        public void CreatePost_CanCreate_ValidHolidayCheckboxFalse()
        {
            // Arrange - create the controller
            HolidayController target  = new HolidayController(mock.Object);
            Holiday           Holiday = new Holiday {
                HolidayID = 100, Title = "Test", HolidayDate = new DateTime(2014, 09, 09), IsPostponed = false
            };

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

            // Assert - check the result
            mock.Verify(m => m.SaveHoliday(Holiday), Times.Once);
            Assert.IsInstanceOf(typeof(List <Holiday>), result.ViewData.Model);
            Assert.IsInstanceOf(typeof(ViewResult), result);
        }
Esempio n. 3
0
        public void CreateGet_ReturnView()
        {
            //Arrange
            HolidayController controller = new HolidayController(mock.Object);


            //Act
            var        result      = controller.Create() as ViewResult;
            SelectList countryList = result.ViewBag.CountryList as SelectList;

            //Assert
            Assert.IsInstanceOf(typeof(SelectList), result.ViewBag.CountryList);
            Assert.AreEqual(5, countryList.ToList().Count);
            Assert.AreEqual("Ukraine", countryList.ToArray()[0].Text);
            Assert.AreEqual("Zimbabve", countryList.ToArray()[4].Text);
            Assert.AreEqual("", result.ViewName);
        }
Esempio n. 4
0
        public void CreatePost_CanCreate_ValidHolidayCheckboxFalse()
        {
            // Arrange - create the controller
            HolidayController target  = new HolidayController(mock.Object);
            Holiday           Holiday = new Holiday {
                HolidayID = 1, Title = " Test", HolidayDate = new DateTime(2014, 01, 01)
            };

            // Act - call the action method
            RedirectToRouteResult result = (RedirectToRouteResult)target.Create(Holiday, "01.01.2014", 1, false);

            // Assert - check the result
            mock.Verify(m => m.SaveHoliday(Holiday, new DateTime(2014, 01, 01), 1, false), Times.Once);
            Assert.IsFalse(result.Permanent);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("ABMView", result.RouteValues["action"]);
        }
Esempio n. 5
0
        public void CreatePost_CannotCreate_InvalidHolidayChecboxFalse()
        {
            // Arrange - create the controller
            Holiday Holiday = new Holiday {
                HolidayID = 1, Title = "", HolidayDate = new DateTime(2014, 01, 01), IsPostponed = false
            };
            HolidayController target = new HolidayController(mock.Object);

            // Act - call the action method
            target.ModelState.AddModelError("error", "error");
            ViewResult result = target.Create(Holiday) as ViewResult;

            // Assert - check the result
            mock.Verify(m => m.SaveHoliday(It.IsAny <Holiday>()), Times.Never);
            Assert.IsInstanceOf(typeof(Holiday), result.ViewData.Model);
            Assert.IsInstanceOf(typeof(ViewResult), result);
        }