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 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 ShouldAddCollectPrimaryKeyToRecordDefinitionsContainingReferencedPrimaryKey() { AddmlFlatFileDefinition personFile = new AddmlFlatFileDefinitionBuilder().WithName("personFile").Build(); AddmlRecordDefinition personFileRecordDef = new AddmlRecordDefinitionBuilder().WithAddmlFlatFileDefinition(personFile).Build(); AddmlFieldDefinition personPrimaryKey = new AddmlFieldDefinitionBuilder().WithRecordDefinition(personFileRecordDef) .WithName("personPrimaryKey") .IsPartOfPrimaryKey(true).Build(); AddmlFlatFileDefinition addressFile = new AddmlFlatFileDefinitionBuilder().WithName("addressFile").Build(); var addmlForeignKey = new AddmlForeignKey("testkey"); AddmlRecordDefinition addressFileRecordDef = new AddmlRecordDefinitionBuilder() .WithAddmlFlatFileDefinition(addressFile) .WithRecordProcess(A_16_ControlForeignKey.Name) .WithForeignKey(addmlForeignKey) .Build(); new AddmlFieldDefinitionBuilder().WithRecordDefinition(addressFileRecordDef).WithName("addressPrimaryKey").IsPartOfPrimaryKey(true).Build(); AddmlFieldDefinition addressForeignKey = new AddmlFieldDefinitionBuilder().WithRecordDefinition(addressFileRecordDef) .WithName("addressForeignKey") // .WithForeignKey(personPrimaryKey) .Build(); addmlForeignKey.ForeignKeys.Add(addressForeignKey); addmlForeignKey.ForeignKeyReferenceIndexes.Add(personPrimaryKey.GetIndex()); addmlForeignKey.ForeignKeyReferenceFields.Add(personPrimaryKey); AddmlFlatFileDefinition unrelatedFile = new AddmlFlatFileDefinitionBuilder().WithName("unrelatedFile").Build(); AddmlRecordDefinition unrelatedFileRecordDef = new AddmlRecordDefinitionBuilder().WithAddmlFlatFileDefinition(unrelatedFile).Build(); AddmlFieldDefinition unrelatedFilePrimaryKey = new AddmlFieldDefinitionBuilder().WithRecordDefinition(unrelatedFileRecordDef) .WithName("unrelatedFilePrimaryKey") .IsPartOfPrimaryKey(true).Build(); AddmlDefinition addmlDefinition = new AddmlDefinition( new List <AddmlFlatFileDefinition>() { personFile, addressFile, unrelatedFile }, new List <AddmlFlatFileDefinition>() { personFile, addressFile }); Dictionary <IAddmlIndex, List <string> > recordProcesses = addmlDefinition.GetRecordProcessesGroupedByRecord(); DebugPrintListOfProcesses(recordProcesses); recordProcesses[personFileRecordDef.GetIndex()].Contains(AI_01_CollectPrimaryKey.Name).Should().BeTrue(); recordProcesses[addressFileRecordDef.GetIndex()].Contains(A_16_ControlForeignKey.Name).Should().BeTrue(); recordProcesses[unrelatedFileRecordDef.GetIndex()].Should().BeEmpty(); }
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"); }
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 ShouldNotAddCollectPrimaryKeyProcessWhenControlForeignKeyIsNotDefinedInAnyRecordDefinition() { AddmlFlatFileDefinition personFile = new AddmlFlatFileDefinitionBuilder().WithName("personFile").Build(); AddmlRecordDefinition personFileRecordDef = new AddmlRecordDefinitionBuilder().WithAddmlFlatFileDefinition(personFile).Build(); AddmlFieldDefinition personPrimaryKey = new AddmlFieldDefinitionBuilder().WithRecordDefinition(personFileRecordDef) .WithName("personPrimaryKey") .IsPartOfPrimaryKey(true).Build(); AddmlFlatFileDefinition addressFile = new AddmlFlatFileDefinitionBuilder().WithName("addressFile").Build(); var addmlForeignKey = new AddmlForeignKey("testkey"); AddmlRecordDefinition addressFileRecordDef = new AddmlRecordDefinitionBuilder() .WithAddmlFlatFileDefinition(addressFile) .WithForeignKey(addmlForeignKey) .Build(); new AddmlFieldDefinitionBuilder().WithRecordDefinition(addressFileRecordDef).WithName("addressPrimaryKey").IsPartOfPrimaryKey(true).Build(); var addressField = new AddmlFieldDefinitionBuilder().WithRecordDefinition(addressFileRecordDef) .WithName("addressForeignKey") .Build(); addmlForeignKey.ForeignKeys.Add(addressField); addmlForeignKey.ForeignKeyReferenceIndexes.Add(personPrimaryKey.GetIndex()); addmlForeignKey.ForeignKeyReferenceFields.Add(personPrimaryKey); AddmlDefinition addmlDefinition = new AddmlDefinition( new List <AddmlFlatFileDefinition>() { personFile, addressFile }, new List <AddmlFlatFileDefinition>() { personFile, addressFile }); Dictionary <IAddmlIndex, List <string> > recordProcesses = addmlDefinition.GetRecordProcessesGroupedByRecord(); DebugPrintListOfProcesses(recordProcesses); recordProcesses[personFileRecordDef.GetIndex()].Should().BeEmpty(); recordProcesses[addressFileRecordDef.GetIndex()].Should().BeEmpty(); }