public void WhenAddingReminder_ThenUpdatesServiceReminder() { const int newReminderId = 456; var vehicle = new Vehicle { VehicleId = DefaultVehicleId, Name = "vehicle" }; _vehicleRepository .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId)) .Returns(vehicle); _reminderRepository .Setup(r => r.Create(DefaultVehicleId, It.IsAny<Reminder>())) .Callback(new Action<int, Reminder>((vehicleId, reminder) => { // represents the entity created internally reminder.ReminderId = newReminderId; reminder.VehicleId = DefaultVehicleId; })); var formModel = new ReminderFormModel(); var handler = new AddReminderToVehicle(_vehicleRepository.Object, _reminderRepository.Object); handler.Execute(DefaultUserId, DefaultVehicleId, formModel); Assert.Equal(newReminderId, formModel.ReminderId); Assert.Equal(DefaultVehicleId, formModel.VehicleId); }
public void WhenAddingReminder_ThenDelegatesToReminderRepository() { var vehicle = new Vehicle { VehicleId = DefaultVehicleId, Name = "vehicle" }; _vehicleRepository .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId)) .Returns(vehicle); var handler = new AddReminderToVehicle(_vehicleRepository.Object, _reminderRepository.Object); handler.Execute(DefaultUserId, DefaultVehicleId, new ReminderFormModel()); _reminderRepository .Verify(r => r.Create(DefaultVehicleId, It.IsAny<Reminder>()), Times.Once()); }