예제 #1
0
        public void filtering_vehicle_items()
        {
            ArrayEnrollmentProvider enrollmentProvider = new ArrayEnrollmentProvider();
            IVehicleBuilder         vehicleBuilder     = new VehicleBuilder(enrollmentProvider);

            vehicleBuilder.addWheel();
            vehicleBuilder.addWheel();
            vehicleBuilder.setColor(CarColor.Blue);
            vehicleBuilder.setDoors(0);
            vehicleBuilder.setEngine(40);

            using (IVehicleStorage vehicleStorage = new InMemoryVehicleStorage())
            {
                for (int i = 0; i < enrollmentProvider.Count; i++)
                {
                    IVehicle vehicle = vehicleBuilder.build();

                    if (i % 3 == 0)
                    {
                        vehicle.Engine.start();
                    }

                    vehicleStorage.set(vehicle);
                }

                Func <IVehicle, bool> byOddEnrollment = vehicle => vehicle.Enrollment.Number % 2 == 0;

                IEnumerable <IEngine> selectedEngines = vehicleStorage
                                                        .get()
                                                        .filter(byOddEnrollment)                               //4
                                                        .filter(vehicle => vehicle.Enrollment.Serial == "BBC") //2
                                                        .select(vehicle => vehicle.Engine)                     //2
                                                        .filter(engine => engine.IsStarted);                   //1

                Assert.AreEqual(1, selectedEngines.Count());
            }
        }
예제 #2
0
        public void vehicleStoarge_implementations_must_return_6_items()
        {
            ArrayEnrollmentProvider enrollmentProvider = new ArrayEnrollmentProvider();
            IVehicleBuilder         vehicleBuilder     = new VehicleBuilder(enrollmentProvider);

            IVehicleStorage[] vehicleStorages = new IVehicleStorage[]
            {
                new InMemoryVehicleStorage(),
                new FileVehicleStorage(this.VehiclesFilePath, vehicleBuilder),
            };

            vehicleBuilder.addWheel();
            vehicleBuilder.addWheel();
            vehicleBuilder.setColor(CarColor.Blue);
            vehicleBuilder.setDoors(0);
            vehicleBuilder.setEngine(40);

            for (int i = 0; i < enrollmentProvider.Count; i++)
            {
                IVehicle vehicle = vehicleBuilder.build();
                foreach (IVehicleStorage vehicleStorage in vehicleStorages)
                {
                    vehicleStorage.set(vehicle);
                }
            }

            foreach (IVehicleStorage vehicleStorage in vehicleStorages)
            {
                IEnumerable <IVehicle> vehicles = vehicleStorage.get();
                Assert.AreEqual(enrollmentProvider.Count, vehicles.Count());
            }

            foreach (IVehicleStorage vehicleStorage in vehicleStorages)
            {
                vehicleStorage.Dispose();
            }
        }