public void KeyReferenceCheck_Enabled_Test() { // Arrange var insertRecordService = new InsertRecordService(this.recordReference, this.attributeDecorator, enforceKeyReferenceCheck: true); var primaryKeySymbols = new List<ColumnSymbol> { new ColumnSymbol {ColumnName = "Key1", TableType = typeof (ManualKeyPrimaryTable), Value = "ABCD"}, new ColumnSymbol {ColumnName = "Key2", TableType = typeof (ManualKeyPrimaryTable), Value = 5}, }; var primaryKeyInsertRecordMock = new Mock<InsertRecord>(insertRecordService, new RecordReference<ManualKeyPrimaryTable>( Helpers.GetTypeGeneratorMock(new ManualKeyPrimaryTable()).Object, this.attributeDecorator), this.peers, this.attributeDecorator ); primaryKeyInsertRecordMock.Setup(m => m.GetPrimaryKeySymbols()).Returns(primaryKeySymbols); // Act. Assert. // Remember: Insert record service populated with the record reference as given in the test initialization above. Helpers.ExceptionTest( () => insertRecordService.GetForeignKeyColumns(new[] {primaryKeyInsertRecordMock.Object}), typeof (InserRecordServiceException), "Foreign key in record found without corresponding record/primary key assigned. Foreign type: Tests.TestModels.ForeignTable, Property name: ForeignKey"); }
public void GetForeignKeyColumns_NoForeignKeyPrimaryKeyMatch_Test() { // Arrange var insertRecordService = new InsertRecordService(this.recordReference, this.attributeDecorator, enforceKeyReferenceCheck: false); var primaryKeySymbols = new List<ColumnSymbol> { new ColumnSymbol {ColumnName = "Key1", TableType = typeof (ManualKeyPrimaryTable), Value = "ABCD"}, new ColumnSymbol {ColumnName = "Key2", TableType = typeof (ManualKeyPrimaryTable), Value = 5}, }; var primaryKeyInsertRecordMock = new Mock<InsertRecord>(insertRecordService, new RecordReference<ManualKeyPrimaryTable>( Helpers.GetTypeGeneratorMock(new ManualKeyPrimaryTable()).Object, this.attributeDecorator), this.peers, this.attributeDecorator ); primaryKeyInsertRecordMock.Setup(m => m.GetPrimaryKeySymbols()).Returns(primaryKeySymbols); // Act List<ExtendedColumnSymbol> fkColumns = // Remember: Insert record service populated with the record reference as given in the test initialization above. insertRecordService.GetForeignKeyColumns(new[] { primaryKeyInsertRecordMock.Object }).ToList(); // Assert Assert.AreEqual(1, fkColumns.Count); Assert.AreEqual("ForeignKey", fkColumns[0].ColumnName); Assert.AreEqual(Helper.GetDefaultValue(typeof (ForeignTable).GetProperty("ForeignKey").PropertyType), fkColumns[0].Value); }