コード例 #1
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);
        }
コード例 #2
0
        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);
        }