Пример #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 DeleteGet_InvalidHoliday()
        {
            // Arrange - create the controller
            HolidayController target = new HolidayController(mock.Object);

            // Act - call the action method
            var     result  = (HttpNotFoundResult)target.Delete(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);
        }
        public void PingGet_ReturnsSuccess()
        {
            //Arrange
            var controller = new HolidayController(_service.Object, _mockLogger.Object, _confOptions);

            //Act
            var result = controller.Get();

            //Assert
            var contentResult = result.Should().BeOfType <ContentResult>().Subject;

            contentResult.StatusCode.Should().Be((int)System.Net.HttpStatusCode.OK);
            contentResult.Content.Should().Be("PingGet response from RPS Api Holiday");
        }
Пример #4
0
        public void DeleteGet_ValidCountryWithoutAssociatedDate_CannotDelete()
        {
            // Arrange - create the controller
            HolidayController target = new HolidayController(mock.Object);

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

            // Assert - check the result
            Assert.AreEqual("", result.ViewName);
            Assert.IsInstanceOf(typeof(Holiday), result.ViewData.Model);
            Assert.IsInstanceOf(typeof(ViewResult), result);
            Assert.IsNotNull(result.ViewData.Model);
        }
Пример #5
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);
        }
Пример #6
0
        private void setReturnDate()
        {
            _returnDate = DateTime.Today.AddDays(SettingsModel.MaxDaysCount);

            #region Check the calculated date is a holiday and set the date to next
            bool isAHoliday = HolidayController.IsAHoliday(ReturnDate);
            while (isAHoliday)
            {
                ReturnDate.AddDays(1);
                isAHoliday = HolidayController.IsAHoliday(ReturnDate);
            }
            #endregion

            returnDatePicker.Value = ReturnDate;
        }
Пример #7
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);
        }
Пример #8
0
        public void DeletePost_CanDelete_ValidHoliday()
        {
            // Arrange - create the controller
            HolidayController target = new HolidayController(mock.Object);

            // Act - call the action method
            RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(1);

            // Assert - check the result
            mock.Verify(m => m.DeleteHoliday(1), Times.Once);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("ABMView", result.RouteValues["action"]);
            Assert.IsNotNull(result.RouteValues["tab"]);
            Assert.IsFalse(result.Permanent);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
        }
Пример #9
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);
        }
Пример #10
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);
        }
        public async Task PostAsync_Succeeds()
        {
            //Arrange
            var request  = HolidayControllerTestsDataGenerator.GetValidRequestData();
            var response = HolidayControllerTestsDataGenerator.GetValidResponseData();

            _service.Setup(m => m.PerformHolidayCalculationAsync(request, _confOptions)).ReturnsAsync(response);
            var controller = new HolidayController(_service.Object, _mockLogger.Object, _confOptions);

            //Act
            var result = await controller.PostAsync(request);

            //Assert
            var okObjectRequest = result.Should().BeOfType <OkObjectResult>().Subject;

            okObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.OK);
        }
Пример #12
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);
        }
Пример #13
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"]);
        }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
0
        public void DeletePost_CannotDelete_ValidHoliday()
        {
            // Arrange - create the controller
            HolidayController target = new HolidayController(mock.Object);

            mock.Setup(x => x.DeleteHoliday(It.IsAny <int>()))
            .Callback(() => { throw new System.Data.Entity.Infrastructure.DbUpdateException(); });


            // Act - call the action method
            RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(2);

            // Assert - check the result
            mock.Verify(m => m.DeleteHoliday(2), Times.Once);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("DataBaseDeleteError", result.RouteValues["action"]);
        }
Пример #17
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);
        }
Пример #18
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);
        }
        public void PostHoliday()
        {
            // Arrange
            HolidayController controller = new HolidayController();

            Espl.Linkup.Domain.Leave.Holiday.Holiday HolidayObj = new Espl.Linkup.Domain.Leave.Holiday.Holiday
            {
                Title       = "Christmas",
                WeekDay     = "Sunday",
                HolidayType = "Fixed",
                HolidayDate = new DateTime()
            };
            var actResult = controller.Post(HolidayObj);
            // Act
            var result = actResult as OkNegotiatedContentResult <Espl.Linkup.Domain.Leave.Holiday.Holiday>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Content.ID > 0);
        }
        public void PutHoliday()
        {
            // Arrange
            HolidayController controller = new HolidayController();

            Espl.Linkup.Domain.Leave.Holiday.Holiday HolidayObj = new Espl.Linkup.Domain.Leave.Holiday.Holiday
            {
                ID          = 1,
                Title       = "Put request sucessfull",
                WeekDay     = "Sunday",
                HolidayType = "Fixed",
                HolidayDate = new DateTime()
            };
            var actResult = controller.Put(1, HolidayObj);
            // Act
            var result = actResult as OkNegotiatedContentResult <Espl.Linkup.Domain.Leave.Holiday.Holiday>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Content.Title.Equals("Put request sucessfull"));
        }
        public async Task PostAsync_FailsWithBadRequest_WhenThereIsAValidationError(HolidayCalculationRequestModel request, string expectedErrorMessage)
        {
            //Arrange
            var controller = new HolidayController(_service.Object, _mockLogger.Object, _confOptions);

            //Act
            var result = await controller.PostAsync(request);

            //Assert
            var badRequestObjectRequest = result.Should().BeOfType <BadRequestObjectResult>().Subject;

            badRequestObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.BadRequest);

            _mockLogger.Verify(x => x.Log(
                                   LogLevel.Error,
                                   It.IsAny <EventId>(),
                                   It.Is <object>(v => v.ToString().Contains(expectedErrorMessage)),
                                   null,
                                   It.IsAny <Func <object, Exception, string> >()
                                   ));
        }
        public async Task PostAsync_Succeeds_WithNoHTNPData()
        {
            //Arrange
            var request = new HolidayCalculationRequestModel
            {
                Hpa = new HolidayPayAccruedCalculationRequestModel
                {
                    InsolvencyDate           = new DateTime(2017, 03, 22),
                    EmpStartDate             = new DateTime(2016, 12, 19),
                    DismissalDate            = new DateTime(2017, 03, 20),
                    ContractedHolEntitlement = 25,
                    HolidayYearStart         = new DateTime(2017, 01, 01),
                    IsTaxable    = true,
                    PayDay       = (int)DayOfWeek.Saturday,
                    ShiftPattern = new List <string> {
                        "1", "2", "3", "4", "5"
                    },
                    WeeklyWage      = 243.25m,
                    DaysCFwd        = 5.5m,
                    DaysTaken       = 3.5m,
                    IpConfirmedDays = 25
                },
                Htnp = new List <HolidayTakenNotPaidCalculationRequestModel>()
            };
            var response = new HolidayCalculationResponseDTO();

            _service.Setup(m => m.PerformHolidayCalculationAsync(request, _confOptions)).ReturnsAsync(response);
            var controller = new HolidayController(_service.Object, _mockLogger.Object, _confOptions);

            //Act
            var result = await controller.PostAsync(request);

            //Assert
            var okObjectRequest = result.Should().BeOfType <OkObjectResult>().Subject;

            okObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.OK);
        }
Пример #23
0
 private void HolidayForm_Load(object sender, EventArgs e)
 {
     holidayColourLabel.BackColor = HolidayCalender.HolidayColour;
     holidayCalender.SelectedDays = HolidayController.loadHolidays(displayMonth);
 }
Пример #24
0
 public static HolidayController Fixture()
 {
     HolidayController controller = new HolidayController(new HolidayRepository(), "", new LoginView());
     return controller;
 }
Пример #25
0
 private void HomeForm_Load(object sender, EventArgs e)
 {
     HolidayCalender.HolidayColour = Color.LightCoral;
     holidayCalender.SelectedDays  = HolidayController.loadHolidays(DateTime.Today);
 }
Пример #26
0
        public static HolidayController Fixture()
        {
            HolidayController controller = new HolidayController(new HolidayRepository(), "", new LoginView());

            return(controller);
        }
Пример #27
0
 private void okButton_Click(object sender, EventArgs e)
 {
     HolidayController.addHolidays(displayMonth, holidayCalender.SelectedDays);
 }
Пример #28
0
 public void SetUp()
 {
     mock       = Mock_Repository.CreateMock();
     controller = new HolidayController(mock.Object);
 }