public void FailWhenRallyDoesNotExist()
        {
            var rallyId = "rally1";
            var vehicle = new Vehicle
            {
                Id   = "v1",
                Type = VehicleType.SportCar
            };
            var vehicleFactoryMock = GetVehicleFactoryWhichReturns(vehicle.Id);
            var service            = new AddVehicleService(CommonBuilders.SetUpRepoWithNoRally(rallyId).Object, vehicleFactoryMock.Object);

            var result = service.AddVehicle(rallyId, vehicle);

            Assert.True(result.IsFailure);
            Assert.Equal(ErrorMessages.RallyNotFound, result.Error);
        }
        public void CallApproAppropriateMethodOnFactoryDependingOnVehicleType()
        {
            var rallyId = "2019";
            var vehicle = new Vehicle
            {
                Id   = "v1",
                Type = VehicleType.SportCar
            };
            var vehicleFactoryMock = GetVehicleFactoryWhichReturns(vehicle.Id);
            var rallyRepo          = CommonBuilders.SetUpRepoWithRally(
                rallyId, CommonBuilders.GetRallyThatAcceptsVehicle(vehicle.Id));
            var service = new AddVehicleService(rallyRepo, vehicleFactoryMock.Object);

            var result = service.AddVehicle(rallyId, vehicle);

            vehicleFactoryMock.Verify(factory => factory.CreateSportCar(vehicle.Id, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()));
        }
        public void ReturnOkWhenRallyExistsAndAcceptsVehicle()
        {
            var rallyId = "2019";
            var vehicle = new Vehicle
            {
                Id   = "v1",
                Type = VehicleType.SportCar
            };
            var vehicleFactoryMock = GetVehicleFactoryWhichReturns(vehicle.Id);
            var rallyRepo          = CommonBuilders.SetUpRepoWithRally(
                rallyId, CommonBuilders.GetRallyThatAcceptsVehicle(vehicle.Id));
            var service = new AddVehicleService(rallyRepo, vehicleFactoryMock.Object);

            var result = service.AddVehicle(rallyId, vehicle);

            Assert.True(result.IsSuccess);
            vehicleFactoryMock.Verify(factory => factory.CreateSportCar(vehicle.Id, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()));
        }
        public void ReturnFailWhenRallyExistsAndDoesNotAcceptVehicle()
        {
            var forReason = "Rally has already started.";
            var rallyId   = "2019";
            var vehicle   = new Vehicle
            {
                Id   = "v1",
                Type = VehicleType.SportCar
            };
            var vehicleFactoryMock = GetVehicleFactoryWhichReturns(vehicle.Id);
            var rallyRepo          = CommonBuilders.SetUpRepoWithRally(
                rallyId, CommonBuilders.GetRallyThatDoesNotAcceptsVehicle(vehicle.Id, forReason));
            var service = new AddVehicleService(rallyRepo, vehicleFactoryMock.Object);

            var result = service.AddVehicle(rallyId, vehicle);

            Assert.False(result.IsSuccess);
            vehicleFactoryMock.Verify(factory => factory.CreateSportCar(vehicle.Id, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()));
            Assert.Equal(forReason, result.Error);
        }
 public Result AddVehicle(string rallId, AddingVehicle vehicle)
 {
     return(_addVehicleToRallyService.AddVehicle(rallId, vehicle));
 }