Example #1
0
        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());
        }
Example #2
0
        public void TestClassMapIdentityMappingWithMapAttribute()
        {
            // Act
            var actual   = IdentityMapper.Get <ClassMapperTestWithAttributesClass>();
            var expected = "Id";

            // Assert
            Assert.AreEqual(expected, actual.GetMappedName());
        }
Example #3
0
        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());
        }
Example #4
0
        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());
        }
Example #5
0
        /// <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);
        }
Example #6
0
        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());
        }