コード例 #1
0
        public void WhenOverdueListWhenNoReminders_ThenReturnsModelWithEmptyCollection()
        {
            ReminderController controller = GetTestableReminderController();

            controller.HttpContext.Request.SetAjaxRequest();
            controller.HttpContext.Request.SetJsonRequest();

            MockHandlerFor <GetOverdueRemindersForUser>(
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId))
                .Returns(new ReminderModel[] { }));

            MockHandlerFor <GetVehicleById>(
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId, defaultVehicleId))
                .Returns(new VehicleModel(
                             new Vehicle {
                VehicleId = defaultVehicleId, Name = "Vehicle"
            },
                             new VehicleStatisticsModel())));

            var result = (JsonResult)controller.OverdueList();
            var model  = (JsonRemindersOverdueListViewModel)result.Data;
            var list   = new List <OverdueReminderViewModel>(model.Reminders);

            Assert.Equal(0, list.Count());
        }
コード例 #2
0
        public void WhenOverdueListInvalidUser_ThenThrows()
        {
            ReminderController controller = GetTestableReminderController();

            controller.HttpContext.Request.SetAjaxRequest();
            controller.HttpContext.Request.SetJsonRequest();

            MockHandlerFor(
                () => new Mock <GetOverdueRemindersForUser>(null, null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId))
                .Throws(new BusinessServicesException("Unable to get overdue reminders.")));

            MockHandlerFor(
                () => new Mock <GetVehicleById>(null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId, defaultVehicleId))
                .Returns(new VehicleModel(
                             new Vehicle {
                VehicleId = defaultVehicleId, Name = "Vehicle"
            },
                             new VehicleStatisticsModel())));

            Assert.Throws <BusinessServicesException>(() => { controller.OverdueList(); });
        }
コード例 #3
0
        public void WhenOverdueList_ThenReturnsModel()
        {
            ReminderController controller = GetTestableReminderController();

            controller.HttpContext.Request.SetAjaxRequest();
            controller.HttpContext.Request.SetJsonRequest();

            var dueDate   = new DateTime(2010, 12, 1, 0, 0, 0, DateTimeKind.Utc);
            var reminders = new[]
            {
                new ReminderModel
                {
                    ReminderId = 1,
                    VehicleId  = defaultVehicleId,
                    Title      = "Reminder1",
                    DueDate    = dueDate
                },
                new ReminderModel
                {
                    ReminderId  = 2,
                    VehicleId   = defaultVehicleId,
                    Title       = "Reminder2",
                    DueDistance = 1000
                },
                new ReminderModel
                {
                    ReminderId  = 3,
                    VehicleId   = defaultVehicleId,
                    Title       = "Reminder3",
                    DueDate     = dueDate,
                    DueDistance = 1000
                },
            };

            MockHandlerFor(
                () => new Mock <GetOverdueRemindersForUser>(null, null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId))
                .Returns(reminders));

            MockHandlerFor(
                () => new Mock <GetVehicleById>(null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId, defaultVehicleId))
                .Returns(new VehicleModel(
                             new Vehicle {
                VehicleId = defaultVehicleId, Name = "Vehicle"
            },
                             new VehicleStatisticsModel())));

            var result = (JsonResult)controller.OverdueList();
            var model  = (JsonRemindersOverdueListViewModel)result.Data;
            var list   = new List <OverdueReminderViewModel>(model.Reminders);

            Assert.Equal(reminders.Length, model.Reminders.Count());

            Assert.Equal("Reminder1 | Vehicle @ 12/1/2010", list[0].FullTitle);
            Assert.Equal("Reminder2 | Vehicle @ 1000", list[1].FullTitle);
            Assert.Equal("Reminder3 | Vehicle @ 12/1/2010 or 1000", list[2].FullTitle);
        }
コード例 #4
0
        public void WhenOverdueListWithNonJsonCall_ThenReturnsEmpty()
        {
            ReminderController controller = GetTestableReminderController();

            controller.HttpContext.Request.SetAjaxRequest();
            // no json set on context

            var dueDate   = new DateTime(2010, 12, 1, 0, 0, 0, DateTimeKind.Utc);
            var reminders = new[]
            {
                new ReminderModel
                {
                    ReminderId = 1,
                    VehicleId  = defaultVehicleId,
                    Title      = "Reminder1",
                    DueDate    = dueDate
                },
                new ReminderModel
                {
                    ReminderId  = 2,
                    VehicleId   = defaultVehicleId,
                    Title       = "Reminder2",
                    DueDistance = 1000
                },
                new ReminderModel
                {
                    ReminderId  = 3,
                    VehicleId   = defaultVehicleId,
                    Title       = "Reminder3",
                    DueDate     = dueDate,
                    DueDistance = 1000
                },
            };

            MockHandlerFor(
                () => new Mock <GetOverdueRemindersForUser>(null, null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId))
                .Returns(reminders));

            MockHandlerFor(
                () => new Mock <GetVehicleById>(null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId, defaultVehicleId))
                .Returns(new VehicleModel(
                             new Vehicle {
                VehicleId = defaultVehicleId, Name = "Vehicle"
            },
                             new VehicleStatisticsModel())));

            ActionResult result = controller.OverdueList();

            Assert.IsType <EmptyResult>(result);
        }