Beispiel #1
0
        public void Controller_Calendar_Update_Post_Id_Is_Null_Or_Empty_Should_Return_Error_Page()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            SchoolCalendarModel dataNull  = new SchoolCalendarModel();
            SchoolCalendarModel dataEmpty = new SchoolCalendarModel();

            // Make data.Id = null
            dataNull.Id = null;

            // Make data.Id empty
            dataEmpty.Id = "";

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var resultNull  = (RedirectToRouteResult)controller.Update(dataNull);
            var resultEmpty = (RedirectToRouteResult)controller.Update(dataEmpty);

            // Assert
            Assert.AreEqual("Error", resultNull.RouteValues["action"], TestContext.TestName);
            Assert.AreEqual("Error", resultEmpty.RouteValues["action"], TestContext.TestName);
        }
Beispiel #2
0
        public void Controller_Calendar_Update_Post_TimeEnd_Invalid_Should_Send_Back_For_Edit()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            SchoolCalendarModel dataBelowMin = new SchoolCalendarModel
            {
                TimeEnd = TimeSpan.FromHours(0) // less than 1
            };

            SchoolCalendarModel dataAboveMax = new SchoolCalendarModel
            {
                TimeEnd = TimeSpan.FromHours(25) // greater than 24
            };

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult resultBelowMin = controller.Update(dataBelowMin) as ViewResult;
            ViewResult resultAboveMax = controller.Update(dataAboveMax) as ViewResult;

            // Assert
            Assert.IsFalse(controller.ModelState.IsValid);
            Assert.IsNotNull(resultBelowMin, TestContext.TestName);
            Assert.IsNotNull(resultAboveMax, TestContext.TestName);
        }
        public async Task Update_ShouldSendToEndpointAndReturnOk()
        {
            //Data
            var model = new CalendarEventModel
            {
                Id           = Guid.Empty,
                Name         = "test",
                LocationName = "testname",
                StartDate    = DateTime.Now,
                EndDate      = DateTime.Now
            };

            //Setup
            _mockEndpointInstance.Setup(x => x.Send(It.Is <UpdateCalendarEventCommand>(y =>
                                                                                       y.Model.Name == model.Name && y.Model.LocationName == model.LocationName &&
                                                                                       y.Model.StartDate == model.StartDate && y.Model.EndDate == model.EndDate), It.IsAny <SendOptions>()))
            .Returns(Task.CompletedTask).Verifiable();
            _mockUserManagerWrapper.Setup(x => x.FindByNameAsync(It.IsAny <string>())).Returns(Task.FromResult(new User()));
            var calendarController = new CalendarController(_mockEndpointInstance.Object, _mockUserManagerWrapper.Object);
            var controllerContext  = new ControllerContext
            {
                HttpContext = _httpContext.Object
            };

            calendarController.ControllerContext = controllerContext;

            //Test
            var result = await calendarController.Update(model) as OkResult;

            Assert.NotNull(result);
            Assert.AreEqual(200, result.StatusCode);

            //Analysis
            _mockEndpointInstance.Verify();
        }
        public void Edit_NotExistingIdPassed_ReturnsNotFoundResponse()
        {
            // Arrange
            var fakeEvent = Helpers.FakeEventGen();
            // Act
            var response = _controller.Update(fakeEvent.Id, fakeEvent); // DB is empty thus any id will work here.

            // Assert
            Assert.AreEqual(typeof(NotFoundResult), response.GetType());
        }
        public void Edit_ExistingIdPassed_ReturnsOkObjectResult()
        {
            // Arrange
            var joopOutEvent = Helpers.GetJoopOutEvent();

            joopOutEvent.Name = "Let's Update";

            //Act
            var response = _controller.Update(joopOutEvent.Id, joopOutEvent);

            // Assert
            Assert.AreEqual(typeof(OkObjectResult), response.GetType());
        }
Beispiel #6
0
        public void Controller_Calendar_Update_Post_Data_Is_Null_Should_Return_Error_Page()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Update((SchoolCalendarModel)null);

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
Beispiel #7
0
        public void Controller_Calendar_Update_Get_IdIsNull_ShouldReturnErrorPage()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Update((string)null);

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
Beispiel #8
0
        public void Controller_Calendar_Update_Post_Default_Should_Pass()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            SchoolCalendarModel scm = DataSourceBackend.Instance.SchoolCalendarBackend.GetDefault();

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = controller.Update(scm) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName);
        }
Beispiel #9
0
        public void Controller_Calendar_Update_Get_Default_Should_Pass()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            string id = DataSourceBackend.Instance.SchoolCalendarBackend.GetDefault().Id;

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Update(id) as ViewResult;

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
        public async Task EventUpdate_WithValidModel_Return_OkResult()
        {
            //Arrange
            var eventDto = new EventDTO
            {
                Title = "FAKE",
                Note  = "FAKE",
                Start = DateTime.Now,
                End   = DateTime.Now.AddHours(1)
            };

            //Act
            var result = await _controller.Update(eventDto);

            //Assert
            Assert.IsType <OkResult>(result);
        }
Beispiel #11
0
        public void Controller_Calendar_Update_Post_Model_Is_Invalid_Should_Send_Back_For_Edit()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            SchoolCalendarModel data = new SchoolCalendarModel();

            // Make ModelState Invalid
            controller.ModelState.AddModelError("test", "test");

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Update(data) as ViewResult;

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
Beispiel #12
0
        public void Controller_Calendar_Update_Get_myDataIsNull_ShouldReturnErrorPage()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            string id = DataSourceBackend.Instance.SchoolCalendarBackend.GetDefault().Id;

            // Reset DataSourceBackend
            DataSourceBackend.Instance.Reset();
            DataSourceBackend.SetTestingMode(true);

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Update(id);

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
            Assert.AreEqual("Home", result.RouteValues["controller"], TestContext.TestName);
        }
Beispiel #13
0
        public void Controller_Calendar_Update_Post_TimeEnd_Subtract_Invalid_Should_Send_Back_For_Edit()
        {
            // Arrange
            CalendarController controller = new CalendarController();

            SchoolCalendarModel data = new SchoolCalendarModel
            {
                // End is before Start
                TimeStart = TimeSpan.FromHours(4),
                TimeEnd   = TimeSpan.FromHours(2)
            };

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Update(data) as ViewResult;

            // Assert
            Assert.IsFalse(controller.ModelState.IsValid);                  // model is invalid
            Assert.IsTrue(data.TimeEnd.Subtract(data.TimeStart).Ticks < 1); // end is before start
            Assert.IsNotNull(result, TestContext.TestName);
        }