Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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 static TestRun RunTest(params Record[] records)
        {
            var collectPrimarykeyProcess = new CollectPrimaryKey();
            var controlForeignKeyProcess = new ControlForeignKey();

            foreach (var record in records)
            {
                collectPrimarykeyProcess.Run(record);
                controlForeignKeyProcess.Run(record);
            }

            // need to do transfering of primary keys manually in the test environment
            controlForeignKeyProcess.CollectedPrimaryKeys = collectPrimarykeyProcess._primaryKeys;

            return(controlForeignKeyProcess.GetTestRun());
        }