示例#1
0
        public override bool Equals(object obj)
        {
            VehicleDetails vehicleDetails = obj as VehicleDetails;

            if ((object)vehicleDetails == null)
            {
                return(false);
            }

            return(this == vehicleDetails);
        }
示例#2
0
        public void Update(MitchellClaim updater)
        {
            if (updater.ClaimNumber != null && this.ClaimNumber != updater.ClaimNumber)
            {
                throw new InternalErrorException("MitchellClaim.Update can only be invoked with a claim that has the same claim number as the target claim.");
            }

            this.ClaimantFirstName = updater.ClaimantFirstName ?? this.ClaimantFirstName;
            this.ClaimantLastName = updater.ClaimantLastName ?? this.ClaimantLastName;
            this.Status = updater.Status ?? this.Status;
            this.LossDate = updater.LossDate ?? this.LossDate;
            this.AssignedAdjusterId = updater.AssignedAdjusterId ?? this.AssignedAdjusterId;

            if (updater.LossInfo != null)
            {
                this.LossInfo.Update(updater.LossInfo);
            }

            // Update or add vehicles present in the updater.
            if (updater.Vehicles != null)
            {
                foreach (VehicleDetails updaterVehicleDetails in updater.Vehicles)
                {
                    VehicleDetails existingVehicle =
                        this.Vehicles.FirstOrDefault(v => v.Vin == updaterVehicleDetails.Vin);
                    if (existingVehicle != null)
                    {
                        existingVehicle.Update(updaterVehicleDetails);
                    }
                    else
                    {
                        this.Vehicles.Add(updaterVehicleDetails.DeepClone());
                    }
                }

                // Now handle vehicle deletion.
                // Vehicles that are present in the current claim but absent in the updater will be deleted.
                List<VehicleDetails> vehiclesToDelete = new List<VehicleDetails>();
                foreach (VehicleDetails existingVehicleDetails in this.Vehicles)
                {
                    if (updater.Vehicles.FirstOrDefault(v => v.Vin == existingVehicleDetails.Vin) == null)
                    {
                        // A vehicle that was found in this claim is absent from the updater.
                        // This is an indication that the existing vehicle should be deleted.
                        vehiclesToDelete.Add(existingVehicleDetails);
                    }
                }

                foreach (VehicleDetails vehicleToDelete in vehiclesToDelete)
                {
                    this.Vehicles.Remove(vehicleToDelete);
                }
            }
        }
示例#3
0
 public void Update(VehicleDetails updater)
 {
     this.Vin               = updater.Vin ?? this.Vin;
     this.ModelYear         = updater.ModelYear ?? this.ModelYear;
     this.MakeDescription   = updater.MakeDescription ?? this.MakeDescription;
     this.ModelDescription  = updater.ModelDescription ?? this.ModelDescription;
     this.EngineDescription = updater.EngineDescription ?? this.EngineDescription;
     this.ExteriorColor     = updater.ExteriorColor ?? this.ExteriorColor;
     this.LicPlate          = updater.LicPlate ?? this.LicPlate;
     this.LicPlateState     = updater.LicPlateState ?? this.LicPlateState;
     this.LicPlateExpDate   = updater.LicPlateExpDate ?? this.LicPlateExpDate;
     this.DamageDescription = updater.DamageDescription ?? this.DamageDescription;
     this.Mileage           = updater.Mileage ?? this.Mileage;
 }
示例#4
0
        public void TestPutSimple()
        {
            string newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim expectedClaim = TestDataGenerator.GetTestClaim(newClaimNumber);

            // Create a new claim
            HttpResponseMessage response = ClaimsController.Post(expectedClaim);
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            // Prepare a claim "updater".
            MitchellClaim updater = new MitchellClaim();

            updater.ClaimantLastName = "NewLastName";
            expectedClaim.ClaimantLastName = updater.ClaimantLastName;

            updater.LossDate = expectedClaim.LossDate.Value.AddDays(1);
            expectedClaim.LossDate = updater.LossDate;

            // Note:  The updater will have to include both vehicles that are changed and those who are not changed.
            //        The vehicles that are not changed will only have the Vin field set.
            //        This system enables us to delete vehicles with the update request. The tread-off is that when we 
            //        specify a list of vehicles then that list must include vehicles that are not changed.
            updater.Vehicles = new List<VehicleDetails>();

            updater.Vehicles.Add(new VehicleDetails() { Vin = expectedClaim.Vehicles[0].Vin });

            VehicleDetails sourceVehicle = expectedClaim.Vehicles[1];
            VehicleDetails updaterVehicle = new VehicleDetails()
            {
                Vin = sourceVehicle.Vin,
                Mileage = sourceVehicle.Mileage + 100
            };
            updater.Vehicles.Add(updaterVehicle);
            sourceVehicle.Mileage = updaterVehicle.Mileage;

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "A PUT of an existing claim should succeed.");

            // Retrieved the updated claim and compare it with the expected value.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was created, updated and retrieved should have the expected values.");
        }
示例#5
0
        public VehicleDetails DeepClone()
        {
            VehicleDetails newVehicleDetails = new VehicleDetails()
            {
                Vin               = Vin,
                ModelYear         = ModelYear,
                MakeDescription   = MakeDescription,
                ModelDescription  = ModelDescription,
                EngineDescription = EngineDescription,
                ExteriorColor     = ExteriorColor,
                LicPlate          = LicPlate,
                LicPlateState     = LicPlateState,
                LicPlateExpDate   = LicPlateExpDate,
                DamageDescription = DamageDescription,
                Mileage           = Mileage,
            };

            return(newVehicleDetails);
        }
示例#6
0
        public void TestPutClaimAndAddNewVehicle()
        {
            string newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim expectedClaim = TestDataGenerator.GetTestClaim(newClaimNumber);

            // Create a new claim
            HttpResponseMessage response = ClaimsController.Post(expectedClaim);
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            // Prepare a claim "updater".
            MitchellClaim updater = new MitchellClaim();

            updater.ClaimantLastName = "NewLastName";
            expectedClaim.ClaimantLastName = updater.ClaimantLastName;

            // Note:  The updater will have to include both vehicles that are changed and those who are not changed.
            //        The vehicles that are not changed will only have the Vin field set.
            //        This system enables us to delete vehicles with the update request. The tread-off is that when we 
            //        specify a list of vehicles then that list must include vehicles that are not changed.
            updater.Vehicles = new List<VehicleDetails>();

            updater.Vehicles.Add(new VehicleDetails() { Vin = expectedClaim.Vehicles[0].Vin });
            updater.Vehicles.Add(new VehicleDetails() { Vin = expectedClaim.Vehicles[1].Vin });

            // We'll request a new vehicle to be added. However, this vehicle has required parameters that are not specified.
            VehicleDetails newVehicle = new VehicleDetails()
            {
                Vin = TestDataGenerator.GenerateUniqueVinNumber(),
                ModelYear = 2015,
                Mileage = 200
            };
            updater.Vehicles.Add(newVehicle);
            expectedClaim.Vehicles.Add(newVehicle.DeepClone());

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "A PUT of an existing claim should succeed.");

            // Retrieved the updated claim and compare it with the expected value.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim.Vehicles.Count, 3, "Defensive check - making sure that the expected claim was setup correctly.");
            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was created, updated and retrieved should have the expected values.");
        }
示例#7
0
        public VehicleDetails DeepClone()
        {
            VehicleDetails newVehicleDetails = new VehicleDetails()
            {
                Vin = Vin,
                ModelYear = ModelYear,
                MakeDescription = MakeDescription,
                ModelDescription = ModelDescription,
                EngineDescription = EngineDescription,
                ExteriorColor = ExteriorColor,
                LicPlate = LicPlate,
                LicPlateState = LicPlateState,
                LicPlateExpDate = LicPlateExpDate,
                DamageDescription = DamageDescription,
                Mileage = Mileage,
            };

            return newVehicleDetails;
        }
示例#8
0
 public void Update(VehicleDetails updater)
 {
     this.Vin = updater.Vin ?? this.Vin;
     this.ModelYear = updater.ModelYear ?? this.ModelYear;
     this.MakeDescription = updater.MakeDescription ?? this.MakeDescription;
     this.ModelDescription = updater.ModelDescription ?? this.ModelDescription;
     this.EngineDescription = updater.EngineDescription ?? this.EngineDescription;
     this.ExteriorColor = updater.ExteriorColor ?? this.ExteriorColor;
     this.LicPlate = updater.LicPlate ?? this.LicPlate;
     this.LicPlateState = updater.LicPlateState ?? this.LicPlateState;
     this.LicPlateExpDate = updater.LicPlateExpDate ?? this.LicPlateExpDate;
     this.DamageDescription = updater.DamageDescription ?? this.DamageDescription;
     this.Mileage = updater.Mileage ?? this.Mileage;
 }