public async Task TestViolationReportGeneration() { var ukprn = 12345678; var jobId = 100; var reportName = "EAS Rule Violation Report"; var filename = $"12345678_100_EAS Rule Violation Report-12345678-20200801-090000.csv"; var container = "container"; var submissionDate = new DateTime(2020, 8, 1, 9, 0, 0); var easJobContext = new Mock<IEasJobContext>(); easJobContext.Setup(jc => jc.FileReference).Returns("Filename"); easJobContext.Setup(jc => jc.Ukprn).Returns(ukprn); easJobContext.Setup(jc => jc.Container).Returns(container); easJobContext.Setup(jc => jc.JobId).Returns(jobId); easJobContext.Setup(jc => jc.SubmissionDateTimeUtc).Returns(submissionDate); var fileNameServiceMock = new Mock<IFileNameService>(); var csvServiceMock = new Mock<ICsvFileService>(); fileNameServiceMock.Setup(fns => fns.GetFilename(ukprn, jobId, reportName, It.IsAny<DateTime>(), OutputTypes.Csv)).Returns(filename); ViolationReport report = new ViolationReport(fileNameServiceMock.Object, csvServiceMock.Object); var result = await report.GenerateReportAsync(easJobContext.Object, new EasCsvRecordBuilder().Build(), new ValidationErrorModelBuilder().Build(), CancellationToken.None); result.First().Should().Be(filename); result.Should().HaveCount(1); fileNameServiceMock.VerifyAll(); csvServiceMock.VerifyAll(); }
public override void CheckColumn(ViolationReport report, Column column) { if (column.ParsedName.LastWord.Value == "Id" && column.Name != "Id") { ParsedIdentifier fullTableName = column.ParsedName.GetRange(0, -1); ParsedIdentifier nonQualifiedTableName = column.ParsedName.GetRange(1, -1); if (nonQualifiedTableName.Words.Count > 1 && _qualifierGlueWords.Contains(nonQualifiedTableName.FirstWord.Value)) { nonQualifiedTableName = nonQualifiedTableName.GetRange(1); } if (!(_specialReferenceNames.Contains(fullTableName.Value) || column.Table.Database.TablesByShortName.ContainsKey(fullTableName.Value) || column.Table.Database.TablesByShortName.ContainsKey(nonQualifiedTableName.Value))) { report.AddViolation(column, "The column ends with the word \"Id\" but no table exists that this " + "column should reference."); } } base.CheckColumn(report, column); }
public override void CheckTable(ViolationReport report, Table table) { if (!table.ParsedName.HasPrefix && table.Name.Name != "Version") { report.AddViolation(table, "The table name does not begin with a recognised table prefix."); } }
public override void CheckTable(ViolationReport report, Table table) { if (table.ParsedName.ContainsOneOfWord(_vagueWords)) { report.AddViolation(table, "The table name includes a word that may make the " + "name too vague. Try making the column name more descriptive or precise."); } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.Name == "Id" && column != column.Table.FirstColumn) { report.AddViolation(column, "The column has the name \"Id\", but does not follow the convention of " + "placing this field first in the column order."); } }
public override void CheckTable(ViolationReport report, Table table) { if (table.ParsedName.LastWord.Value.EndsWith("s")) { report.AddViolation(table, "The table name appears to be a plural, when all table names should be " + "singular."); } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.DataType == "float" && !column.ParsedName.ContainsOneOfWord(_floatSuggestingWords)) { report.AddViolation(column, "The column uses a float type when the name does not suggest that it is " + "a distance, length, weight or fraction. Monetary fields should never use " + "the floating point type; use a decimal instead."); } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.DataType != "bit") return; if (column.IsNullable) { report.AddViolation(column, "The column is a nullable bit column, which is only recommended where " + "null is assigned a specific meaning."); } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.Table.Name.Name == "Version") return; if (column.DataType == "varchar" || column.DataType == "text") { report.AddViolation(column, "Do not use the non-unicode data types \"varchar\" or \"text\". Use " + "\"nvarchar\" or \"ntext\" instead."); } }
public override void CheckTable(ViolationReport report, Table table) { foreach (ParsedWord word in table.ParsedName.Words) { if (!word.IsProperCase) { report.AddViolation(table, "The name of the table is not in proper case."); return; } } }
public override void CheckColumn(ViolationReport report, Column column) { foreach (ParsedWord word in column.ParsedName.Words) { if (!word.IsProperCase) { report.AddViolation(column, "The name of the column is not in proper case."); return; } } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.DataType == "varbinary" || column.DataType == "binary") { if (column.CharacterOctetLength > 510) { report.AddViolation(column, "The column is a large binary or varbinary column; making it an \"image\" type may " + "increase performance by reducing row sizes."); } } }
public override void CheckColumn(ViolationReport report, Column column) { foreach (ParsedWord word in column.ParsedName.Words) { if (word.Value.IndexOfAny(_vowels) == -1 && !_ignoreWords.Contains(word.Value)) { report.AddViolation(column, string.Format( "The word \"{0}\" in the column name appears to be an abbreviation (it does " + "not contain any vowels, and it is not a very well known abbreviation such as \"GST\" or " + "\"TFN\"). Abbreviations should in general never be used.", word.Value)); } } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.DataType == "char" || column.DataType == "nchar" || column.DataType == "varchar" || column.DataType == "nvarchar") { if (column.CharacterMaximumLength == 1) { report.AddViolation(column, "Avoid one letter character fields. The only " + "common use for them is as yes and no fields, which should use the " + "\"bit\" data type in any case."); } } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.ParsedName.ContainsOneOfWord(_booleanWords) && column.DataType != "bit") { report.AddViolation(column, "The column contains a word suggesting that it is a boolean field, but it " + "does not use the bit data type."); } if (column.DataType == "bit" && !column.ParsedName.ContainsOneOfWord(_booleanWords)) { report.AddViolation(column, "The column is a boolean field, but does not contain any word suggesting that " + "it is a boolean field. For example, prefixing the field with \"Is\" (if doing " + "so is grammatically correct) may make the use of the field clearer."); } }
public override void CheckTable(ViolationReport report, Table table) { if (table.Columns.Count <= 5) return; int nullFieldCount = 0; foreach (Column column in table.Columns.Values) { if (column.IsNullable) nullFieldCount++; } if ((double)nullFieldCount / (double)table.Columns.Count > 0.7) { report.AddViolation(table, "More than 70% of the fields in this table are nullable. This may indicate " + "that nullable fields are not being used properly."); } }
private void InsertViolation(object parameter) { if (ValidateEmployee(EmployeeId)) { if (Description != null) { using (KongBuBankEntities db = new KongBuBankEntities()) { Employee employee = db.Employees.Find(EmployeeId); int score = CalculateViolation(); employee.ViolationScore += score; ViolationReport report = new ViolationReport(); report.ViolationId = "VR" + IdFormat(Count("ViolationReport") + 1); report.EmployeeId = employee.EmployeeId; report.Score = score; report.Description = Description; report.Date = DateTime.Now; report.IsActive = true; db.ViolationReports.Add(report); db.SaveChanges(); CurrentEmployee = employee; MessageBox.Show("Violation Score Added! [" + CurrentEmployee.ViolationScore + "]", "Success"); if (CurrentEmployee.ViolationScore > VIOLATIONTHRESHOLD) { MessageBox.Show("Violation Threshold Exceeded. Please send firing request to Manager!", "Warning"); } } } else { MessageBox.Show("Description must be filled!", "Error"); } } }
public override void CheckColumn(ViolationReport report, Column column) { if (column.ParsedName.LastWord.Value == "Enum" && column.DataType != "int") { report.AddViolation(column, "Columns with names ending in \"Enum\" should " + "always use the data type \"int\"."); } if (column.ParsedName.ContainsWord("Fraction") && column.DataType != "float") { report.AddViolation(column, "Columns containing the word \"Fraction\" should " + "always use the data type \"float\"."); } if (column.ParsedName.ContainsOneOfWord(_percentageWords)) { report.AddViolation(column, "Columns should not contain the word \"Percentage\" " + "or similar words. Prefer using the \"Fraction\" convention; include the " + "word \"Fraction\" and use a floating point type with values between zero " + "and one to represent a fraction."); } }
public override void CheckColumn(ViolationReport report, Column column) { foreach (KeyValuePair<string, string> pair in _preferredWords) { if (column.ParsedName.ContainsWord(pair.Key)) { report.AddViolation(column, string.Format( "The column contains the word \"{0}\", which should not be used. Prefer the " + "word {1} instead.", pair.Key, pair.Value)); } } }
public virtual void CheckColumn(ViolationReport report, Column column) { }
public virtual void CheckDatabase(ViolationReport report, Database database) { }
public virtual void CheckTable(ViolationReport report, Table table) { }