public void TestIdentityMapperMappingViaExpressionForBaseProperty() { // Derived 1 // Setup IdentityMapper.Add <IdentityMapperTestDerivedClass1>(e => e.ColumnId); // Act var actual = IdentityMapper.Get <IdentityMapperTestDerivedClass1>(); var expected = "ColumnId"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); // Derived 2 // Setup IdentityMapper.Add <IdentityMapperTestDerivedClass2>(e => e.ColumnId); // Act actual = IdentityMapper.Get <IdentityMapperTestDerivedClass2>(); expected = "ColumnId"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }
public void TestClassMapIdentityMappingWithMapAttribute() { // Act var actual = IdentityMapper.Get <ClassMapperTestWithAttributesClass>(); var expected = "Id"; // Assert Assert.AreEqual(expected, actual.GetMappedName()); }
public void TestIdentityMapperMappingViaExpression() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(e => e.ColumnInt); // Act var actual = IdentityMapper.Get <IdentityMapperTestClass>(); var expected = "ColumnInt"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }
public void TestIdentityMapperMappingViaFieldOverride() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnInt")); IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnString"), true); // Act var actual = IdentityMapper.Get <IdentityMapperTestClass>(); var expected = "ColumnString"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }
/// <summary> /// Resolves the identity <see cref="ClassProperty"/> of the data entity type. /// </summary> /// <param name="entityType">The type of the data entity.</param> /// <returns>The instance of the identity <see cref="ClassProperty"/> object.</returns> public ClassProperty Resolve(Type entityType) { var properties = PropertyCache.Get(entityType); // Get the first entry with Identity attribute var property = properties? .FirstOrDefault(p => p.GetIdentityAttribute() != null); // Get from the implicit mapping if (property == null) { property = IdentityMapper.Get(entityType); } // Return the instance return(property); }
public void TestIdentityMapperMappingViaFieldWithMapAttribute() { // Setup IdentityMapper.Add <IdentityMapperTestWithAttributeClass>(new Field("ColumnInt")); // Act var actual = IdentityMapper.Get <IdentityMapperTestWithAttributeClass>(); var expected = "ColumnInt"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); // Act actual = IdentityCache.Get <IdentityMapperTestWithAttributeClass>(); expected = "ColumnString"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }