public bool Compile(CreateFormDecisionTable table, out CreateFormDecisionTable compiledTable, out List <string> errors) { if (table == null) { throw new ArgumentNullException("table"); } compiledTable = null; errors = null; //Explode rows containing CSVs or * //Set 'null' and '' to null CreateFormDecisionTable _compiledTable = table.Clone(); _compiledTable.Compiled = true; List <string> _errors = new List <string>(); CompileFormColumn(_compiledTable, _errors); CompileColumn(nameof(CreateFormDecisionRow.InitialEnrollmentStatus), AdapApplicationStatus.List, _compiledTable, _errors); CompileColumn(nameof(CreateFormDecisionRow.ReenrollmentStatus), AdapApplicationStatus.List, _compiledTable, _errors); CompileColumn(nameof(CreateFormDecisionRow.SvfWithChangesStatus), AdapApplicationStatus.List, _compiledTable, _errors); CompileColumn(nameof(CreateFormDecisionRow.SvfNoChangesStatus), SvfNoChangesStatus.List, _compiledTable, _errors); CompileColumn(nameof(CreateFormDecisionRow.UpdateFormStatus), AdapApplicationStatus.List, _compiledTable, _errors); //MoopStatus if (_errors.Count > 0) { errors = _errors; return(false); } compiledTable = _compiledTable; return(true); }
public void DeserializeJsonTest2() { //Arrange string path = Constants.Rules.CreateForms.DECISION_TABLE_PATH; if (!File.Exists(path)) { throw new Exception(String.Format("File does not exist {0}", path)); } string json = File.ReadAllText(path); if (String.IsNullOrWhiteSpace(json)) { throw new Exception("JSON string was null or whitespace"); } //Act CreateFormDecisionTable table = JsonConvert.DeserializeObject <CreateFormDecisionTable>(json); //Assert Assert.IsNotNull(table); Assert.AreEqual(Constants.Rules.CreateForms.REENROLLMENT_WINDOW_DAYS, table.ReenrollmentWindowDays); Assert.AreEqual(Constants.Rules.CreateForms.SVF_WINDOW_DAYS, table.SvfWindowDays); Assert.IsTrue(table.Rows.Count > 0); }
private void CompileFormColumn(CreateFormDecisionTable _compiledTable, List <string> _errors) { CreateFormDecisionTable tempTable = _compiledTable.Clone(); _compiledTable.Rows.Clear(); int rowNumber = 0; foreach (var row in tempTable.Rows) { row.RowNumber = ++rowNumber; if (String.IsNullOrWhiteSpace(row.Form)) { string error = String.Format("row.Form was null or white space. Row {0}: {1}", row.RowNumber, row); mLogger.LogError(error); _errors.Add(error); continue; } row.Form = row.Form.Trim(); if (!Form.LIST.Contains(row.Form)) { string error = String.Format("row.Form {0} is not a known value. Row {1}: {2}", row.Form, row.RowNumber, row); mLogger.LogError(error); _errors.Add(error); continue; } _compiledTable.Rows.Add(row); } }
public void CompileTest6() { //Arrange string path = Constants.Rules.CreateForms.DECISION_TABLE_PATH_6; if (!File.Exists(path)) { throw new Exception(String.Format("File does not exist {0}", path)); } var tableBuilder = GetCreateFormDecisionTableBuilder(); CreateFormDecisionTable table = tableBuilder.FromJson(path); if (table == null) { throw new Exception("table was null"); } //Act CreateFormDecisionTable compiledTable; List <string> errors; bool result = tableBuilder.Compile(table, out compiledTable, out errors); //Assert Assert.IsTrue(result); Assert.IsNotNull(compiledTable); Assert.IsNull(errors); Assert.IsTrue(compiledTable.Compiled); Assert.AreEqual(Constants.Rules.CreateForms.REENROLLMENT_WINDOW_DAYS, compiledTable.ReenrollmentWindowDays); Assert.AreEqual(Constants.Rules.CreateForms.SVF_WINDOW_DAYS, compiledTable.SvfWindowDays); Assert.IsTrue(compiledTable.Rows.Count == 4); Assert.IsTrue(compiledTable.Rows.Count >= table.Rows.Count); var rowCount = compiledTable.Rows .Where(x => x.Form == Form.INITIAL_ENROLLMENT) .Where(x => x.InitialEnrollmentStatus != null) .Where(x => x.ReenrollmentStatus == null) .Where(x => x.SvfWithChangesStatus == null) .Where(x => x.SvfNoChangesStatus == null) .Where(x => x.UpdateFormStatus == null) .Where(x => !x.CanCreate.Value) .Where(x => !String.IsNullOrWhiteSpace(x.Explanation)) .Where(x => x.CheckReenrollmentWindow.Value == FunctionColumn.NO) .Where(x => x.CheckSvfWindow.Value == FunctionColumn.NO) .Count(); Assert.AreEqual(compiledTable.Rows.Count, rowCount); Assert.IsTrue(compiledTable.Rows.Where(x => x.InitialEnrollmentStatus == AdapApplicationStatus.IN_PROGRESS).Any()); Assert.IsTrue(compiledTable.Rows.Where(x => x.InitialEnrollmentStatus == AdapApplicationStatus.NEEDS_REVIEW).Any()); Assert.IsTrue(compiledTable.Rows.Where(x => x.InitialEnrollmentStatus == AdapApplicationStatus.NEEDS_INFORMATION).Any()); Assert.IsTrue(compiledTable.Rows.Where(x => x.InitialEnrollmentStatus == AdapApplicationStatus.APPROVED).Any()); }
public void CompileTest1() { //Arrange string path = Constants.Rules.CreateForms.DECISION_TABLE_PATH_1; if (!File.Exists(path)) { throw new Exception(String.Format("File does not exist {0}", path)); } var tableBuilder = GetCreateFormDecisionTableBuilder(); CreateFormDecisionTable table = tableBuilder.FromJson(path); if (table == null) { throw new Exception("table was null"); } //Act CreateFormDecisionTable compiledTable; List <string> errors; bool result = tableBuilder.Compile(table, out compiledTable, out errors); //Assert Assert.IsTrue(result); Assert.IsNotNull(compiledTable); Assert.IsNull(errors); Assert.IsTrue(compiledTable.Compiled); Assert.AreEqual(Constants.Rules.CreateForms.REENROLLMENT_WINDOW_DAYS, compiledTable.ReenrollmentWindowDays); Assert.AreEqual(Constants.Rules.CreateForms.SVF_WINDOW_DAYS, compiledTable.SvfWindowDays); Assert.IsTrue(compiledTable.Rows.Count == 1); var row = compiledTable.Rows[0]; Assert.AreEqual(Form.INITIAL_ENROLLMENT, row.Form); Assert.IsNull(row.InitialEnrollmentStatus); Assert.IsNull(row.ReenrollmentStatus); Assert.IsNull(row.SvfWithChangesStatus); Assert.IsNull(row.SvfNoChangesStatus); Assert.IsNull(row.UpdateFormStatus); Assert.IsTrue(row.CanCreate.Value); Assert.IsFalse(String.IsNullOrWhiteSpace(row.Explanation)); Assert.AreEqual(FunctionColumn.NO, row.CheckReenrollmentWindow.Value); Assert.AreEqual(FunctionColumn.NO, row.CheckSvfWindow.Value); }
public void FromJsonTest() { //Arrange string path = Constants.Rules.CreateForms.DECISION_TABLE_PATH_1; if (!File.Exists(path)) { throw new Exception(String.Format("File does not exist {0}", path)); } var tableBuilder = GetCreateFormDecisionTableBuilder(); //Act CreateFormDecisionTable table = tableBuilder.FromJson(path); //Assert Assert.IsNotNull(table); Assert.AreEqual(Constants.Rules.CreateForms.REENROLLMENT_WINDOW_DAYS, table.ReenrollmentWindowDays); Assert.AreEqual(Constants.Rules.CreateForms.SVF_WINDOW_DAYS, table.SvfWindowDays); Assert.IsTrue(table.Rows.Count > 0); Assert.IsFalse(table.Compiled); }
private void CompileColumn(string columnName, string[] allowedStatusValues, CreateFormDecisionTable _compiledTable, List <string> _errors) { if (String.IsNullOrWhiteSpace(columnName)) { throw new ArgumentException("String was null or whitespace.", "columnName"); } if (allowedStatusValues == null) { throw new ArgumentNullException("allowedStatusValues"); } if (_compiledTable == null) { throw new ArgumentNullException("_compiledTable"); } if (_errors == null) { throw new ArgumentNullException("_errors"); } CreateFormDecisionTable tempTable = _compiledTable.Clone(); _compiledTable.Rows.Clear(); foreach (var row in tempTable.Rows) { PropertyInfo columnPropertyInfo = typeof(CreateFormDecisionRow).GetProperty(columnName); if (columnPropertyInfo == null) { throw new Exception(String.Format("Failed to get PropertyInfo for {0}", columnName)); } string cellValue = columnPropertyInfo.GetValue(row) as string; if (String.IsNullOrWhiteSpace(cellValue)) { columnPropertyInfo.SetValue(row, null); _compiledTable.Rows.Add(row); continue; } cellValue.Trim().ToUpperInvariant(); if (cellValue.Equals("NULL", StringComparison.InvariantCultureIgnoreCase)) { columnPropertyInfo.SetValue(row, null); _compiledTable.Rows.Add(row); continue; } if (cellValue.Equals("*", StringComparison.InvariantCultureIgnoreCase)) { //Exlode row including adding null var _row = new CreateFormDecisionRow(row); columnPropertyInfo.SetValue(_row, null); _compiledTable.Rows.Add(_row); foreach (string status in allowedStatusValues) { _row = new CreateFormDecisionRow(row); columnPropertyInfo.SetValue(_row, status); _compiledTable.Rows.Add(_row); } continue; } //Handle CSV if (cellValue.Contains(",")) { string[] statusList = cellValue .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .ToArray(); CreateFormDecisionRow _row; foreach (string status in statusList) { if (String.IsNullOrWhiteSpace(status)) { continue; } if (status.Equals("NULL", StringComparison.InvariantCultureIgnoreCase)) { _row = new CreateFormDecisionRow(row); columnPropertyInfo.SetValue(_row, null); _compiledTable.Rows.Add(_row); continue; } if (!allowedStatusValues.Contains(status)) { string error = String.Format("row.{0} {1} is not a known value. Row {2}: {3}", columnName, status, row.RowNumber, row); mLogger.LogError(error); _errors.Add(error); continue; } _row = new CreateFormDecisionRow(row); columnPropertyInfo.SetValue(_row, status.ToUpperInvariant()); _compiledTable.Rows.Add(_row); } continue; } //Handle simple case if (!allowedStatusValues.Contains(cellValue)) { string error = String.Format("row.{0} {1} is not a known value. Row {2}: {3}", columnName, cellValue, row.RowNumber, row); mLogger.LogError(error); _errors.Add(error); continue; } _compiledTable.Rows.Add(row); } }