示例#1
0
        public void WhenCanAddReminderWithInvalidDueDistance_ThenReturnsValidationResult()
        {
            var vehicle1 = new Vehicle
            {
                VehicleId = DefaultVehicleId,
                Name      = "vehicle1",
                Fillups   = new[] { new FillupEntry {
                                        Odometer = 7000
                                    } }
            };

            _vehicleRepositoryMock
            .Setup(vr => vr.GetVehicle(DefaultUserId, DefaultVehicleId))
            .Returns(vehicle1);

            var handler = new CanAddReminder(_vehicleRepositoryMock.Object);

            var formModel = new ReminderFormModel {
                VehicleId = DefaultVehicleId, Title = "Test", DueDistance = 5000
            };

            var result = handler.Execute(DefaultUserId, formModel);

            Assert.NotEmpty(result);
        }
        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));
            }
        }
示例#3
0
        public void WhenCanAddReminderWithInvalidVehicleId_ThenReturnsValidationResult()
        {
            const int nonExistentVehicleId = -1;

            _vehicleRepositoryMock
            .Setup(vr => vr.GetVehicle(DefaultUserId, nonExistentVehicleId))
            .Returns((Vehicle)null);

            var handler = new CanAddReminder(_vehicleRepositoryMock.Object);

            var formModel = new ReminderFormModel {
                VehicleId = nonExistentVehicleId, Title = "Test", DueDistance = 20000
            };

            var result = handler.Execute(DefaultUserId, formModel);

            Assert.NotEmpty(result);
        }
示例#4
0
        public void WhenCanAddReminder_ThenReturnsEmptyCollection()
        {
            var vehicle1 = new Vehicle {
                VehicleId = DefaultVehicleId, Name = "vehicle1"
            };

            _vehicleRepositoryMock
            .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
            .Returns(vehicle1);

            var handler = new CanAddReminder(_vehicleRepositoryMock.Object);

            var formModel = new ReminderFormModel {
                VehicleId = DefaultVehicleId, Title = "Test", DueDistance = 20000
            };

            var result = handler.Execute(DefaultUserId, formModel);

            Assert.Empty(result);
        }