public void ScheduleEngineersShiftRange_Success()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.AddProfile <BAUMappingProfile>();
            });
            var date = DateTime.Now.NextDayOfWeek(DayOfWeek.Thursday);
            Mock <IShiftService> mockService = new Mock <IShiftService>(MockBehavior.Strict);

            mockService.Setup(s => s.ScheduleEngineerShiftRange(It.IsAny <ShiftRequestModel>()))
            .Returns(
                new List <EngineerShiftModel> {
                new EngineerShiftModel {
                    Date = date, Duration = 4, Engineer = new EngineerModel {
                        Id = 1, Name = "Engineer 1"
                    }
                },
                new EngineerShiftModel {
                    Date = date.NextDayOfWeek(DayOfWeek.Tuesday), Duration = 4, Engineer = new EngineerModel {
                        Id = 2, Name = "Engineer 2"
                    }
                },
            });

            ShiftController controller = new ShiftController(mockService.Object);
            var             model      = new ShiftRequestModel
            {
                Count     = 2,
                StartDate = date,
                EndDate   = date.NextDayOfWeek(DayOfWeek.Tuesday)
            };
            var result = controller.ScheduleEngineersShiftRange(model);

            Assert.NotNull(result);
            Assert.True(result.GetType() == typeof(OkObjectResult));
            var expected = new List <EngineerModel> {
                new EngineerModel {
                    Id = 1, Name = "Engineer 1"
                },
                new EngineerModel {
                    Id = 2, Name = "Engineer 2"
                },
            };

            Assert.Equal(expected, (result as OkObjectResult).Value);
            mockService.Verify(m => m.ScheduleEngineerShiftRange(model), Times.Once());
        }
        public void ScheduleEngineersShiftRange_Exception()
        {
            Mock <IShiftService> mockService = new Mock <IShiftService>(MockBehavior.Strict);

            mockService.Setup(s => s.ScheduleEngineerShiftRange(It.IsAny <ShiftRequestModel>())).Throws(new InvalidOperationException("Testing controller exception handler"));

            ShiftController controller = new ShiftController(mockService.Object);
            var             date       = DateTime.Now.NextDayOfWeek(DayOfWeek.Thursday);
            var             model      = new ShiftRequestModel
            {
                Count     = 2,
                StartDate = date,
                EndDate   = date.NextDayOfWeek(DayOfWeek.Tuesday)
            };
            var result = controller.ScheduleEngineersShiftRange(model);

            Assert.NotNull(result);
            Assert.True(result.GetType() == typeof(BadRequestObjectResult));
            Assert.Equal("Testing controller exception handler", (result as BadRequestObjectResult).Value);
            mockService.Verify(m => m.ScheduleEngineerShiftRange(It.IsAny <ShiftRequestModel>()), Times.Once());
        }
        public void ScheduleEngineersShiftRange_EndDate_Error()
        {
            Mock <IShiftService> mockService = new Mock <IShiftService>(MockBehavior.Strict);

            mockService.Setup(s => s.ScheduleEngineerShiftRange(It.IsAny <ShiftRequestModel>()));//.Returns(new List<EngineerShiftModel>());

            ShiftController controller = new ShiftController(mockService.Object);
            var             date       = DateTime.Now.NextDayOfWeek(DayOfWeek.Thursday);
            var             model      = new ShiftRequestModel
            {
                Count     = 2,
                StartDate = date.NextDayOfWeek(DayOfWeek.Tuesday),
                EndDate   = date
            };
            var result = controller.ScheduleEngineersShiftRange(model);

            Assert.NotNull(result);
            Assert.True(result.GetType() == typeof(BadRequestObjectResult));

            Assert.Equal("The final date must be greater than the initial date.", (result as BadRequestObjectResult).Value);
            mockService.Verify(m => m.ScheduleEngineerShiftRange(It.IsAny <ShiftRequestModel>()), Times.Never());
        }