示例#1
0
 public void DBANAMETest()
 {
     ServiceCensusBlock target = new ServiceCensusBlock(); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     target.DBANAME = expected;
     actual = target.DBANAME;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#2
0
        public ActionResult MapData(DataMappingModel mappingModel, Submission submission)
        {
            if (Session[uploadKey] == null) {
                updateStatusMessage("Your session has expired. Please upload a new file.");
                return RedirectToAction("Index", "Home");
            }

            //get mappnig columns
            var columns = mappingModel.MappingObject;
            var defaultData = mappingModel.DefaultData;
            //get upload data
            var obj = Session[uploadKey] as dynamic;
            var data = obj.data as IEnumerable<IDictionary<string, object>>;
            //data to be stored
            IList<ServiceCensusBlock> dataList = new List<ServiceCensusBlock>();
            IDictionary<int, object> errorList = new Dictionary<int, object>();
            //by pass DefaultData validation
            var defaultDataModelStates = ModelState.Where(x => x.Key.Contains("DefaultData")).ToList();
            foreach (var state in defaultDataModelStates) {
                ModelState.Remove(state.Key);//remove these DefaultData states
            }
            //now that the model is valid we can start mapping data
            if (ModelState.IsValid) {
                int count = 1;//start at line 1
                foreach (var entry in data) {
                    short tempShort;
                    object tempValue;
                    string str, key, useDefault = "Use default";
                    try {
                        ModelState.Clear();//clear model state to validate transfer data
                        #region data transfer
                        var dataEntry = new ServiceCensusBlock();
                        //PROVIDER NAME
                        key = columns.PROVNAMEColumn;
                        tempValue = key == useDefault ? defaultData.PROVNAME : entry[key];
                        dataEntry.PROVNAME = tempValue != null ? tempValue.ToString() : string.Empty;

                        key = columns.DBANAMEColumn;
                        tempValue = key == useDefault ? defaultData.DBANAME : entry[key];
                        dataEntry.DBANAME = tempValue != null ? tempValue.ToString() : dataEntry.DBANAME;

                        key = columns.Provider_typeColumn;
                        tempValue = key == useDefault ? defaultData.Provider_Type : entry[key];
                        str = tempValue != null ? tempValue.ToString() : "";
                        dataEntry.Provider_Type =
                            short.TryParse(str, out tempShort) ?
                            tempShort : (short)-9999;

                        key = columns.FRNColumn;
                        tempValue = key == useDefault ? defaultData.FRN : entry[key];
                        dataEntry.FRN = tempValue != null ? tempValue.ToString().Replace("-", "") : dataEntry.FRN;

                        key = columns.FULLFIPSIDColumn;
                        tempValue = key == useDefault ? defaultData.FULLFIPSID : entry[key];
                        dataEntry.FULLFIPSID = tempValue != null ? tempValue.ToString() : dataEntry.FULLFIPSID;

                        key = columns.TRANSTECHColumn;
                        tempValue = key == useDefault ? defaultData.TRANSTECH : entry[key];
                        str = tempValue != null ? tempValue.ToString() : "";
                        dataEntry.TRANSTECH =
                            short.TryParse(str, out tempShort) ?
                            tempShort : dataEntry.TRANSTECH;

                        key = columns.MAXADDOWNColumn;
                        tempValue = key == useDefault ? defaultData.MAXADDOWN : entry[key];
                        dataEntry.MAXADDOWN = tempValue != null ? tempValue.ToString() : dataEntry.MAXADDOWN;

                        key = columns.MAXADUPColumn;
                        tempValue = key == useDefault ? defaultData.MAXADUP : entry[key];
                        dataEntry.MAXADUP = tempValue != null ? tempValue.ToString() : dataEntry.MAXADUP;

                        try {
                            key = columns.TYPICDOWNColumn;
                            tempValue = key == useDefault ? defaultData.TYPICDOWN : entry[key];
                            dataEntry.TYPICDOWN = tempValue != null ? tempValue.ToString() : dataEntry.TYPICDOWN;
                        }
                        catch {
                            //reserve default value if error occurs
                        }

                        try {
                            key = columns.TYPICUPColumn;
                            tempValue = key == useDefault ? defaultData.TYPICUP : entry[key];
                            dataEntry.TYPICUP = tempValue != null ? tempValue.ToString() : dataEntry.TYPICUP;
                        }
                        catch {
                            //reserve default value if error occurs
                        }

                        #endregion

                        //validate data for each entry
                        TryValidateModel(dataEntry);
                        if (ModelState.IsValid) {
                            dataList.Add(dataEntry);
                        }
                        else {
                            //redirect to report errors
                            errorList.Add(count, ModelState.ToList());
                        }
                    }
                    catch (Exception ex) {
                        ViewBag.errorMsg = "Error processing submitted data. " + ex.Message;
                        return View("Error");
                    }
                    count++;//increase count
                }
                //Session[uploadKey] = null;//discard session data
                //store data to be committed to session
                Session[mappingKey] = new {
                    mappingObject = columns,
                    validData = dataList,
                    defaultData = defaultData
                };

                //get submission
                if (submission != null) {
                    submission.DataCount = dataList.Count;
                    submission.RecordsStored = 0;
                    submission.ProgressPercentage = 0;

                    //check if the entry is already in the database
                    if (submission.SubmissionID == 0)
                        insertSubmission(submission);
                }
                //prepare view model
                var previewData = new PreviewMappingModel();
                previewData.SuccessCount = dataList.Count();
                previewData.ErrorList = errorList;
                previewData.Data = dataList;
                previewData.SubmissionID = submission.SubmissionID;
                return View("ReviewMapping", previewData);
            }
            //error has occured
            else {
                //re-populate view data
                List<string> uploadedColumns = data.First().Keys.ToList();
                //add 'use default' value to apply default values
                uploadedColumns.Add("Use default");
                mappingModel.UploadDataColumns = uploadedColumns;
                //data first row
                ViewBag.firstRowData = data.First().ToJSon();
                return View(mappingModel);
            }
        }
示例#3
0
 public void FRNTest()
 {
     ServiceCensusBlock target = new ServiceCensusBlock(); // TODO: Initialize to an appropriate value
     string expected = "0001234567"; // TODO: Initialize to an appropriate value
     string actual = "0001234567";
     target.FRN = "1234567";
     actual = target.FRN;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#4
0
 public void TRANSTECHTest()
 {
     ServiceCensusBlock target = new ServiceCensusBlock(); // TODO: Initialize to an appropriate value
     short expected = 0; // TODO: Initialize to an appropriate value
     short actual;
     target.TRANSTECH = expected;
     actual = target.TRANSTECH;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#5
0
 public void SubmissionTest()
 {
     ServiceCensusBlock target = new ServiceCensusBlock(); // TODO: Initialize to an appropriate value
     Submission expected = null; // TODO: Initialize to an appropriate value
     Submission actual;
     target.Submission = expected;
     actual = target.Submission;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#6
0
 public void ServiceCensusBlockConstructorTest()
 {
     ServiceCensusBlock target = new ServiceCensusBlock();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }