Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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());
        }
        public HttpResponseMessage PostReminder(int vehicleId, NewReminder reminder)
        {
            reminder.VehicleId = vehicleId;

            var errors = canAddReminder.Execute(1, reminder);

            ModelState.AddModelErrors(errors);

            if (ModelState.IsValid)
            {
                addReminderToVehicle.Execute(1, vehicleId, reminder);
                return(ReminderCreated(reminder));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }