public MitchellClaim DBGetClaimByID(string claimNum)
        {
            MitchellClaim ret = new MitchellClaim();

            try
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    string query =
                        " SELECT * " +
                        " FROM (( " +
                        "         MitchellClaims LEFT JOIN StatusCode ON (MitchellClaims.Status = StatusCode.StatusID) " +
                        "     ) AS withStatus LEFT JOIN LossInfo ON (withStatus.LossInfo = LossInfo.LossInfoID) " +
                        " ) AS withLossInfo LEFT JOIN CauseOfLossCode ON (withLossInfo.CauseOfLoss = CauseOfLossCode.CauseID) " +
                        " WHERE ClaimNumber = :ClaimNumber ";

                    using (NpgsqlCommand command = new NpgsqlCommand(query, connection))
                    {
                        command.Parameters.Add(new NpgsqlParameter("ClaimNumber", NpgsqlDbType.Varchar));

                        command.Parameters[0].Value = claimNum;

                        using (NpgsqlDataReader dr = command.ExecuteReader())
                        {
                            if (dr.Read())
                            {
                                ret = new MitchellClaim()
                                {
                                    ClaimNumber       = dr["ClaimNumber"].ToString().Trim(),
                                    ClaimantFirstName = dr["ClaimantFirstName"].ToString().Trim(),
                                    ClaimantLastName  = dr["ClaimantLastName"].ToString().Trim(),
                                    Status            = dr["StatusDesc"].ToString().Trim(),
                                    LossDate          = DateTime.Parse(dr["LossDate"].ToString().Trim()),
                                    LossInfo          = new LossInfoType()
                                    {
                                        CauseOfLoss     = dr["CauseDesc"].ToString().Trim(),
                                        ReportedDate    = DateTime.Parse(dr["ReportedDate"].ToString().Trim()),
                                        LossDescription = dr["LossDescription"].ToString().Trim()
                                    },
                                    AssignedAdjusterID = long.Parse(dr["AssignedAdjusterID"].ToString().Trim()),
                                    Vehicles           = new Vehicles()
                                };
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Error handling
                Console.WriteLine("Error in DBGetClaimByID(string claimNum): " + ex.Message);
            }
            finally
            {
            }

            return(ret);
        }
Example #2
0
        public void UpdateClaim(MitchellClaim updater)
        {
            if (string.IsNullOrWhiteSpace(updater.ClaimNumber))
            {
                throw new InvalidApiUsageException(ApiUsageError.ClaimNumberNotSpecified);
            }

            MitchellClaim existingClaim;

            if (_claims.TryGetValue(updater.ClaimNumber, out existingClaim))
            {
                // Before updating the claim let's make sure we will not end up with an invalid claim.
                // We are going to create a clone, update the clone and only if everything looks fine then we'll
                // persist the clone.
                MitchellClaim newClaim = existingClaim.DeepClone();
                newClaim.Update(updater);

                if (newClaim.ValidateRequiredFields() == false)
                {
                    throw new InvalidApiUsageException(ApiUsageError.RequiredFieldNotSpecified);
                }

                // Now that we know everything is OK, persist the updated claim.
                _claims[updater.ClaimNumber] = newClaim;
            }
            else
            {
                // This method is used incorrectly. The client may attempt to update a claim that does not exist but
                // that attempt should not propagate to this level.
                // As far as this method is concerned, this is an invalid call.
                throw new InvalidApiUsageException(ApiUsageError.ItemNotFound);
            }
        }
Example #3
0
        public void TestDeleteNotExistentClaim()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(testClaim, retrievedClaim, "The posted and retrieved claim should have the same values.");

            response = ClaimsController.Delete(newClaimNumber);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Deleting an existing claim should succeed.");

            try
            {
                response = ClaimsController.Delete(newClaimNumber);
                Assert.Fail("An attempt to delete a claim that does not exist should result in an error.");
            }
            catch (HttpResponseException ex) when(ex.Response.StatusCode == HttpStatusCode.NotFound)
            {
                // This is the expected behavior
            }
        }
        private void ReqCreateClaim(MitchellClaim cla)
        {
            try
            {
                string url = "http://localhost:35798/RestServiceImpl.svc/claims/create";

                // Build the POST request
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.Method      = "POST";
                req.ContentType = "application/json; charset=utf-8";
                req.Timeout     = System.Threading.Timeout.Infinite;
                req.KeepAlive   = false;
                req.Headers.Add("SOAPAction", url);

                using (var streamWriter = new StreamWriter(req.GetRequestStream()))
                {
                    string json = new JavaScriptSerializer().Serialize(cla);
                    ResTxt.Text = json;

                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                // Get the request's response
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                ResTxt.Text = "";
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
Example #5
0
        private HttpResponseMessage UpdateClaim(MitchellClaim updater)
        {
            HttpResponseMessage response;

            try
            {
                _repository.UpdateClaim(updater);
                response = new HttpResponseMessage(HttpStatusCode.OK);
            }
            catch (InvalidApiUsageException ex) when(ex.UsageError == ApiUsageError.RequiredFieldNotSpecified)
            {
                response = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    ReasonPhrase = "A required field is missing."
                };
            }
            catch (InvalidApiUsageException ex) when(ex.UsageError == ApiUsageError.DuplicateVehicles)
            {
                response = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    ReasonPhrase = "Duplicate vehicles are not allowed."
                };
            }

            return(response);
        }
Example #6
0
        public void TestPutWithRequiredParametersNotSpecified()
        {
            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";

            updater.Vehicles = new List <VehicleDetails>();

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

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "An update of a claim that would results in required fields that are not specified should fail with a specific status.");

            // Retrieved the claim we attempted to update and make sure it did not change.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was subject to a failed update should not have changed.");
        }
Example #7
0
        public void TestPutClaimWithEmptyVehicleList()
        {
            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.Vehicles = new List <VehicleDetails>();

            // Update the claim.
            response = ClaimsController.Put(newClaimNumber, updater);
            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "An update request where the updater has an empty vehicle list is not legal.");

            // Retrieved the claim we attempted to update and make sure it did not change.
            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(expectedClaim, retrievedClaim, "The claim that was subject to a failed update should not have changed.");
        }
Example #8
0
        public void TestPutClaimWithNoVehicleList()
        {
            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;

            // 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, 2, "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.");
        }
Example #9
0
        private string Serialize(MitchellClaim cla)
        {
            string XmlizedString = null;

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(MitchellClaim));
                //create an instance of the MemoryStream class since we intend to keep the XML string
                //in memory instead of saving it to a file.
                MemoryStream memoryStream = new MemoryStream();
                //XmlTextWriter - fast, non-cached, forward-only way of generating streams or files
                //containing XML data
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
                //Serialize emp in the xmlTextWriter
                xs.Serialize(xmlTextWriter, cla);
                //Get the BaseStream of the xmlTextWriter in the Memory Stream
                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                //Convert to array
                XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
            }
            catch (Exception ex)
            {
            }

            return(XmlizedString);
        }
        private MitchellClaim ReqGetClaimByID(string claimNum)
        {
            MitchellClaim ret = new MitchellClaim();

            try
            {
                string url = "http://localhost:35798/RestServiceImpl.svc/claims/" + claimNum; /*22c9c23bac142856018ce14a26b6c299 for George Washington's claim*/

                // Build the GET request
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "GET";

                using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                {
                    using (StreamReader sr = new StreamReader(res.GetResponseStream()))
                    {
                        JavaScriptSerializer js = new JavaScriptSerializer();
                        var objText             = sr.ReadToEnd();
                        ResTxt.Text = objText;
                        ret         = js.Deserialize <MitchellClaim>(objText);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(ret);
        }
        protected void BtnInsert_Click(object sender, EventArgs e)
        {
            // Get all fields' values
            string   newClaimNumber   = ((TextBox)(XmlGridView.FooterRow.FindControl("TxtClaNum"))).Text;
            string   newFirstName     = ((TextBox)(XmlGridView.FooterRow.FindControl("TxtFName"))).Text;
            string   newLastName      = ((TextBox)(XmlGridView.FooterRow.FindControl("TxtLName"))).Text;
            string   newStatus        = ((DropDownList)(XmlGridView.FooterRow.FindControl("DrpStatus"))).SelectedValue;
            DateTime newLossDate      = ((Calendar)(XmlGridView.FooterRow.FindControl("CalLossDate"))).SelectedDate;
            string   newLossInfoCause = ((DropDownList)(XmlGridView.FooterRow.FindControl("DrpLossInfoCause"))).SelectedValue;
            DateTime newReportedDate  = ((Calendar)(XmlGridView.FooterRow.FindControl("CalRepDate"))).SelectedDate;
            string   newLossInfoDesc  = ((TextBox)(XmlGridView.FooterRow.FindControl("TxtLossInfoDesc"))).Text;

            // Try parsing assigned adjuster ID to check if it's numeric
            string newAssignedAdjStr  = ((TextBox)(XmlGridView.FooterRow.FindControl("TxtAssAdjuster"))).Text;
            long   newAssignedAdjLong = 0;
            bool   assignedAdjIsNum   = long.TryParse(newAssignedAdjStr, out newAssignedAdjLong);

            // Validate fields
            if (newClaimNumber == "")
            {
                ResTxt.Text = "Claim number is required. Please enter a claim number.";
                return;
            }

            if (!assignedAdjIsNum ||
                newAssignedAdjStr == "")
            {
                ResTxt.Text = "Assigned adjuster ID must be numeric. Please enter a numeric ID.";
                return;
            }

            // Create Mitchell claim
            MitchellClaim cla = new MitchellClaim()
            {
                ClaimNumber       = newClaimNumber,
                ClaimantFirstName = newFirstName,
                ClaimantLastName  = newLastName,
                Status            = newStatus,
                LossDate          = newLossDate,
                LossInfo          = new LossInfoType()
                {
                    CauseOfLoss     = newLossInfoCause,
                    ReportedDate    = newReportedDate,
                    LossDescription = newLossInfoDesc
                },
                AssignedAdjusterID = newAssignedAdjLong,
                Vehicles           = new Vehicles()
                {
                    VehicleDetails = new List <VehicleDetails>()
                    {
                        new VehicleDetails()
                    }
                }
            };

            ReqCreateClaim(cla);

            UpdateGrid();
        }
Example #12
0
        public void TestPostClaimWithNoClaimNumber()
        {
            MitchellClaim testClaim = TestDataGenerator.GetTestClaim(null);

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that contains no claim number should fail with a specific status.");
        }
Example #13
0
        public void TestClaimDeepClone()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim claim          = TestDataGenerator.GetTestClaim(newClaimNumber);

            MitchellClaim anotherClaim = claim.DeepClone();

            Assert.AreEqual(claim, anotherClaim, "A deep cloned claim must have the same values as the original.");
        }
Example #14
0
        public MitchellClaim GetClaimType(string ClaimNumber)
        {
            MitchellClaim mitchclaim = new MitchellClaim();

            using (MitchellClaimsDbEntities _db = new MitchellClaimsDbEntities())
            {
                var claimval = (from claim in _db.mitchellClaims
                                where claim.ClaimNumber == ClaimNumber
                                select claim).FirstOrDefault();
                if (claimval != null)
                {
                    LossInfo _info = null;
                    if (claimval.lossInfo != null)
                    {
                        _info = new LossInfo()
                        {
                            CauseOfLoss     = (CauseOfLossCode)claimval.lossInfo.CauseOfLossId,
                            ReportedDate    = (DateTime)claimval.lossInfo.ReportedDate,
                            LossDescription = claimval.lossInfo.LossDescription
                        };
                    }

                    List <VehicleDetails> _vehicles = new List <VehicleDetails>();
                    foreach (var item in claimval.vehicleInfoes)
                    {
                        VehicleDetails vehicle = new VehicleDetails()
                        {
                            Vin               = item.Vin,
                            ModelYear         = (int)item.ModelYear,
                            MakeDescription   = item.MakeDescription,
                            ModelDescription  = item.ModelDescription,
                            EngineDescription = item.EngineDescription,
                            ExteriorColor     = item.ExteriorColor,
                            LicPlate          = item.LicPlate,
                            LicPlateState     = item.LicPlateState,
                            LicPlateExpDate   = (DateTime)item.LicPlateExpDate,
                            DamageDescription = item.DamageDescription,
                            Mileage           = (int)item.Mileage
                        };
                        _vehicles.Add(vehicle);
                    }

                    mitchclaim.ClaimNumber        = claimval.ClaimNumber;
                    mitchclaim.ClaimantFirstName  = claimval.ClaimantFirstName;
                    mitchclaim.ClaimantLastName   = claimval.ClaimantLastName;
                    mitchclaim.Status             = (StatusCode)claimval.Status;
                    mitchclaim.LossDate           = (DateTime)claimval.LossDate;
                    mitchclaim.LossInfo           = _info;
                    mitchclaim.AssignedAdjusterID = (int)claimval.AssignedAdjusterID;
                    mitchclaim.Vehicles           = _vehicles;
                }

                return(mitchclaim);
            }
        }
Example #15
0
        public void TestPostClaimWithNoVehicles()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            testClaim.Vehicles.Clear();

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that contains no vehicle information should fail with a specific status.");
        }
Example #16
0
        public void TestPostClaimWithRequiredParametersNotSpecified()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            testClaim.Vehicles[0].ModelYear = null;

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that has required fields that are not specified should fail with a specific status.");
        }
Example #17
0
        public void TestPostDuplicateClaim()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            response = ClaimsController.Post(testClaim);
            Assert.AreEqual(HttpStatusCode.Conflict, response.StatusCode, "A POST of a duplicate should fail with a specific status.");
        }
Example #18
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.");
        }
Example #19
0
        public void TestPostSimple()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "A POST of a new claim should succeed.");

            MitchellClaim retrievedClaim = ClaimsController.Get(newClaimNumber);

            Assert.AreEqual(testClaim, retrievedClaim, "The posted and retrieved claim should have the same values.");
        }
Example #20
0
        /// <summary>
        /// Updates the given claim changing a few fields.
        /// At this point, those fields are not parameterizable.
        /// </summary>
        /// <remarks>
        /// Note that UpdateClaim and GetTestClaimUpdateInXmlFormat must be kept in sync.
        /// </remarks>
        public static void UpdateClaim(MitchellClaim claim)
        {
            claim.ClaimantLastName = "NewLastName";
            claim.Status           = ClaimStatus.Open;
            claim.LossDate         = new DateTime(2016, 1, 2, 13, 14, 15, 700, DateTimeKind.Utc);

            claim.LossInfo.CauseOfLoss = CauseOfLoss.Collision;

            VehicleDetails vehicleDetails = claim.Vehicles.Single(v => v.Vin == "1M8GDM9AXKP000001");

            vehicleDetails.ModelYear       = 2014;
            vehicleDetails.LicPlateExpDate = new DateTime(2017, 1, 3, 0, 0, 0, DateTimeKind.Utc);
        }
Example #21
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.");
        }
Example #22
0
        public void TestPostClaimWithDuplicateVehicles()
        {
            string        newClaimNumber = TestDataGenerator.GenerateUniqueClaimNumber();
            MitchellClaim testClaim      = TestDataGenerator.GetTestClaim(newClaimNumber);

            testClaim.Vehicles.Clear();
            VehicleDetails vehicleDetails = TestDataGenerator.GetTestVehicle("1M8GDM9AXKP000001");

            testClaim.Vehicles.Add(vehicleDetails);
            testClaim.Vehicles.Add(vehicleDetails);

            HttpResponseMessage response = ClaimsController.Post(testClaim);

            Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "A POST of a claim that contains duplicate vehicles should fail with a specific status.");
        }
Example #23
0
        private MitchellClaim Deserialize(byte[] xmlByteData)
        {
            MitchellClaim cla = new MitchellClaim();

            try
            {
                XmlSerializer ds           = new XmlSerializer(typeof(MitchellClaim));
                MemoryStream  memoryStream = new MemoryStream(xmlByteData);
                cla = (MitchellClaim)ds.Deserialize(memoryStream);
            }
            catch (Exception ex)
            {
            }

            return(cla);
        }
        public void DBCreateClaim(MitchellClaim newClaim)
        {
            try
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    string query =
                        " INSERT INTO MitchellClaims (ClaimNumber, ClaimantFirstName, ClaimantLastName, Status, LossDate, LossInfo, AssignedAdjusterID, Vehicles) " +
                        " VALUES (:ClaimNumber, :ClaimantFirstName, :ClaimantLastName, :Status, :LossDate, :LossInfo, :AssignedAdjusterID, :Vehicles); ";

                    using (NpgsqlCommand command = new NpgsqlCommand(query, connection))
                    {
                        command.Parameters.Add(new NpgsqlParameter("ClaimNumber", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("ClaimantFirstName", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("ClaimantLastName", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("Status", NpgsqlDbType.Integer));
                        command.Parameters.Add(new NpgsqlParameter("LossDate", NpgsqlDbType.Timestamp));
                        command.Parameters.Add(new NpgsqlParameter("LossInfo", NpgsqlDbType.Integer));
                        command.Parameters.Add(new NpgsqlParameter("AssignedAdjusterID", NpgsqlDbType.Bigint));
                        command.Parameters.Add(new NpgsqlParameter("Vehicles", NpgsqlDbType.Integer));

                        command.Parameters[0].Value = newClaim.ClaimNumber;
                        command.Parameters[1].Value = (newClaim.ClaimantFirstName == "") ? ("") : (newClaim.ClaimantFirstName);
                        command.Parameters[2].Value = (newClaim.ClaimantLastName == "") ? ("") : (newClaim.ClaimantLastName);
                        command.Parameters[3].Value = (newClaim.Status == "OPEN") ? (1) : (2);
                        command.Parameters[4].Value = newClaim.LossDate;
                        command.Parameters[5].Value = DBCreateLossInfo(newClaim.LossInfo);
                        command.Parameters[6].Value = newClaim.AssignedAdjusterID;
                        command.Parameters[7].Value = DBCreateVehicleList(newClaim);

                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                // Error handling
                Console.WriteLine("Error in DBCreateClaim: " + ex.Message);
            }
            finally
            {
            }
        }
Example #25
0
        public void TestGetVehicleByClaimAndVin()
        {
            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.");

            VehicleDetails vehicleDetails0 = _vehiclesController.Get(newClaimNumber, expectedClaim.Vehicles[0].Vin);

            Assert.AreEqual(expectedClaim.Vehicles[0], vehicleDetails0, "GET of vehicle[0] of a claim should succeed.");

            VehicleDetails vehicleDetails1 = _vehiclesController.Get(newClaimNumber, expectedClaim.Vehicles[1].Vin);

            Assert.AreEqual(expectedClaim.Vehicles[1], vehicleDetails1, "GET of vehicle[1] of a claim should succeed.");
        }
Example #26
0
        public void AddClaim(MitchellClaim claim)
        {
            if (claim.ValidateRequiredFields() == false)
            {
                throw new InvalidApiUsageException(ApiUsageError.RequiredFieldNotSpecified);
            }

            if (_claims.ContainsKey(claim.ClaimNumber))
            {
                throw new InvalidApiUsageException(ApiUsageError.ItemAlreadyExists);
            }

            if (claim.Vehicles.GroupBy(v => v.Vin).Any(g => g.Count() > 1))
            {
                throw new InvalidApiUsageException(ApiUsageError.DuplicateVehicles);
            }

            _claims.Add(claim.ClaimNumber, claim);
        }
        public int DBCreateVehicleList(MitchellClaim newClaim)
        {
            int newVehicleListID = 0;

            try
            {
                using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
                {
                    connection.Open();

                    string query = " INSERT INTO VehicleList (VListClaimNumber) VALUES (:VListClaimNumber) RETURNING VListID; ";

                    using (NpgsqlCommand command = new NpgsqlCommand(query, connection))
                    {
                        command.Parameters.Add(new NpgsqlParameter("VListClaimNumber", NpgsqlDbType.Varchar));

                        command.Parameters[0].Value = newClaim.ClaimNumber;

                        newVehicleListID = Int32.Parse(command.ExecuteScalar().ToString().Trim());
                    }
                }
            }
            catch (Exception ex)
            {
                // Error handling
                Console.WriteLine("Error in DBCreateVehicleList: " + ex.Message);
            }
            finally
            {
            }

            if (newClaim.Vehicles.VehicleDetails.Count > 0)
            {
                // Store each vehicle in the claim in the database
                foreach (VehicleDetails v in newClaim.Vehicles.VehicleDetails)
                {
                    DBCreateVehicles(v, newVehicleListID);
                }
            }

            //Console.WriteLine("Added vehicle list ID: " + newVehicleListID);
            return(newVehicleListID);
        }
Example #28
0
        public MitchellClaim GetClaim(string ClaimNumber)
        {
            MitchellClaim _claim = new MitchellClaim();

            try
            {
                _claim = _repository.GetClaimType(ClaimNumber);
                if (_claim.ClaimNumber == null)
                {
                    throw new FaultException("There are no records for specific claim");
                }
                return(_claim);
            }
            catch (FaultException fault)
            {
                MitchellFault _fault = new MitchellFault();
                _fault.Message = fault.Message;
                throw new FaultException <MitchellFault>(_fault);
            }
        }
        private MitchellClaim CreateArbitrary(DateTime lossDate)
        {
            // Create arbitrary claim
            MitchellClaim cla = new MitchellClaim()
            {
                ClaimNumber       = GenerateRandomString(10),
                ClaimantFirstName = GenerateRandomString(10),
                ClaimantLastName  = GenerateRandomString(10),
                Status            = "OPEN",
                LossDate          = lossDate,
                LossInfo          = new LossInfoType()
                {
                    CauseOfLoss     = "Collision",
                    ReportedDate    = new DateTime(),
                    LossDescription = GenerateRandomString(50)
                },
                AssignedAdjusterID = 12345,
                Vehicles           = new Vehicles()
                {
                    VehicleDetails = new List <VehicleDetails>()
                    {
                        new VehicleDetails()
                        {
                            ModelYear         = 2015,
                            MakeDescription   = GenerateRandomString(10),
                            ModelDescription  = GenerateRandomString(10),
                            EngineDescription = GenerateRandomString(10),
                            ExteriorColor     = GenerateRandomString(10),
                            Vin               = GenerateRandomString(10),
                            LicPlate          = GenerateRandomString(10),
                            LicPlateState     = "CA",
                            LicPlateExpDate   = new DateTime(),
                            DamageDescription = GenerateRandomString(50),
                            Mileage           = 1000
                        }
                    }
                }
            };

            return(cla);
        }
Example #30
0
        /// <summary>
        /// Update an existing claim or creates a new claim.
        /// Rules regarding updating vehicles:
        ///     - If the <paramref name="updater"/> does not have a list of vehicles then no vehicle is updated.
        ///     - If the <paramref name="updater"/> contains a new vehicle (new based on its VIN number)
        ///       then that vehicle is added to the claim being updated.
        ///     - If the <paramref name="updater"/> contains a vehicle also found in the claim being updated
        ///       (based on its VIN number) then that vehicle is updated.
        ///     - If the <paramref name="updater"/> contains a vehicle also found in the claim being updated
        ///       (based on its VIN number) but the vehicle in the updater only has its VIN number specified then
        ///       then that vehicle is not changed in the claim being updated.
        ///     - If the <paramref name="updater"/> does not contain a vehicle that is found in the claim being updated
        ///       (based on its VIN number) then that vehicle is deleted from the claim being updated.
        /// </summary>
        /// <remarks>
        /// PUT api/<controller>/22c9c23bac142856018ce14a26b6c299
        /// </remarks>
        public HttpResponseMessage Put(string claimNumber, [FromBody] MitchellClaim updater)
        {
            if (updater.ClaimNumber != null && claimNumber != updater.ClaimNumber)
            {
                return(new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    ReasonPhrase = "Inconsistent claim number."
                });
            }

            // In case the updater does not specify the claim number.
            updater.ClaimNumber = claimNumber;

            if (_repository.ContainsClaim(claimNumber))
            {
                return(UpdateClaim(updater));
            }
            else
            {
                return(AddClaim(updater));
            }
        }