Пример #1
0
        public void Vehicle_CreateANewVehicle_DontSendColor_ResultInvalid()
        {
            var vehicle = new VehicleBuilder().WithColor(string.Empty).Builder();

            Assert.True(vehicle.Invalid);
            Assert.Contains("Color", vehicle.Notifications.Select(x => x.Property));
        }
Пример #2
0
        public void Vehicle_CreateANewVehicle_TypeTruck_NumberOfPassagers_Is42()
        {
            var vehicle = new VehicleBuilder().IsTruck().Builder();

            Assert.True(vehicle.Valid);
            Assert.Equal(2, vehicle.NumberOfPassagers);
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Running data import, sort and export program.");

            List <Vehicle> vehicles = new List <Vehicle>();

            using (ReadFile reader = new ReadFile("RazorbuleTechTask3.Resources.Technical Test Data.csv"))
            {
                // skip the first line as these are headers
                var data = reader.ReadLine();

                VehicleBuilder builder = new VehicleBuilder();

                // while lines exist in the reader, iterate over
                while ((data = reader.ReadLine()) != null)
                {
                    // split the line by comma
                    var options = data.Split(',');
                    vehicles.Add(builder.Construct(options));
                }
            }

            // before continuing to use the dataset
            // we need to remove any non-distinct vehicles by their registration
            vehicles = vehicles.Distinct(new Vehicle()).ToList();

            Step1(vehicles);
            Step2(vehicles);

            Console.ReadKey();
        }
        internal static VehicleBuilder RegisterVehicle(
            eVehicleType i_VehicleType,
            string i_Model,
            string i_LicenseNumber,
            string i_NameOfOwner,
            string i_PhoneNumOfOwner)
        {
            VehicleBuilder vehicleBuilder = null;

            switch (i_VehicleType)
            {
            case eVehicleType.Car:
                vehicleBuilder = new VehicleBuilder(new Car(i_Model, i_LicenseNumber, i_NameOfOwner, i_PhoneNumOfOwner));
                break;

            case eVehicleType.Truck:
                vehicleBuilder = new VehicleBuilder(new Truck(i_Model, i_LicenseNumber, i_NameOfOwner, i_PhoneNumOfOwner));
                break;

            case eVehicleType.MotorCycle:
                vehicleBuilder = new VehicleBuilder(new MotorCycle(i_Model, i_LicenseNumber, i_NameOfOwner, i_PhoneNumOfOwner));
                break;
            }

            return(vehicleBuilder);
        }
Пример #5
0
        static void Main(string[] args)
        {
            var vehicleBuilder = new VehicleBuilder();

            Vehicle avanza = vehicleBuilder
                             .WithManufacture("Toyota")
                             .WithType("Avanza")
                             .HavingDoors(5)
                             .HavingWheels(4)
                             .HavingWheelRadius(18.5);

            Console.WriteLine(avanza);
            Console.ReadKey();
            Console.WriteLine();

            avanza = vehicleBuilder.Move(10);
            Console.WriteLine(avanza);
            Console.ReadKey();
            Console.WriteLine();

            avanza = vehicleBuilder.Stop();
            Console.WriteLine(avanza);
            Console.ReadKey();
            Console.WriteLine();
        }
Пример #6
0
 public void CreateVehicle(VehicleBuilder builder)
 {
     builder.BuildFrame();
     builder.BuildEngine();
     builder.BuildWheels();
     builder.BuildDoors();
 }
Пример #7
0
 public void Construct(VehicleBuilder vehicleBuilder)
 {
     vehicleBuilder.BuildFrame();
     vehicleBuilder.BuildEngine();
     vehicleBuilder.BuildWheels();
     vehicleBuilder.BuildDoors();
 }
Пример #8
0
        public void engine_horse_power_can_not_be_negative()
        {
            IEnrollmentProvider enrollmentProvider = new DefaultEnrollmentProvider();
            IVehicleBuilder     builder            = new VehicleBuilder(enrollmentProvider);

            Negassert.mustFail(() => builder.setEngine(-70));
        }
Пример #9
0
 public void MotorCycleBuilder()
 {
     builder = new MotorCycleBuilder();
     shop.Construct(builder);
     builder.Vehicle.Show();
     Assert.IsNotNull(builder);
 }
Пример #10
0
        public void Plan_Should_Create_A_New_Job()
        {
            // arrange
            CustomerBuilder       customerBuilder       = new CustomerBuilder();
            VehicleBuilder        vehicleBuilder        = new VehicleBuilder();
            MaintenanceJobBuilder maintenanceJobBuilder = new MaintenanceJobBuilder();
            Customer customer = customerBuilder
                                .Build();
            Vehicle vehicle = vehicleBuilder
                              .WithCustomerId(customer.CustomerId)
                              .Build();
            MaintenanceJob sut = maintenanceJobBuilder
                                 .WithCustomer(customer)
                                 .WithVehicle(vehicle)
                                 .Build();

            // act
            // sut.Plan() is called by the Testdata Builder

            // assert
            Assert.Equal(maintenanceJobBuilder.Id, sut.Id);
            Assert.Equal(maintenanceJobBuilder.StartTime, sut.StartTime);
            Assert.Equal(maintenanceJobBuilder.EndTime, sut.EndTime);
            Assert.Equal(customer, sut.Customer);
            Assert.Equal(vehicle, sut.Vehicle);
            Assert.Equal(maintenanceJobBuilder.Description, sut.Description);
            Assert.Null(sut.ActualStartTime);
            Assert.Null(sut.ActualEndTime);
            Assert.Null(sut.Notes);
            Assert.Equal("Planned", sut.Status);
        }
Пример #11
0
        public void inMemoryVehicleStorage_must_be_empty_on_each_instance()
        {
            IVehicle vehicle, motoVehicle;

            SingleEnrollmentProvider        enrollmentProvider = new SingleEnrollmentProvider();
            IEqualityComparer <IEnrollment> equalityComparer   = new EnrollmentEqualityComparer();
            IVehicleBuilder vehicleBuilder = new VehicleBuilder(enrollmentProvider);
            IVehicleStorage vehicleStorage = new InMemoryVehicleStorage();

            vehicleBuilder.addWheel();
            vehicleBuilder.addWheel();
            vehicleBuilder.setDoors(0);
            vehicleBuilder.setEngine(40);
            motoVehicle = vehicleBuilder.build();

            Assert.AreEqual(0, vehicleStorage.Count);
            vehicleStorage.set(motoVehicle);
            Assert.AreEqual(1, vehicleStorage.Count);

            vehicle = vehicleStorage.get(enrollmentProvider.DefaultEnrollment);
            Assert.IsNotNull(vehicle);
            Assert.IsTrue(equalityComparer.Equals(enrollmentProvider.DefaultEnrollment, vehicle.Enrollment));

            vehicleStorage = new InMemoryVehicleStorage();
            Assert.AreEqual(0, vehicleStorage.Count);

            Negassert.mustFail(() =>
            {
                vehicle = vehicleStorage.get(enrollmentProvider.DefaultEnrollment);
            });
        }
Пример #12
0
        public void Finish_Should_Finish_An_Existing_Job()
        {
            // arrange
            CustomerBuilder       customerBuilder       = new CustomerBuilder();
            VehicleBuilder        vehicleBuilder        = new VehicleBuilder();
            MaintenanceJobBuilder maintenanceJobBuilder = new MaintenanceJobBuilder();
            Customer customer = customerBuilder
                                .Build();
            Vehicle vehicle = vehicleBuilder
                              .WithCustomerId(customer.CustomerId)
                              .Build();
            MaintenanceJob sut = maintenanceJobBuilder
                                 .WithCustomer(customer)
                                 .WithVehicle(vehicle)
                                 .Build();

            DateTime actualStartTime = maintenanceJobBuilder.StartTime.AddMinutes(30);
            DateTime actualEndTime   = maintenanceJobBuilder.EndTime.AddMinutes(15);
            string   notes           = $"Mechanic notes {maintenanceJobBuilder.Id}";

            // act
            sut.Finish(actualStartTime, actualEndTime, notes);

            // assert
            Assert.Equal(maintenanceJobBuilder.Id, sut.Id);
            Assert.Equal(maintenanceJobBuilder.StartTime, sut.StartTime);
            Assert.Equal(maintenanceJobBuilder.EndTime, sut.EndTime);
            Assert.Equal(customer, sut.Customer);
            Assert.Equal(vehicle, sut.Vehicle);
            Assert.Equal(maintenanceJobBuilder.Description, sut.Description);
            Assert.Equal(actualStartTime, sut.ActualStartTime.Value);
            Assert.Equal(actualEndTime, sut.ActualEndTime.Value);
            Assert.Equal(notes, sut.Notes);
            Assert.Equal("Completed", sut.Status);
        }
Пример #13
0
        public void Planning_Too_Much_MaintenanceJobs_In_Parallel_Should_Throw_Exception()
        {
            // arrange
            var initializingEvents = new Event[] {
                new WorkshopPlanningCreatedEventBuilder().WithDate(DateTime.Today).Build()
            };
            WorkshopPlanning sut = new WorkshopPlanning(initializingEvents);

            VehicleBuilder vehicleBuilder = new VehicleBuilder();
            PlanMaintenanceJobCommandBuilder commandBuilder = new PlanMaintenanceJobCommandBuilder()
                                                              .WithVehicleBuilder(vehicleBuilder);

            PlanMaintenanceJob command1 = commandBuilder.Build();

            vehicleBuilder.WithLicenseNumber(Guid.NewGuid().ToString());
            PlanMaintenanceJob command2 = commandBuilder.Build();

            vehicleBuilder.WithLicenseNumber(Guid.NewGuid().ToString());
            PlanMaintenanceJob command3 = commandBuilder.Build();

            vehicleBuilder.WithLicenseNumber(Guid.NewGuid().ToString());
            PlanMaintenanceJob command4 = commandBuilder.Build();

            // act
            sut.PlanMaintenanceJob(command1);
            sut.PlanMaintenanceJob(command2);
            sut.PlanMaintenanceJob(command3);
            var thrownException = Assert.Throws <BusinessRuleViolationException>(() => {
                sut.PlanMaintenanceJob(command4); // 4th parallel job
            });

            // assert
            Assert.Equal("Maintenancejob overlaps with more than 3 other jobs.",
                         thrownException.Message);
        }
Пример #14
0
        private static void buildMassiveVehicles(int numberOfVehicles, TimeSpan maxTime)
        {
            IEnrollmentProvider enrollmentProvider       = new DefaultEnrollmentProvider();
            IVehicleBuilder     builder                  = new VehicleBuilder(enrollmentProvider);
            IDictionary <IEnrollment, IVehicle> vehicles = new Dictionary <IEnrollment, IVehicle>();

            builder.addWheel();
            builder.addWheel();
            builder.addWheel();
            builder.addWheel();

            builder.setDoors(2);
            builder.setEngine(100);
            builder.setColor(CarColor.Red);

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < numberOfVehicles; i++)
            {
                IVehicle vehicle = builder.build();

                Assert.IsFalse(vehicles.ContainsKey(vehicle.Enrollment));
                vehicles.Add(vehicle.Enrollment, vehicle);

                Assert.IsTrue(stopwatch.Elapsed < maxTime);
            }
        }
Пример #15
0
    public bool SaveVehicle(string filepath)
    {
        int    removeIndex = filepath.LastIndexOf('/');
        string directory   = filepath.Remove(removeIndex);

        if (!Directory.Exists(directory))
        {
            Directory.CreateDirectory(directory);
        }

        StreamWriter sw = new StreamWriter(filepath);

        if (sw == null)
        {
            return(false);
        }
        string serializedVehicle = VehicleBuilder.SerializeVehicle(vehicle);

        if (serializedVehicle == string.Empty)
        {
            return(false);
        }
        sw.WriteLine(serializedVehicle);
        sw.WriteLine(vehicle.transform.childCount);
        sw.Close();
        return(true);
    }
Пример #16
0
        public void cannot_set_15_doors()
        {
            IEnrollmentProvider enrollmentProvider = new DefaultEnrollmentProvider();
            IVehicleBuilder     builder            = new VehicleBuilder(enrollmentProvider);

            Negassert.mustFail(() => builder.setDoors(15));
        }
Пример #17
0
        public void WrongBuildRequests_01()
        {
            SingleEnrollmentProvider enrollmentProvider = new SingleEnrollmentProvider();
            IVehicleBuilder          builder            = new VehicleBuilder(enrollmentProvider);

            Negassert.mustFail(() => builder.removeWheel());
            builder.addWheel();
            builder.addWheel();
            builder.addWheel();
            builder.addWheel();

            Negassert.mustFail(() => builder.setDoors(-27));
            builder.setDoors(5);
            Negassert.mustFail(() => builder.setEngine(-40));
            Negassert.mustFail(() => builder.setEngine(0));
            builder.setEngine(100);
            Negassert.mustFail(() => builder.setColor((CarColor)27));

            IVehicle vehicle = builder.build();

            Negassert.mustFail(() => vehicle.Engine.stop());

            vehicle.Engine.start();
            Negassert.mustFail(() => vehicle.Engine.start());

            Negassert.mustFail(() => vehicle.setWheelsPressure(-1));
            Negassert.mustFail(() => vehicle.setWheelsPressure(0));
            Negassert.mustFail(() => vehicle.setWheelsPressure(0.99));
            Negassert.mustFail(() => vehicle.setWheelsPressure(5.01));
            vehicle.setWheelsPressure(2);
        }
Пример #18
0
 public void Construct(VehicleBuilder vehicleBuilder)
 {
     vehicleBuilder.BuildShape();
     vehicleBuilder.BuildEngine();
     vehicleBuilder.BuildGearbox();
     vehicleBuilder.BuildWheels();
 }
        private void initVehicleBuilder(eVehicleType i_VehicleType)
        {
            switch (i_VehicleType)
            {
            case eVehicleType.FuelCar:
                m_VehicleBuilder = new FuelCarBuilder();
                break;

            case eVehicleType.ElectricCar:
                m_VehicleBuilder = new ElectricCarBuilder();
                break;

            case eVehicleType.FuelMotorcycle:
                m_VehicleBuilder = new FuelMotorcycleBuilder();
                break;

            case eVehicleType.ElectricMotorcycle:
                m_VehicleBuilder = new ElectricMotorcycleBuilder();
                break;

            case eVehicleType.FuelTruck:
                m_VehicleBuilder = new TruckBuilder();
                break;
            }
        }
Пример #20
0
 public void CarBuilding()
 {
     builder = new CarBuilder();
     shop.Construct(builder);
     builder.Vehicle.Show();
     Assert.IsNotNull(builder);
 }
Пример #21
0
 public void Construct(VehicleBuilder vehicleBuilder)
 {
     vehicleBuilder.BuildFrame();
     vehicleBuilder.BuildEngine();
     vehicleBuilder.BuildWheels();
     vehicleBuilder.BuildDoors();
 }
Пример #22
0
        private void addVehicle()
        {
            getOwnerDetails(out string ownerPhone, out string ownerName);
            Console.WriteLine("Please choose the vehicle type out of the following options");
            displayEnumOptions <VehicleBuilder.eVehicleType>();
            VehicleBuilder.eVehicleType userRequestedVehicleType =
                (VehicleBuilder.eVehicleType)getEnumChoiceFromUser <VehicleBuilder.eVehicleType>();
            Dictionary <string, VehicleParam> paramsDictionary = new Dictionary <string, VehicleParam>();
            Vehicle             vehicleToAdd   = VehicleBuilder.BuildVehicle(userRequestedVehicleType);
            List <VehicleParam> parametersList = vehicleToAdd.GetNewVehicleParams();

            foreach (VehicleParam param in parametersList)
            {
                Console.WriteLine("Please enter {0}", param.FriendlyName);
                if (param.Type.IsEnum)
                {
                    Console.WriteLine("Options: " + string.Join(",", Enum.GetNames(param.Type)));
                    string userInput = Console.ReadLine();
                    param.Value = Enum.Parse(param.Type, userInput);
                }
                else
                {
                    string userInput = Console.ReadLine();
                    param.Value = Convert.ChangeType(userInput, param.Type);
                }

                paramsDictionary.Add(param.Name, param);
            }

            vehicleToAdd.InitNewVehicle(paramsDictionary);
            m_Garage.AddVehicle(ownerPhone, ownerName, vehicleToAdd);
            Console.WriteLine("Vehicle was added to the garage");
        }
        public void Build_Should_ReturnResult_When_ValuesSet()
        {
            var actual = new VehicleBuilder().SetSpeed(1).SetNumberOfWheels(2).SetSpeed(3).Build();

            Assert.NotNull(actual);
            Assert.Equal(3, actual.Speed);
            Assert.Equal(2, actual.NumberOfWheels);
        }
Пример #24
0
 public override IVehicle Build(VehicleBuilder builder)
 {
     builder.BuildChassis();
     builder.BuildBody();
     builder.BuildReinforcedStorageArea();
     builder.BuildWindows();
     return(builder.Vehicle);
 }
Пример #25
0
 public void Construct(VehicleBuilder vehicleBuilder)
 {
     VehicleBuilder = vehicleBuilder;
     VehicleBuilder.SetCapacity();
     VehicleBuilder.SetDriver();
     VehicleBuilder.SetPrice();
     VehicleBuilder.SetChildChair();
 }
Пример #26
0
        public void FinishTheRaceWhenDistanceIsEqualToTotalRallyDistance(int checkVehicleStatusTimeInSeconds, int raceTotalDistance, double vehicleDistance)
        {
            var vehicle = VehicleBuilder.BuildWithDistance(vehicleDistance);

            var actual = vehicle.UpdateStatus(checkVehicleStatusTimeInSeconds, raceTotalDistance);

            actual.Status.Should().Be(VehicleStatus.Finished);
        }
 // Builder uses a complex series of steps
 public static void Construct(VehicleBuilder vehicleBuilder)
 {
     //一か所にまとめておくことも可能。
     vehicleBuilder.BuildFrame();
     vehicleBuilder.BuildEngine();
     vehicleBuilder.BuildWheels();
     vehicleBuilder.BuildDoors();
 }
Пример #28
0
        public void RemoveVehicleFromTheRace()
        {
            var vehicle = VehicleBuilder.BuildWithRunningStatus();

            var race = RaceBuilder.BuildWithVehicle(vehicle).RemoveVehicleBy(vehicle.Id);

            race.Vehicles.Should().NotContain(vehicle);
        }
Пример #29
0
 //There may be different constructors (with different steps order)
 public void Construct(VehicleBuilder vehicleBuilder)
 {
     //класа директор определя последователността на стъпките при изграждането на колата.
     vehicleBuilder.BuildFrame();
     vehicleBuilder.BuildEngine();
     vehicleBuilder.BuildWheels();
     vehicleBuilder.BuildDoors();
 }
Пример #30
0
 public void Construct(VehicleBuilder vehicleBuilder)
 {
     // These are the steps required to build a vehicle
     vehicleBuilder.BuildFrame();
     vehicleBuilder.BuildEngine();
     vehicleBuilder.BuildWheels();
     vehicleBuilder.BuildDoors();
 }
Пример #31
0
 //the director determines the order in which th steps are to be executed
 //being executed by the builder
 public override IVehicle Build(VehicleBuilder builder)
 {
     builder.BuildChassis();
     builder.BuildBody();
     builder.BuildPassengerArea();
     builder.BuildBoot();
     builder.BuildWindows();
     return builder.Vehicle;
 }
Пример #32
0
 public override IVehicle Build(VehicleBuilder builder)
 {
     builder.BuildChassis();
     builder.BuildBody();
     builder.BuildPassengerArea();
     builder.BuildBoot();
     builder.BuildWindows();
     return(builder.Vehicle);
 }