Exemplo n.º 1
0
        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));
                }
            }
        }
Exemplo n.º 2
0
        public void fileVehicleStorage_must_persists_vehicles()
        {
            SingleEnrollmentProvider        enrollmentProvider = new SingleEnrollmentProvider();
            IEqualityComparer <IEnrollment> equalityComparer   = new EnrollmentEqualityComparer();
            IVehicleBuilder vehicleBuilder = new VehicleBuilder(enrollmentProvider);


            using (IVehicleStorage vehicleStorage =
                       new FileVehicleStorage(this.VehiclesFilePath, vehicleBuilder))
            {
                vehicleStorage.clear();
                Assert.AreEqual(0, vehicleStorage.Count);
            }

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

            using (IVehicleStorage vehicleStorage =
                       new FileVehicleStorage(this.VehiclesFilePath, vehicleBuilder))
            {
                vehicleStorage.set(motoVehicle);
                Assert.AreEqual(1, vehicleStorage.Count);
            }

            using (IVehicleStorage vehicleStorage =
                       new FileVehicleStorage(this.VehiclesFilePath, vehicleBuilder))
            {
                Assert.AreEqual(1, vehicleStorage.Count);

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