public void ShouldReportErrorWhenInvalidOrganizationNumbersAreFound() { AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .Build(); FlatFile flatFile = new FlatFile(fieldDefinition.GetAddmlFlatFileDefinition()); ControlOrganizationNumber test = new ControlOrganizationNumber(); test.Run(flatFile); test.Run(new Field(fieldDefinition, "914994780")); // ok test.Run(new Field(fieldDefinition, "914994781")); // invalid checksum test.Run(new Field(fieldDefinition, "91499478")); // invalid length test.Run(new Field(fieldDefinition, "91499478A")); // invalid characters test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(3); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig organisasjonsnummer: 914994781"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("Ugyldig organisasjonsnummer: 91499478"); testRun.Results[2].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[2].Message.Should().Be("Ugyldig organisasjonsnummer: 91499478A"); }
public void ShouldReportValuesShorterThanMinLength() { AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .WithMaxLength(3) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition.GetAddmlFlatFileDefinition()); A_18_ControlMaxLength test = new A_18_ControlMaxLength(); test.Run(flatFile); test.Run(new Field(fieldDefinition, "")); test.Run(new Field(fieldDefinition, "1")); test.Run(new Field(fieldDefinition, "12")); test.Run(new Field(fieldDefinition, "123")); test.Run(new Field(fieldDefinition, "1234")); test.Run(new Field(fieldDefinition, "1234")); test.Run(new Field(fieldDefinition, "12345")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Verdier lengre enn maksimumlengde: 1234 12345"); }
public void ShouldReportIncorrectDateDataFormat() { AddmlFieldDefinition fieldDefinition1 = new AddmlFieldDefinitionBuilder() .WithDataType(new DateDataType("dd.MM.yyyyTHH:mm:sszzz", null)) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition1.GetAddmlFlatFileDefinition()); ControlDataFormat test = new ControlDataFormat(); test.Run(flatFile); test.Run(new Field(fieldDefinition1, "")); test.Run(new Field(fieldDefinition1, "18.11.2016T08:43:00+00:00")); // ok test.Run(new Field(fieldDefinition1, "notadate")); test.Run(new Field(fieldDefinition1, "40.11.2016T08:43:00+00:00")); test.Run(new Field(fieldDefinition1, "18.11.2016")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition1.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig dataformat: '', 'notadate', '40.11.2016T08:43:00+00:00', '18.11.2016'"); }
public void ShouldFindNullValues() { List <string> nullValues = new List <string> { "null", "<null>" }; AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType(null, nullValues)) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition.GetAddmlFlatFileDefinition()); AnalyseCountNull test = new AnalyseCountNull(); test.Run(flatFile); test.Run(new Field(fieldDefinition, "1")); test.Run(new Field(fieldDefinition, "null")); test.Run(new Field(fieldDefinition, "nulll")); test.Run(new Field(fieldDefinition, "2")); test.Run(new Field(fieldDefinition, "<null>")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeTrue(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("2 forekomster av null"); }
public void ShouldReportInvalidChecksumValue() { string expectedSha256Hash = "3b67b886241a7d63798ea0e63a70cbca6c2109ab3962b2a5815cbadcb90cbb08".ToUpper(); AddmlFlatFileDefinition flatFileDefinition = new AddmlFlatFileDefinitionBuilder() .WithChecksum(new Checksum("SHA-256", "invalid")) .WithFileInfo(new FileInfo(TestUtil.TestDataDirectory + "checksum.txt")) .Build(); FlatFile flatFile = new FlatFile(flatFileDefinition); AH_01_ControlChecksum test = new AH_01_ControlChecksum(); test.Run(flatFile); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(flatFileDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should() .Contain("Forventet sjekksum: invalid").And .Contain("Aktuell sjekksum: " + expectedSha256Hash); }
public void ShouldReportIncorrectBooleanDataFormat() { AddmlFieldDefinition fieldDefinition1 = new AddmlFieldDefinitionBuilder() .WithDataType(new BooleanDataType("Y/N", null)) .Build(); AddmlFieldDefinition fieldDefinition2 = new AddmlFieldDefinitionBuilder() .WithDataType(new BooleanDataType("Ja/Nei", null)) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition1.GetAddmlFlatFileDefinition()); ControlDataFormat test = new ControlDataFormat(); test.Run(flatFile); test.Run(new Field(fieldDefinition1, "")); test.Run(new Field(fieldDefinition1, "Y")); test.Run(new Field(fieldDefinition1, "N")); test.Run(new Field(fieldDefinition1, "Ja")); test.Run(new Field(fieldDefinition1, "Nei")); test.Run(new Field(fieldDefinition2, "")); test.Run(new Field(fieldDefinition2, "Y")); test.Run(new Field(fieldDefinition2, "N")); test.Run(new Field(fieldDefinition2, "Ja")); test.Run(new Field(fieldDefinition2, "Nei")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(2); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition1.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig dataformat: '', 'Ja', 'Nei'"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinition2.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("Ugyldig dataformat: '', 'Y', 'N'"); }
public void ShouldReportErrorWhenInvalidBirthNumbersAreFound() { AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .Build(); FlatFile flatFile = new FlatFile(fieldDefinition.GetAddmlFlatFileDefinition()); A_32_ControlBirthNumber test = new A_32_ControlBirthNumber(); test.Run(flatFile); test.Run(new Field(fieldDefinition, "19089328341")); // ok test.Run(new Field(fieldDefinition, "19089328342")); // invalid checksum test.Run(new Field(fieldDefinition, "08011129480")); // ok test.Run(new Field(fieldDefinition, "08011129481")); // invalid checkum test.Run(new Field(fieldDefinition, "08063048608")); // ok test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(2); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig fødselsnummer: 19089328342"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("Ugyldig fødselsnummer: 08011129481"); }
public void ShouldReportNullValues() { List <string> nullValues = new List <string> { "null" }; AddmlFieldDefinition fieldDefinition1 = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType(null, nullValues)) .Build(); AddmlFieldDefinition fieldDefinition2 = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType(null, nullValues)) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition1.GetAddmlFlatFileDefinition()); ControlNotNull test = new ControlNotNull(); test.Run(flatFile); test.Run(new Field(fieldDefinition1, "A")); test.Run(new Field(fieldDefinition1, "null")); test.Run(new Field(fieldDefinition1, "B")); test.Run(new Field(fieldDefinition1, "C")); test.Run(new Field(fieldDefinition2, "A")); test.Run(new Field(fieldDefinition2, "B")); test.Run(new Field(fieldDefinition2, "C")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition1.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("NULL-verdier finnes"); }
public void ShouldOnlyShowSixErrorsPerFieldDefinition() { AddmlFieldDefinition fieldDefinition1 = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType("fnr", null)) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition1.GetAddmlFlatFileDefinition()); ControlDataFormat test = new ControlDataFormat(); test.Run(flatFile); test.Run(new Field(fieldDefinition1, "19980803")); // not ok test.Run(new Field(fieldDefinition1, "19990715")); // not ok test.Run(new Field(fieldDefinition1, "19880805")); // not ok test.Run(new Field(fieldDefinition1, "19890915")); // not ok test.Run(new Field(fieldDefinition1, "19990803")); // not ok test.Run(new Field(fieldDefinition1, "19880211")); // not ok test.Run(new Field(fieldDefinition1, "19890311")); // not ok, not shown test.Run(new Field(fieldDefinition1, "19890725")); // not ok, not shown test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition1.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig dataformat: '19980803', '19990715', '19880805', '19890915', '19990803', '19880211' + 2 flere"); }
public void ShouldReturnErrorWhenForeignKeyReferencesNonExistingPrimaryKeyValue() { var addmlFlatFileDefinition = new AddmlFlatFileDefinitionBuilder().Build(); var recordDef = new AddmlRecordDefinitionBuilder() .WithAddmlFlatFileDefinition(addmlFlatFileDefinition) .Build(); AddmlFieldDefinition primaryKeyFieldDef = recordDef.AddAddmlFieldDefinition("id", null, null, new IntegerDataType(), true, false, null, null, null, null, null, true); var primaryKeyField = new Field(primaryKeyFieldDef, "1001"); AddmlFieldDefinition foreignKeyFieldDef = new AddmlFieldDefinitionBuilder() .WithForeignKey(primaryKeyFieldDef) .Build(); var foreignKeyField = new Field(foreignKeyFieldDef, "25"); var controlForeignKey = new ControlForeignKey(); controlForeignKey.Run(primaryKeyField); controlForeignKey.Run(foreignKeyField); controlForeignKey.EndOfFile(); TestRun testRun = controlForeignKey.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); }
public void ShouldReportIfRecordDefinitionIsNotInUse() { AddmlFlatFileDefinition fileDefinition = new AddmlFlatFileDefinitionBuilder().Build(); AddmlRecordDefinition recordDefinitionInUse = new AddmlRecordDefinitionBuilder() .WithAddmlFlatFileDefinition(fileDefinition) .Build(); AddmlRecordDefinition recordDefinitionNotInUse = new AddmlRecordDefinitionBuilder() .WithAddmlFlatFileDefinition(fileDefinition) .Build(); AddmlFieldDefinition fieldDefinitionInUse = new AddmlFieldDefinitionBuilder() .WithRecordDefinition(recordDefinitionInUse) .Build(); AddmlFieldDefinition fieldDefinitionNotInUse = new AddmlFieldDefinitionBuilder() .WithRecordDefinition(recordDefinitionNotInUse) .Build(); FlatFile flatFile = new FlatFile(fileDefinition); A_14_ControlNotUsedRecordDef test = new A_14_ControlNotUsedRecordDef(); test.Run(flatFile); test.Run(new Arkade.Core.Base.Addml.Record(recordDefinitionInUse, new List <Field> { new Field(fieldDefinitionInUse, "A"), new Field(fieldDefinitionInUse, "A"), new Field(fieldDefinitionInUse, "B") })); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(recordDefinitionNotInUse.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Posttypen er ikke i bruk"); }
public void ShouldCreateFrequencyList() { AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder().Build(); FlatFile flatFile = new FlatFile(fieldDefinition.GetAddmlFlatFileDefinition()); AnalyseFrequenceList test = new AnalyseFrequenceList(); test.Run(flatFile); test.Run(new Field(fieldDefinition, "A")); test.Run(new Field(fieldDefinition, "A")); test.Run(new Field(fieldDefinition, "B")); test.Run(new Field(fieldDefinition, "B")); test.Run(new Field(fieldDefinition, "B")); test.Run(new Field(fieldDefinition, "C")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeTrue(); testRun.Results.Count.Should().Be(3); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("2 forekomster av A"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("3 forekomster av B"); testRun.Results[2].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[2].Message.Should().Be("1 forekomster av C"); }
public void ShouldReportIfRecordLengthIsDifferentFromSpecified() { AddmlRecordDefinition recordDefiniton = new AddmlRecordDefinitionBuilder() .WithRecordLength(10) .Build(); AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .WithRecordDefinition(recordDefiniton) .Build(); FlatFile flatFile = new FlatFile(recordDefiniton.AddmlFlatFileDefinition); ControlFixedLength test = new ControlFixedLength(); test.Run(flatFile); test.Run(new Arkade.Core.Base.Addml.Record(recordDefiniton, new List <Field> { new Field(fieldDefinition, "1"), new Field(fieldDefinition, "12"), new Field(fieldDefinition, "123"), })); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(recordDefiniton.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Oppgitt postlengde (10) er ulik faktisk (6)"); }
public void ShouldNotReportExtraFilesWhenDefinedInDokversXml() { WorkingDirectory workingDirectory = new WorkingDirectory(null, new DirectoryInfo(TestUtil.TestDataDirectory + "noark4-extrafiles")); AddmlFlatFileDefinition flatFileDefinition2 = new AddmlFlatFileDefinitionBuilder() .WithFileInfo(new FileInfo( workingDirectory.Content().DirectoryInfo().FullName + Path.DirectorySeparatorChar + "DOKVERS.XML")) .WithFileName("DATA\\DOKVERS.XML") .Build(); AddmlDefinition addmlDefinition = new AddmlDefinitionBuilder() .WithAddmlFlatFileDefinitions(new List <AddmlFlatFileDefinition> { flatFileDefinition2 }) .Build(); Archive archive = new Archive(ArchiveType.Noark4, Uuid.Random(), workingDirectory); ControlExtraOrMissingFiles test = new ControlExtraOrMissingFiles(addmlDefinition, archive); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeTrue(); }
public void ShouldVerifyThatOnlyCodesAreUsed() { AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .WithCodeList(new List <AddmlCode> { new AddmlCode("Y", ""), new AddmlCode("N", "") }) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition.GetAddmlFlatFileDefinition()); ControlCodes test = new ControlCodes(); test.Run(flatFile); test.Run(new Field(fieldDefinition, "Y")); test.Run(new Field(fieldDefinition, "N")); test.Run(new Field(fieldDefinition, "A")); test.Run(new Field(fieldDefinition, "B")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ikke i kodelisten: A B"); }
public void ShouldReturnNoErrorsWhenAllForeignKeysExists() { var addmlFlatFileDefinition = new AddmlFlatFileDefinitionBuilder().Build(); var recordDef = new AddmlRecordDefinitionBuilder() .WithAddmlFlatFileDefinition(addmlFlatFileDefinition) .Build(); AddmlFieldDefinition primaryKeyFieldDef = recordDef.AddAddmlFieldDefinition("id", null, null, new IntegerDataType(), true, false, null, null, null, null, null, true); var primaryKeyField = new Field(primaryKeyFieldDef, "1001"); AddmlFieldDefinition foreignKeyFieldDef = recordDef.AddAddmlFieldDefinition("foreignKeyId", null, null, new IntegerDataType(), true, false, null, null, null, null, null, false); var foreignKeyField = new Field(foreignKeyFieldDef, "1001"); var controlForeignKey = new ControlForeignKey(); controlForeignKey.Run(primaryKeyField); controlForeignKey.Run(foreignKeyField); controlForeignKey.EndOfFile(); TestRun testRun = controlForeignKey.GetTestRun(); testRun.IsSuccess().Should().BeTrue(); }
public void ShouldReportErrorWhenInvalidAccountNumbersAreFound() { AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .Build(); FlatFile flatFile = new FlatFile(fieldDefinition.GetAddmlFlatFileDefinition()); A_34_ControlAccountNumber test = new A_34_ControlAccountNumber(); test.Run(flatFile); test.Run(new Field(fieldDefinition, "12345678903")); // ok test.Run(new Field(fieldDefinition, "12345678901")); // invalid checksum test.Run(new Field(fieldDefinition, "1234567890")); // invalid length test.Run(new Field(fieldDefinition, "1234567890A")); // invalid characters test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(3); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig kontonummer: 12345678901"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("Ugyldig kontonummer: 1234567890"); testRun.Results[2].Location.ToString().Should().Be(fieldDefinition.GetIndex().ToString()); testRun.Results[2].Message.Should().Be("Ugyldig kontonummer: 1234567890A"); }
public void XmlFilesAreValidAccordingToSchema() { string workingDirectory = $"{AppDomain.CurrentDomain.BaseDirectory}\\TestData\\Noark5\\StructureValidation\\correct"; TestRun testRun = CreateTestRun(workingDirectory); testRun.IsSuccess().Should().BeTrue(); }
private void Test(TestRun testRun) { _stream.WriteLine(@" <div class=""test"">"); _stream.WriteLine(@" <h3>"); _stream.WriteLine(@" " + testRun.TestName); _stream.WriteLine(@" </h3>"); _stream.WriteLine(@""); _stream.WriteLine(@" <p class=""test-description"">"); _stream.WriteLine(@" " + testRun.TestDescription); _stream.WriteLine(@" </p>"); _stream.WriteLine(@""); _stream.WriteLine(@" <h4>" + Resources.Report.HeadingTestResults + "</h4>"); if (testRun.IsSuccess() && (testRun.TestType == TestType.ContentControl || testRun.TestType == TestType.Structure)) { _stream.WriteLine("<p>" + Resources.Report.TestNoErrorsFound + "</p>"); } else { _stream.WriteLine(@" <table class=""table"">"); _stream.WriteLine(@" <thead>"); _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <th>" + Resources.Report.TestLocation + "</th>"); _stream.WriteLine(@" <th>" + Resources.Report.TestMessage + "</th>"); _stream.WriteLine(@" </tr>"); _stream.WriteLine(@" </thead>"); _stream.WriteLine(@" <tbody>"); foreach (TestResult testResult in testRun.Results.Take(NumberOfErrorsToShow)) // TODO only first 100 results are included due to problem loading report in browser { _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <td>"); _stream.WriteLine(@" " + testResult.Location); _stream.WriteLine(@" </td>"); _stream.WriteLine(@" <td>"); _stream.WriteLine(@" " + SubstitueLineBreaksWithHtmlBreak(testResult.Message)); _stream.WriteLine(@" </td>"); _stream.WriteLine(@" </tr>"); } if (testRun.Results.Count > NumberOfErrorsToShow) { _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <td></td>"); _stream.WriteLine(@" <td>" + string.Format(Resources.Report.TestMoreErrorsOfSameKind, testRun.Results.Count - NumberOfErrorsToShow) + "</td>"); _stream.WriteLine(@" </tr>"); } _stream.WriteLine(@" </tbody>"); _stream.WriteLine(@" </table>"); } _stream.WriteLine(@" </div>"); }
public void ShouldReturnSuccessWhenSingleForeignKeyReferenceExist() { var attachmentDataRecord = new Record(_attachmentRecordDef, new Field(_messageIdPrimaryKeyFieldDef, "1001")); var testRecord = new Record(_recordDef, new Field(_primaryKeyFieldDef, "1234"), new Field(_foreignKeyMessageIdFieldDef, "1001")); TestRun testRun = RunTest(testRecord, attachmentDataRecord); testRun.IsSuccess().Should().BeTrue(); }
public void ShouldReportIfKeyIsNotUnique() { AddmlRecordDefinition recordDefinition = new AddmlRecordDefinitionBuilder() .Build(); AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .WithRecordDefinition(recordDefinition) .IsPartOfPrimaryKey(true) .Build(); AddmlFieldDefinition fieldDefinition2 = new AddmlFieldDefinitionBuilder() .WithRecordDefinition(recordDefinition) .IsPartOfPrimaryKey(false) .Build(); FlatFile flatFile = new FlatFile(recordDefinition.AddmlFlatFileDefinition); ControlKey test = new ControlKey(); test.Run(flatFile); test.Run(new Arkade.Core.Addml.Record(recordDefinition, new List <Field> { new Field(fieldDefinition, "A"), new Field(fieldDefinition, "A"), new Field(fieldDefinition2, "B") })); test.Run(new Arkade.Core.Addml.Record(recordDefinition, new List <Field> { new Field(fieldDefinition, "A"), new Field(fieldDefinition, "B"), new Field(fieldDefinition2, "B") })); test.Run(new Arkade.Core.Addml.Record(recordDefinition, new List <Field> { new Field(fieldDefinition, "A"), new Field(fieldDefinition, "C"), new Field(fieldDefinition2, "B") })); test.Run(new Arkade.Core.Addml.Record(recordDefinition, new List <Field> { new Field(fieldDefinition, "A"), new Field(fieldDefinition, "B"), new Field(fieldDefinition2, "B") })); test.Run(new Arkade.Core.Addml.Record(recordDefinition, new List <Field> { new Field(fieldDefinition, "A"), new Field(fieldDefinition, "C"), new Field(fieldDefinition2, "C") })); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(recordDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Følgende primærnøkkelverdier er ikke unike: A,B A,C"); }
private void Test(TestRun testRun) { _stream.WriteLine(@" <div class=""test"">"); _stream.WriteLine(@" <h3>"); _stream.WriteLine(@" " + testRun.TestName); _stream.WriteLine(@" </h3>"); _stream.WriteLine(@""); _stream.WriteLine(@" <p class=""test-description"">"); _stream.WriteLine(@" " + testRun.TestDescription); _stream.WriteLine(@" </p>"); _stream.WriteLine(@""); /* * sb.AppendLine(@" <p class=""test-duration"">"); * sb.AppendLine(@" Tidsbruk: " + testRun.TestDuration + " millisekunder"); * sb.AppendLine(@" </p>"); * sb.AppendLine(@""); */ _stream.WriteLine(@" <h4>Testresultater</h4>"); if (testRun.IsSuccess() && (testRun.TestType == TestType.ContentControl || testRun.TestType == TestType.Structure)) { _stream.WriteLine("<p>Ingen avvik funnet.</p>"); } else { _stream.WriteLine(@" <table class=""table"">"); _stream.WriteLine(@" <thead>"); _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <th>Lokasjon</th>"); _stream.WriteLine(@" <th>Melding</th>"); _stream.WriteLine(@" </tr>"); _stream.WriteLine(@" </thead>"); _stream.WriteLine(@" <tbody>"); foreach (TestResult testResult in testRun.Results.Take(100)) // TODO only first 100 results are included due to problem loading report in browser { _stream.WriteLine(@" <tr>"); _stream.WriteLine(@" <td>"); _stream.WriteLine(@" " + testResult.Location); _stream.WriteLine(@" </td>"); _stream.WriteLine(@" <td>"); _stream.WriteLine(@" " + testResult.Message); _stream.WriteLine(@" </td>"); _stream.WriteLine(@" </tr>"); } _stream.WriteLine(@" </tbody>"); _stream.WriteLine(@" </table>"); } _stream.WriteLine(@" </div>"); }
public void ShouldReturnErrorWhenCombinedForeignKeysReferenceDoesNotExist() { var attachmentDataRecord = new Record(_attachmentRecordDef, new Field(_messageIdPrimaryKeyFieldDef, "556677"), new Field(_attachmentNumberPrimaryKeyFieldDef, "1")); var testRecord = new Record(_recordWithBothCombinedAndSingleForeignKeyDef, new Field(_primaryKeyFieldDef, "1234"), new Field(_foreignKeyMessageIdFieldDef, "1001"), new Field(_foreignKeyAttachmentNumberFieldDef, "1")); TestRun testRun = A_16_ControlForeignKeySingleTest.RunTest(attachmentDataRecord, testRecord); testRun.IsSuccess().Should().BeFalse(); }
public void ShouldReportIncorrectStringDataFormat() { AddmlFieldDefinition fieldDefinition1 = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType("fnr", null)) .Build(); AddmlFieldDefinition fieldDefinition2 = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType("org", null)) .Build(); AddmlFieldDefinition fieldDefinition3 = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType("knr", null)) .Build(); AddmlFieldDefinition fieldDefinition4 = new AddmlFieldDefinitionBuilder() .WithDataType(new StringDataType(null, null)) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition1.GetAddmlFlatFileDefinition()); ControlDataFormat test = new ControlDataFormat(); test.Run(flatFile); test.Run(new Field(fieldDefinition1, "")); test.Run(new Field(fieldDefinition1, "17080232930")); // not ok test.Run(new Field(fieldDefinition1, "17080232934")); // ok test.Run(new Field(fieldDefinition2, "")); test.Run(new Field(fieldDefinition2, "914994781")); // not ok test.Run(new Field(fieldDefinition2, "914994780")); // ok test.Run(new Field(fieldDefinition3, "")); test.Run(new Field(fieldDefinition3, "63450608211")); // not ok test.Run(new Field(fieldDefinition3, "63450608213")); // ok test.Run(new Field(fieldDefinition4, "")); test.Run(new Field(fieldDefinition4, "A")); test.Run(new Field(fieldDefinition4, "B")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(3); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition1.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig dataformat: '', '17080232930'"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinition2.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("Ugyldig dataformat: '', '914994781'"); testRun.Results[2].Location.ToString().Should().Be(fieldDefinition3.GetIndex().ToString()); testRun.Results[2].Message.Should().Be("Ugyldig dataformat: '', '63450608211'"); }
public void ShouldReturnErrorWhenSingleForeignKeyReferenceDoesNotExist() { var attachmentDataRecord1 = new Record(_attachmentRecordDef, new Field(_messageIdPrimaryKeyFieldDef, "556677")); var attachmentDataRecord2 = new Record(_attachmentRecordDef, new Field(_messageIdPrimaryKeyFieldDef, "1002")); var testRecord1 = new Record(_recordDef, new Field(_primaryKeyFieldDef, "1234"), new Field(_foreignKeyMessageIdFieldDef, "1001")); var testRecord2 = new Record(_recordDef, new Field(_primaryKeyFieldDef, "1235"), new Field(_foreignKeyMessageIdFieldDef, "1002")); TestRun testRun = RunTest(testRecord1, testRecord2, attachmentDataRecord1, attachmentDataRecord2); testRun.IsSuccess().Should().BeFalse(); }
public void ShouldFindMaxAndMinLengthRecord() { AddmlFlatFileDefinition flatFileDefinition = new AddmlFlatFileDefinitionBuilder() .WithFieldSeparator("BB") .WithRecordSeparator("A") .Build(); FlatFile flatFile = new FlatFile(flatFileDefinition); AddmlRecordDefinition recordDefinition = new AddmlRecordDefinitionBuilder() .WithAddmlFlatFileDefinition(flatFileDefinition) .Build(); AddmlFieldDefinition fieldDefinition = new AddmlFieldDefinitionBuilder() .WithRecordDefinition(recordDefinition) .Build(); List <Field> fields1 = new List <Field> { new Field(fieldDefinition, "1234567890"), new Field(fieldDefinition, "12345"), new Field(fieldDefinition, "1") }; Record record1 = new Record(recordDefinition, fields1); List <Field> fields2 = new List <Field> { new Field(fieldDefinition, "1"), new Field(fieldDefinition, ""), new Field(fieldDefinition, "3") }; Record record2 = new Record(recordDefinition, fields2); AnalyseFindExtremeRecords test = new AnalyseFindExtremeRecords(); test.Run(flatFile); test.Run(record1); test.Run(record2); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeTrue(); testRun.Results.Count.Should().Be(1); testRun.Results[0].Location.ToString().Should().Be(recordDefinition.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Lengste/korteste post: 20/6"); }
public void ShouldReportIncorrectIntegerDataFormat() { AddmlFieldDefinition fieldDefinition1 = new AddmlFieldDefinitionBuilder() .WithDataType(new IntegerDataType("n.nnn", null)) .Build(); AddmlFieldDefinition fieldDefinition2 = new AddmlFieldDefinitionBuilder() .WithDataType(new IntegerDataType("nnE+exp", null)) .Build(); AddmlFieldDefinition fieldDefinition3 = new AddmlFieldDefinitionBuilder() .WithDataType(new IntegerDataType(null, null)) .Build(); FlatFile flatFile = new FlatFile(fieldDefinition1.GetAddmlFlatFileDefinition()); ControlDataFormat test = new ControlDataFormat(); test.Run(flatFile); test.Run(new Field(fieldDefinition1, "1")); test.Run(new Field(fieldDefinition1, "1.100")); test.Run(new Field(fieldDefinition1, "1.1")); test.Run(new Field(fieldDefinition1, "1E+2")); test.Run(new Field(fieldDefinition1, "notanint1")); test.Run(new Field(fieldDefinition2, "1")); test.Run(new Field(fieldDefinition2, "1.100")); test.Run(new Field(fieldDefinition2, "1.1")); test.Run(new Field(fieldDefinition2, "1E+2")); test.Run(new Field(fieldDefinition2, "notanint1")); test.Run(new Field(fieldDefinition3, "1")); test.Run(new Field(fieldDefinition3, "1.100")); test.Run(new Field(fieldDefinition3, "1.1")); test.Run(new Field(fieldDefinition3, "1E+2")); test.Run(new Field(fieldDefinition3, "notanint1")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(3); testRun.Results[0].Location.ToString().Should().Be(fieldDefinition1.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("Ugyldig dataformat: '1.1', '1E+2', 'notanint1'"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinition2.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("Ugyldig dataformat: '1', '1.100', '1.1', 'notanint1'"); testRun.Results[2].Location.ToString().Should().Be(fieldDefinition3.GetIndex().ToString()); testRun.Results[2].Message.Should().Be("Ugyldig dataformat: '1.100', '1.1', '1E+2', 'notanint1'"); }
public void ShouldReportWhenFileInArchiveIsNotReferencedInAddml() { WorkingDirectory workingDirectory = new WorkingDirectory(null, new DirectoryInfo(TestUtil.TestDataDirectory + "noark3")); AddmlFlatFileDefinition flatFileDefinition1 = new AddmlFlatFileDefinitionBuilder() .WithFileInfo(new FileInfo(workingDirectory.Content().DirectoryInfo().FullName + Path.DirectorySeparatorChar + "nosuchfile.txt")) .WithFileName("nosuchfile.txt") .Build(); AddmlFlatFileDefinition flatFileDefinition2 = new AddmlFlatFileDefinitionBuilder() .WithFileInfo(new FileInfo(workingDirectory.Content().DirectoryInfo().FullName + Path.DirectorySeparatorChar + "ARKIV.DAT")) .WithFileName("ARKIV.DAT") .Build(); AddmlDefinition addmlDefinition = new AddmlDefinitionBuilder() .WithAddmlFlatFileDefinitions( new List <AddmlFlatFileDefinition> { flatFileDefinition1, flatFileDefinition2 }, new List <AddmlFlatFileDefinition> { flatFileDefinition1, }) .Build(); Archive archive = new Archive(ArchiveType.Fagsystem, Uuid.Random(), workingDirectory); AH_02_ControlExtraOrMissingFiles test = new AH_02_ControlExtraOrMissingFiles(addmlDefinition, archive); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeFalse(); testRun.Results.Count.Should().Be(4); string errorMessage = "Finnes i arkiv, men ikke i ADDML"; testRun.Results[0].Location.ToString().Should().Contain("DOK.DAT"); testRun.Results[0].Message.Should().Be(errorMessage); testRun.Results[1].Location.ToString().Should().Contain("noark_3_arkivuttrekk_med_prosesser.xml"); testRun.Results[1].Message.Should().Be(errorMessage); testRun.Results[2].Location.ToString().Should().Contain("SAK.DAT"); testRun.Results[2].Message.Should().Be(errorMessage); testRun.Results[3].Location.ToString().Should().Contain("nosuchfile.txt"); testRun.Results[3].Message.Should().Be("Finnes i ADDML, men ikke i arkiv"); }
public void ShouldReturnSuccessWhenCombinedForeignKeysAndSingleForeignKeyReferencesExist() { var attachmentDataRecord = new Record(_attachmentRecordDef, new Field(_messageIdPrimaryKeyFieldDef, "1001"), new Field(_attachmentNumberPrimaryKeyFieldDef, "1")); var documentRecord = new Record(_documentRecordDef, new Field(_documentPrimaryKeyFieldDef, "42")); var testRecord = new Record(_recordWithBothCombinedAndSingleForeignKeyDef, new Field(_primaryKeyFieldDef, "1234"), new Field(_foreignKeyMessageIdFieldDef, "1001"), new Field(_foreignKeyAttachmentNumberFieldDef, "1"), new Field(_foreignKeyDocumentIdFieldDef, "42")); TestRun testRun = A_16_ControlForeignKeySingleTest.RunTest(attachmentDataRecord, documentRecord, testRecord); testRun.IsSuccess().Should().BeTrue(); }
public void ShouldOnlyCreateFrequencyListOfCodeDefinitions() { AddmlFieldDefinition fieldDefinitionWithCodeList = new AddmlFieldDefinitionBuilder() .WithCodeList(new List <AddmlCode> { new AddmlCode("A", ""), new AddmlCode("B", ""), new AddmlCode("C", ""), }) .Build(); AddmlFieldDefinition fieldDefinitionWithoutCodeList = new AddmlFieldDefinitionBuilder() .WithRecordDefinition(fieldDefinitionWithCodeList.AddmlRecordDefinition) .Build(); FlatFile flatFile = new FlatFile(fieldDefinitionWithCodeList.GetAddmlFlatFileDefinition()); A_05_AnalyseAllFrequenceList test = new A_05_AnalyseAllFrequenceList(); test.Run(flatFile); test.Run(new Field(fieldDefinitionWithCodeList, "A")); test.Run(new Field(fieldDefinitionWithCodeList, "A")); test.Run(new Field(fieldDefinitionWithCodeList, "B")); test.Run(new Field(fieldDefinitionWithCodeList, "B")); test.Run(new Field(fieldDefinitionWithCodeList, "B")); test.Run(new Field(fieldDefinitionWithCodeList, "C")); test.Run(new Field(fieldDefinitionWithoutCodeList, "A")); test.Run(new Field(fieldDefinitionWithoutCodeList, "A")); test.Run(new Field(fieldDefinitionWithoutCodeList, "B")); test.Run(new Field(fieldDefinitionWithoutCodeList, "B")); test.Run(new Field(fieldDefinitionWithoutCodeList, "C")); test.EndOfFile(); TestRun testRun = test.GetTestRun(); testRun.IsSuccess().Should().BeTrue(); testRun.Results.Count.Should().Be(3); testRun.Results[0].Location.ToString().Should().Be(fieldDefinitionWithCodeList.GetIndex().ToString()); testRun.Results[0].Message.Should().Be("2 forekomster av A"); testRun.Results[1].Location.ToString().Should().Be(fieldDefinitionWithCodeList.GetIndex().ToString()); testRun.Results[1].Message.Should().Be("3 forekomster av B"); testRun.Results[2].Location.ToString().Should().Be(fieldDefinitionWithCodeList.GetIndex().ToString()); testRun.Results[2].Message.Should().Be("1 forekomster av C"); }