Example #1
0
        public void MultipleRecordDefinitionsPerflatFileShouldBeSupported()
        {
            FlatFile flatFile = GetDokDat();

            FixedFileFormatReader reader = new FixedFileFormatReader(flatFile);
            int numberOfRecords          = 0;

            while (reader.MoveNext())
            {
                Record record = reader.Current;
                record.Should().NotBeNull();
                record.Fields[0].GetName().Should().Be("Posttype");
                record.Fields[0].Value.Should().BeOneOf("B", "N");

                string posttype = record.Fields[0].Value;
                if (posttype == "B")
                {
                    VerifyBrev(record);
                }
                else if (posttype == "N")
                {
                    VerifyNotat(record);
                }

                numberOfRecords++;
            }

            numberOfRecords.Should().Be(195);

            reader.MoveNext().Should().BeFalse();
        }
Example #2
0
        private void VerifyBrev(Record record)
        {
            record.Fields.Count.Should().Be(24);

            record.Fields[0].GetName().Should().Be("Posttype");
            record.Fields[0].Value.Should().Be("B");
            record.Fields[1].GetName().Should().Be("Grad");
            record.Fields[1].Value.Should().Be("   ");
            record.Fields[2].GetName().Should().Be("Saksnr");
            record.Fields[2].Value.Should().MatchRegex("199./000..");
            record.Fields[3].GetName().Should().Be("Doknr");
            record.Fields[3].Value.Should().MatchRegex("0..");
            record.Fields[4].GetName().Should().Be("Journaldato");
            record.Fields[4].Value.Should().MatchRegex("199.....");
            record.Fields[5].GetName().Should().Be("Doktype");
            record.Fields[5].Value.Should().BeOneOf("I", "U");
            record.Fields[6].GetName().Should().Be("Uoff");
            record.Fields[6].Value.Should().Be("                ");
            record.Fields[7].GetName().Should().Be("Bdato");
            record.Fields[7].Value.Should().MatchRegex("199.....");
            record.Fields[8].GetName().Should().Be("Vedlegg");
            record.Fields[8].Value.Should().Be("  ");
            record.Fields[9].GetName().Should().Be("Avgradering");
            record.Fields[9].Value.Should().Be("   ");
            record.Fields[10].GetName().Should().Be("Saksbeh_for_dok_1_delfelt");
            record.Fields[10].Value.Should().Be("PA  ");
            record.Fields[11].GetName().Should().Be("Saksbeh_for_dok_2_delfelt");
            record.Fields[11].Value.Should().MatchRegex("... ");
            record.Fields[12].GetName().Should().Be("Blankt_felt_1");
            record.Fields[12].Value.Should().MatchRegex("       ");
            record.Fields[13].GetName().Should().Be("Avs_mot_forkortelse");
            record.Fields[13].Value.Should().BeOneOf("          ", "GRPO      ");
            record.Fields[14].GetName().Should().Be("Avs_mot");
            record.Fields[14].Value.Length.Should().Be(70);
            record.Fields[15].GetName().Should().Be("Dokumentbeskrivelse");
            record.Fields[15].Value.Length.Should().Be(140);
            record.Fields[16].GetName().Should().Be("Tillegg");
            record.Fields[16].Value.Length.Should().Be(210);
            record.Fields[17].GetName().Should().Be("Avskrivning_doknr");
            record.Fields[17].Value.Length.Should().Be(3);
            record.Fields[18].GetName().Should().Be("Avskrivning_dato");
            record.Fields[18].Value.Length.Should().Be(8);
            record.Fields[19].GetName().Should().Be("Avskrivning_maate");
            record.Fields[19].Value.Should().BeOneOf("    ", "BU  ", "TA  ");
            record.Fields[20].GetName().Should().Be("Loepenr");
            record.Fields[20].Value.Should().MatchRegex("0000../199.");
            record.Fields[21].GetName().Should().Be("Journalenhet");
            record.Fields[21].Value.Should().Be("GO ");
            record.Fields[22].GetName().Should().Be("Blankt_felt_2");
            record.Fields[22].Value.Should().Be("           ");
            record.Fields[23].GetName().Should().Be("Filreferanse");
            record.Fields[23].Value.Should().Be("                                        ");
        }
Example #3
0
        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();
        }
Example #4
0
        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 = ControlForeignKeySingleTest.RunTest(attachmentDataRecord, testRecord);

            testRun.IsSuccess().Should().BeFalse();
        }
Example #5
0
        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();
        }
Example #6
0
        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");
        }
Example #7
0
        public void RecordValueShouldContainFieldSeparator()
        {
            AddmlRecordDefinition recordDefinition = new AddmlRecordDefinitionBuilder()
                                                     .WithAddmlFlatFileDefinition(new AddmlFlatFileDefinitionBuilder()
                                                                                  .WithFieldSeparator("AA")
                                                                                  .Build())
                                                     .Build();
            List <Field> fields = new List <Field>
            {
                new Field(null, "1"),
                new Field(null, "2"),
                new Field(null, "3")
            };

            Record record = new Record(recordDefinition, fields);

            record.Value.Should().Be("1AA2AA3");
        }
Example #8
0
        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 = ControlForeignKeySingleTest.RunTest(attachmentDataRecord, documentRecord, testRecord);

            testRun.IsSuccess().Should().BeTrue();
        }
        public void ShouldCountRecordDefinitionOccurences()
        {
            var process = new AnalyseCountRecordDefinitionOccurences();
            AddmlFlatFileDefinition addmlFlatFileDefinition = new AddmlFlatFileDefinitionBuilder().Build();
            FlatFile flatFile = new FlatFile(addmlFlatFileDefinition);

            var addmlRecordDefinition1 = new AddmlRecordDefinitionBuilder()
                                         .WithAddmlFlatFileDefinition(addmlFlatFileDefinition)
                                         .WithName("recordDef1")
                                         .Build();
            var addmlRecordDefinition2 = new AddmlRecordDefinitionBuilder()
                                         .WithAddmlFlatFileDefinition(addmlFlatFileDefinition)
                                         .WithName("recordDef2")
                                         .Build();

            Record record1 = new Record(addmlRecordDefinition1, new List <Field>());
            Record record2 = new Record(addmlRecordDefinition1, new List <Field>());
            Record record3 = new Record(addmlRecordDefinition2, new List <Field>());

            process.Run(flatFile);
            process.Run(record1);
            process.Run(record2);
            process.Run(record3);
            process.EndOfFile();
            TestRun testRun = process.GetTestRun();

            testRun.Results.Count.Should().Be(2);

            TestResult resultDef1 = testRun.Results.FirstOrDefault(r => r.Location.ToString().Contains("recordDef1"));
            TestResult resultDef2 = testRun.Results.FirstOrDefault(r => r.Location.ToString().Contains("recordDef2"));

            resultDef1.Should().NotBeNull();
            resultDef2.Should().NotBeNull();

            resultDef1?.Message.Should().Contain("2");
            resultDef2?.Message.Should().Contain("1");
        }
Example #10
0
        private static void VerifyNotat(Record record)
        {
            record.Fields.Count.Should().Be(29);

            record.Fields[0].GetName().Should().Be("Posttype");
            record.Fields[0].Value.Should().Be("N");
            record.Fields[1].GetName().Should().Be("Grad");
            record.Fields[1].Value.Should().Be("   ");
            record.Fields[2].GetName().Should().Be("Saksnr");
            record.Fields[2].Value.Should().MatchRegex("199./000..");
            record.Fields[3].GetName().Should().Be("Doknr");
            record.Fields[3].Value.Should().MatchRegex("0..");
            record.Fields[4].GetName().Should().Be("Journaldato");
            record.Fields[4].Value.Should().MatchRegex("199.....");
            record.Fields[5].GetName().Should().Be("Doktype");
            record.Fields[5].Value.Should().Be("N");
            record.Fields[6].GetName().Should().Be("Uoff");
            record.Fields[6].Value.Should().Be("                ");
            record.Fields[7].GetName().Should().Be("Bdato");
            record.Fields[7].Value.Should().MatchRegex("199.....");
            record.Fields[8].GetName().Should().Be("Vedlegg");
            record.Fields[8].Value.Should().Be("  ");
            record.Fields[9].GetName().Should().Be("Avgradering");
            record.Fields[9].Value.Should().Be("   ");
            record.Fields[10].GetName().Should().Be("Saksbeh_for_dok_1_delfelt");
            record.Fields[10].Value.Should().Be("PA  ");
            record.Fields[11].GetName().Should().Be("Saksbeh_for_dok_2_delfelt");
            record.Fields[11].Value.Should().MatchRegex("... ");
            record.Fields[12].GetName().Should().Be("Blankt_felt_3");
            record.Fields[12].Value.Should().MatchRegex("       ");
            record.Fields[13].GetName().Should().Be("Internt_dok_fra");
            record.Fields[13].Value.Should()
            .BeOneOf("Bjørn Kragevik                ", "Stine Olsen                   ");
            record.Fields[14].GetName().Should().Be("Blankt_felt_4");
            record.Fields[14].Value.Should().Be("        ");
            record.Fields[15].GetName().Should().Be("Internt_dok_til");
            record.Fields[15].Value.Should().Be("GRPO                         ");
            record.Fields[16].GetName().Should().Be("Journalenhet_1");
            record.Fields[16].Value.Should().Be("   ");
            record.Fields[17].GetName().Should().Be("Behandler_1_delfelt");
            record.Fields[17].Value.Should().Be("GO  ");
            record.Fields[18].GetName().Should().Be("Behandler_2_delfelt");
            record.Fields[18].Value.Should().Be("ABC ");
            record.Fields[19].GetName().Should().Be("Blankt_felt_5");
            record.Fields[19].Value.Should().Be("  ");
            record.Fields[20].GetName().Should().Be("Dokumentbeskrivelse");
            record.Fields[20].Value.Length.Should().Be(140);
            record.Fields[21].GetName().Should().Be("Tillegg");
            record.Fields[21].Value.Length.Should().Be(210);
            record.Fields[22].GetName().Should().Be("Blankt_felt_6");
            record.Fields[22].Value.Should().Be("   ");
            record.Fields[23].GetName().Should().Be("Avskrivning_dato");
            record.Fields[23].Value.Should().MatchRegex("        ");
            record.Fields[24].GetName().Should().Be("Avskrivning_maate");
            record.Fields[24].Value.Should().BeOneOf("    ", "BU  ", "TA  ");
            record.Fields[25].GetName().Should().Be("Loepenr");
            record.Fields[25].Value.Should().MatchRegex("0000../199.");
            record.Fields[26].GetName().Should().Be("Journalenhet_2");
            record.Fields[26].Value.Should().Be("GO ");
            record.Fields[27].GetName().Should().Be("Blankt_felt_7");
            record.Fields[27].Value.Should().Be("           ");
            record.Fields[28].GetName().Should().Be("Filreferanse");
            record.Fields[28].Value.Should().Be("                                        ");
        }
 private void RecordShouldMatch(Record record, int fieldIndex, string name, string value)
 {
     record.Fields[fieldIndex].GetName().Should().Be(name);
     record.Fields[fieldIndex].Value.Should().Be(value);
 }
Example #12
0
 public void RunProcesses(FlatFile file, Record record)
 {
     _fileProcessRunner.RunProcesses(file, record);
     _recordProcessRunner.RunProcesses(record);
 }