public void FailWhenRallyDoesNotExist()
        {
            var rallyId = "rally1";
            var service = new StartRallyService(CommonBuilders.SetUpRepoWithNoRally(rallyId).Object);

            var result = service.StartRally(rallyId);

            Assert.True(result.IsFailure);
            Assert.Equal(ErrorMessages.RallyNotFound, result.Error);
        }
        public void FailWhenRallyDoesNotExist()
        {
            var rallyId = "rally1";
            var service = new RemoveVehicleService(CommonBuilders.SetUpRepoWithNoRally(rallyId).Object);

            var result = service.RemoveVehicleFromRally("rally1", "vehicle1");

            Assert.True(result.IsFailure);
            Assert.Equal(ErrorMessages.RallyNotFound, result.Error);
        }
        public void ReturnOkWhenRallyExistsAndSuccessfullyStarts()
        {
            var rallyId   = "rally1";
            var rallyRepo = CommonBuilders.SetUpRepoWithRally(
                rallyId,
                CommonBuilders.GetRallyThatSuccessfullyStarts());
            var service = new StartRallyService(rallyRepo);

            var result = service.StartRally(rallyId);

            Assert.True(result.IsSuccess);
        }
        public void FailWhenRallyDoesNotExist()
        {
            var rallyId   = "2019";
            var vehicleId = "vehicle1";
            var service   = new VehicleStatisticsService(
                CommonBuilders.SetUpRepoWithNoRally(rallyId).Object,
                new FakeVehicleStatisticsFactory(GetExpectedStats()));

            var result = service.GetVehicleStatistics(rallyId, vehicleId);

            Assert.True(result.IsFailure);
            Assert.Equal(ErrorMessages.RallyNotFound, result.Error);
        }
        public void ReturnOkWhenRallyExistsAndRemovesVehicle()
        {
            var rallyId   = "rally1";
            var vehicleId = "vehicle1";

            var rallyRepo = CommonBuilders.SetUpRepoWithRally(
                rallyId,
                CommonBuilders.GetRallyThatRemovesVehicle(vehicleId));
            var service = new RemoveVehicleService(rallyRepo);

            var result = service.RemoveVehicleFromRally(rallyId, vehicleId);

            Assert.True(result.IsSuccess);
        }
        public void FailWhenVehicleDoesNotExist()
        {
            var rallyId   = "2019";
            var vehicleId = "vehicle1";
            var rallyRepo = CommonBuilders.SetUpRepoWithRally(
                rallyId,
                CommonBuilders.GetRallyThatDoesNotHaveVehicle(vehicleId));
            var service = new VehicleStatisticsService(rallyRepo, new FakeVehicleStatisticsFactory(GetExpectedStats()));

            var result = service.GetVehicleStatistics(rallyId, vehicleId);

            Assert.True(result.IsFailure);
            Assert.Equal(ErrorMessages.VehicleDoesNotExist, result.Error);
        }
        public void ReturnFailWhenRallyExistsAndUnsuccessfullyStarts()
        {
            var rallyId   = "rally1";
            var forReason = "some reason";
            var rallyRepo = CommonBuilders.SetUpRepoWithRally(
                rallyId,
                CommonBuilders.GetRallyThatUnsuccessfullyStarts(forReason));
            var service = new StartRallyService(rallyRepo);

            var result = service.StartRally(rallyId);

            Assert.True(result.IsFailure);
            Assert.Equal(forReason, result.Error);
        }
        public void ReturnFailWhenRallyExistsAndDoesNotRemoveVehicle()
        {
            var rallyId   = "rally1";
            var vehicleId = "vehicle1";
            var forReason = "Rally has already started.";
            var rallyRepo = CommonBuilders.SetUpRepoWithRally(
                rallyId,
                CommonBuilders.GetRallyThatDoesNotRemoveVehicle(vehicleId, forReason));
            var service = new RemoveVehicleService(rallyRepo);

            var result = service.RemoveVehicleFromRally(rallyId, vehicleId);

            Assert.True(result.IsFailure);
            Assert.Equal(forReason, result.Error);
        }
        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 GetStatisticsWhenVehicleExists()
        {
            var rallyId       = "2019";
            var vehicleId     = "vehicle1";
            var fakeVehicle   = new FakeVehicle(vehicleId);
            var expectedStats = GetExpectedStats();
            var rallyRepo     = CommonBuilders.SetUpRepoWithRally(
                rallyId,
                CommonBuilders.GetRallyThatHasVehicle(vehicleId, fakeVehicle));
            var service = new VehicleStatisticsService(rallyRepo, new FakeVehicleStatisticsFactory(expectedStats));

            var result = service.GetVehicleStatistics(rallyId, vehicleId);

            Assert.True(result.IsSuccess);
            Assert.Equal(expectedStats, result.Value);
        }
        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);
        }