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); }); }
public void StorageComparison() { IVehicle motoVehicle; SingleEnrollmentProvider enrollmentProvider = new SingleEnrollmentProvider(); IEqualityComparer <IEnrollment> equalityComparer = new EnrollmentEqualityComparer(); IVehicleBuilder vehicleBuilder = new VehicleBuilder(enrollmentProvider); //IDtoConverter dtoConverter = new DefaultDtoConverter(enrollmentProvider); vehicleBuilder.addWheel(); vehicleBuilder.addWheel(); vehicleBuilder.setDoors(0); vehicleBuilder.setEngine(40); motoVehicle = vehicleBuilder.build(); using (IVehicleStorage vehicleMemoryStorage = new InMemoryVehicleStorage()) { using (IVehicleStorage vehicleFileStorage = new FileVehicleStorage(this.VehiclesFilePath, vehicleBuilder)) { vehicleFileStorage.set(motoVehicle); vehicleMemoryStorage.set(motoVehicle); } IVehicle memoryVehicleA = vehicleMemoryStorage.get(enrollmentProvider.DefaultEnrollment); IVehicle fileVehicle; using (IVehicleStorage vehicleFileStorage = new FileVehicleStorage(this.VehiclesFilePath, vehicleBuilder)) { fileVehicle = vehicleFileStorage.get(enrollmentProvider.DefaultEnrollment); Assert.IsNotNull(memoryVehicleA); Assert.IsNotNull(vehicleFileStorage); Assert.IsTrue(SameVehicle(memoryVehicleA, fileVehicle, equalityComparer)); } } }
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()); } }