public void WhenRequestingVehicleDetails_ThenSetsRemindersList()
        {
            const int selectedVehicleId = 99;
            const int odometer          = 15000;

            var vehicle = new VehicleModel(
                new Vehicle {
                VehicleId = selectedVehicleId
            },
                new VehicleStatisticsModel(0, 0, 0, 0, odometer, 0)
                );

            var reminder = new ReminderSummaryModel(new Reminder(), false);

            MockHandlerFor(
                () => new Mock <GetVehicleListForUser>(null),
                m => m.Setup(h => h.Execute(defaultUser.UserId))
                .Returns(new[] { vehicle }));

            Mock <GetOverdueRemindersForVehicle> handler = MockHandlerFor(
                () => new Mock <GetOverdueRemindersForVehicle>(null),
                m => m.Setup(h => h.Execute(selectedVehicleId, It.IsAny <DateTime>(), odometer))
                .Returns(new[] { reminder })
                .Verifiable("Did not get overdue reminders.")
                );

            TestableVehicleController controller = GetTestableVehicleController();
            ActionResult result = controller.Details(selectedVehicleId);

            var model = result.Extract <VehicleDetailsViewModel>();

            handler.Verify();
            Assert.NotNull(model.OverdueReminders);
            Assert.Same(reminder, model.OverdueReminders.First());
        }
Пример #2
0
        public void WhenListReminderGetWithValidVehicleId_ThenReturnsView()
        {
            var vehicle = new VehicleModel(new Vehicle {
                VehicleId = defaultVehicleId
            },
                                           new VehicleStatisticsModel());

            var reminders = new[]
            {
                new Reminder {
                    ReminderId = 1
                },
                new Reminder {
                    ReminderId = 2
                }
            };

            MockHandlerFor <GetAllRemindersForVehicle>(
                x => x
                .Setup(h => h.Execute(defaultVehicleId))
                .Returns(reminders));

            MockHandlerFor <GetVehicleById>(
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId, defaultVehicleId))
                .Returns(vehicle));

            ReminderController controller = GetTestableReminderController();
            ActionResult       result     = controller.List(defaultVehicleId);

            var model = result.Extract <List <ReminderListViewModel> >();

            Assert.Equal(reminders.Length, model[0].Reminders.Count());
            Assert.Equal(reminders[0].ReminderId, model[0].Reminders.First().ReminderId);
        }
        public void WhenAddActionExecuted_ThenVehicleListSetToCollapsed()
        {
            MockDefaultYearMakeModel();
            MockVehicleList();

            TestableVehicleController controller = GetTestableVehicleController();
            ActionResult result = controller.Add();
            var          model  = result.Extract <VehicleAddViewModel>();

            Assert.True(model.VehiclesList.IsCollapsed);
        }
        public void WhenAddActionExecuted_ThenViewModelContainsVehicleListViewModel()
        {
            MockVehicleList();
            MockDefaultYearMakeModel();

            TestableVehicleController controller = GetTestableVehicleController();
            ActionResult result = controller.Add();
            var          model  = result.Extract <VehicleAddViewModel>();

            Assert.NotNull(model);
        }
Пример #5
0
        public void WhenRequestingDashboard_ThenReturnsUser()
        {
            MockHandlers();

            var          controller = GetTestableDashboardController();
            ActionResult result     = controller.Index();
            var          model      = result.Extract <DashboardViewModel>();

            Assert.NotNull(model);
            Assert.NotNull(model.User);
            Assert.Same(defaultUser, model.User);
        }
        public void WhenEditGetFormActionExecuted_ThenViewModelContainsVehicleListViewModel()
        {
            MockVehicleListWithVehicles();
            MockDefaultYearMakeModel();

            TestableVehicleController controller = GetTestableVehicleController();

            ActionResult result = controller.Edit(DefaultVehicleId);
            var          model  = result.Extract <VehicleAddViewModel>();

            Assert.IsType <VehicleAddViewModel>(model);
        }
Пример #7
0
        public void WhenRequestingVehicleDetails_ThenSetsVehicleListToCollapsedView()
        {
            MockHandlerFor <GetVehicleListForUser>(
                x => x.Setup(h => h.Execute(defaultUser.UserId))
                .Returns(DefaultVehicleId.StandardVehicleList()));

            MockHandlerFor <GetOverdueRemindersForVehicle>();

            var          controller = GetTestableVehicleController();
            ActionResult result     = controller.Details(DefaultVehicleId);
            var          model      = result.Extract <VehicleDetailsViewModel>();

            Assert.True(model.VehicleList.IsCollapsed);
        }
Пример #8
0
        public void WhenAddVehicleActionExecutedWithInvalidVehicle_ViewModelContainsVehicleFormViewModel()
        {
            MockVehicleList();
            MockDefaultYearMakeModel();

            TestableVehicleController controller = GetTestableVehicleController();

            controller.ModelState.AddModelError("bad", "bad");

            ActionResult result = controller.Add(new VehicleFormModel(), null, "Save");
            var          model  = result.Extract <VehicleFormModel>();

            Assert.NotNull(model);
        }
        public void WhenRequestingVehicleDetails_ThenSetsVehicleListInViewModel()
        {
            MockHandlerFor(
                () => new Mock <GetVehicleListForUser>(null),
                x => x
                .Setup(h => h.Execute(defaultUser.UserId))
                .Returns(DefaultVehicleId.StandardVehicleList()));

            MockHandlerFor(() => new Mock <GetOverdueRemindersForVehicle>(null));

            TestableVehicleController controller = GetTestableVehicleController();
            ActionResult result = controller.Details(DefaultVehicleId);
            var          model  = result.Extract <VehicleDetailsViewModel>();

            Assert.Equal(3, model.VehicleList.Vehicles.Count());
        }
        public void WhenAddVehicleActionExecutedWithInvalidVehicle_ThenVehicleListSetToCollapsed()
        {
            MockVehicleList();
            MockDefaultYearMakeModel();

            TestableVehicleController controller = GetTestableVehicleController();

            controller.ModelState.AddModelError("bad", "bad");

            ActionResult result = controller.Add(new FormCollection {
                { "Save", "true" }
            }, new VehicleFormModel(), null);
            var model = result.Extract <VehicleAddViewModel>();

            Assert.True(model.VehiclesList.IsCollapsed);
        }
        public void WhenEditGetFormActionExecuted_ThenVehicleListSetToCollapsed()
        {
            MockDefaultYearMakeModel();

            MockHandlerFor(
                () => new Mock <GetVehicleListForUser>(null),
                x => x
                .Setup(h => h.Execute(defaultUser.UserId))
                .Returns(DefaultVehicleId.StandardVehicleList()));

            TestableVehicleController controller = GetTestableVehicleController();

            ActionResult result = controller.Edit(DefaultVehicleId);
            var          model  = result.Extract <VehicleAddViewModel>();

            Assert.True(model.VehiclesList.IsCollapsed);
        }
        public void WhenListReminderGetWithValidVehicleId_ThenReturnsView()
        {
            var vehicles = new[]
            {
                new VehicleModel(new Vehicle {
                    VehicleId = defaultVehicleId
                },
                                 new VehicleStatisticsModel())
            };

            var reminders = new[]
            {
                new Reminder {
                    ReminderId = 1
                },
                new Reminder {
                    ReminderId = 2
                }
            };

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

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

            ReminderController controller = GetTestableReminderController();
            ActionResult       result     = controller.List(defaultVehicleId);

            var model = result.Extract <ReminderDetailsViewModel>();

            Assert.Equal(vehicles.Length, model.VehicleList.Vehicles.List.Count());
            Assert.Same(vehicles[0], model.VehicleList.Vehicles.SelectedItem);
            Assert.Equal(reminders.Length, model.Reminders.List.Count());
            Assert.Equal(reminders[0].ReminderId, model.Reminders.SelectedItem.ReminderId);
        }
Пример #13
0
        public void WhenRequestingVehicleDetails_ThenSetsViewModel()
        {
            var vehicle = new Vehicle {
                VehicleId = DefaultVehicleId
            };
            var list = new[] { new VehicleModel(vehicle, new VehicleStatisticsModel()) };

            MockHandlerFor <GetVehicleListForUser>(
                x => x.Setup(h => h.Execute(defaultUser.UserId))
                .Returns(list));

            MockHandlerFor <GetOverdueRemindersForVehicle>();

            TestableVehicleController controller = GetTestableVehicleController();
            ActionResult result = controller.Details(DefaultVehicleId);

            var model = result.Extract <VehicleDetailsViewModel>();

            Assert.NotNull(model);
        }
        public void WhenEditVehicleActionExecutedWithInValidVehicle_ThenVehicleListSetToCollapsed()
        {
            MockVehicleListWithVehicles();
            MockDefaultYearMakeModel();

            TestableVehicleController controller = GetTestableVehicleController();

            controller.ModelState.AddModelError("bad", "bad");

            var vehicle = new VehicleFormModel {
                VehicleId = 1, Name = null
            };
            var form = new FormCollection {
                { "Save", "true" }
            };

            ActionResult result = controller.Edit(form, vehicle, null);
            var          model  = result.Extract <VehicleAddViewModel>();

            Assert.True(model.VehiclesList.IsCollapsed);
        }