public static void TargetType_PropertyGet_MatchesTypeArgument() { var testColumn = Mock.Of <IModelledColumn>(); var foreignKey = new Key.Foreign <TestTable1>(t => t.PK_TARGET, testColumn); Assert.That(foreignKey.TargetType, Is.EqualTo(typeof(TestTable1))); }
public static void KeySelector_WithSelectorUniqueKeyAndPropertyInfoNotSet_ThrowsInvalidOperationException() { var testColumn = Mock.Of <IModelledColumn>(); var foreignKey = new Key.Foreign <TestTable1>(t => t.UK_TARGET, testColumn); var instance = new TestTable1(); Assert.That(() => foreignKey.KeySelector.Invoke(instance), Throws.InvalidOperationException); }
public static void KeySelector_GivenWrongObject_ThrowsInvalidOperationException() { var testColumn = Mock.Of <IModelledColumn>(); var foreignKey = new Key.Foreign <TestTable1>(t => t.PK_TARGET, testColumn); var instance = new object(); Assert.That(() => foreignKey.KeySelector.Invoke(instance), Throws.InvalidOperationException); }
public static void KeySelector_WithSimpleFunctionToUniqueKey_ReturnsCorrectKey() { var testColumn = Mock.Of <IModelledColumn>(); var foreignKey = new Key.Foreign <TestTable1>(t => t.UK_TARGET, testColumn) { Property = typeof(TestTable1) .GetProperties() .Single(p => p.Name == nameof(TestTable1.FK_UK_SOURCE)) }; var instance = new TestTable1(); var targetKey = foreignKey.KeySelector.Invoke(instance); Assert.That(targetKey.KeyType, Is.EqualTo(DatabaseKeyType.Unique)); }