예제 #1
0
        public void TestPrimaryMapperMappingViaExpressionForBaseProperty()
        {
            // Derived 1

            // Setup
            PrimaryMapper.Add <PrimaryMapperTestDerivedClass1>(e => e.ColumnId);

            // Act
            var actual   = PrimaryMapper.Get <PrimaryMapperTestDerivedClass1>();
            var expected = "ColumnId";

            // Assert
            Assert.IsTrue(actual?.IsPrimary() == true);
            Assert.AreEqual(expected, actual?.GetMappedName());

            // Derived 2

            // Setup
            PrimaryMapper.Add <PrimaryMapperTestDerivedClass2>(e => e.ColumnId);

            // Act
            actual   = PrimaryMapper.Get <PrimaryMapperTestDerivedClass2>();
            expected = "ColumnId";

            // Assert
            Assert.IsTrue(actual?.IsPrimary() == true);
            Assert.AreEqual(expected, actual?.GetMappedName());
        }
예제 #2
0
        private static void Setup()
        {
            // MappedCompleteTable
            ClassMapper.Add <MappedCompleteTable>("[dbo].[COMPLETETABLE]", true);
            PrimaryMapper.Add <MappedCompleteTable>(e => e.SessionIdMapped, true);
            PropertyMapper.Add <MappedCompleteTable>(e => e.SessionIdMapped, "SESSIONID", true);
            PropertyMapper.Add <MappedCompleteTable>(e => e.ColumnBigIntMapped, "COLUMNBIGINT", true);
            PropertyMapper.Add <MappedCompleteTable>(e => e.ColumnBitMapped, "COLUMNBIT", true);
            PropertyMapper.Add <MappedCompleteTable>(e => e.ColumnIntMapped, "COLUMNINT", true);
            PropertyMapper.Add <MappedCompleteTable>(e => e.ColumnDateTimeMapped, "COLUMNDATETIME", true);
            PropertyMapper.Add <MappedCompleteTable>(e => e.ColumnDateTime2Mapped, "COLUMNDATETIME2", true);
            PropertyMapper.Add <MappedCompleteTable>(e => e.ColumnNVarCharMapped, "COLUMNNVARCHAR", true);

            // MappedCompleteTable
            ClassMapper.Add <MappedIdentityTable>("[sc].[IDENTITYTABLE]", true);
            PrimaryMapper.Add <MappedIdentityTable>(e => e.IdMapped, true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.IdMapped, "ID", true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.RowGuidMapped, "ROWGUID", true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.ColumnBitMapped, "COLUMNBIT", true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.ColumnIntMapped, "COLUMNINT", true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.ColumnDateTimeMapped, "COLUMNDATETIME", true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.ColumnDateTime2Mapped, "COLUMNDATETIME2", true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.ColumnFloatMapped, "COLUMNFLOAT", true);
            PropertyMapper.Add <MappedIdentityTable>(e => e.ColumnNVarCharMapped, "COLUMNNVARCHAR", true);

            // MappedCompleteTableForKey
            ClassMapper.Add <MappedCompleteTableForKey>("[dbo].[COMPLETETABLE]", true);
            PropertyMapper.Add <MappedCompleteTableForKey>(e => e.IdMapped, "SESSIONID", true);
        }
예제 #3
0
        public void TestClassMapPrimaryMappingOverride()
        {
            // Setup
            PrimaryMapper.Add <ClassMapperTestClass>(e => e.RowId, true);

            // Act
            var actual   = PrimaryCache.Get <ClassMapperTestClass>();
            var expected = "RowId";

            // Assert
            Assert.AreEqual(expected, actual.GetMappedName());
        }
예제 #4
0
        public void TestPrimaryMapperMappingViaExpression()
        {
            // Setup
            PrimaryMapper.Add <PrimaryMapperTestClass>(e => e.ColumnInt);

            // Act
            var actual   = PrimaryMapper.Get <PrimaryMapperTestClass>();
            var expected = "ColumnInt";

            // Assert
            Assert.IsTrue(actual?.IsPrimary() == true);
            Assert.AreEqual(expected, actual?.GetMappedName());
        }
예제 #5
0
        public void TestPrimaryMapperMappingViaFieldOverride()
        {
            // Setup
            PrimaryMapper.Add <PrimaryMapperTestClass>(new Field("ColumnInt"));
            PrimaryMapper.Add <PrimaryMapperTestClass>(new Field("ColumnString"), true);

            // Act
            var actual   = PrimaryMapper.Get <PrimaryMapperTestClass>();
            var expected = "ColumnString";

            // Assert
            Assert.IsTrue(actual?.IsPrimary() == true);
            Assert.AreEqual(expected, actual?.GetMappedName());
        }
예제 #6
0
        /// <summary>
        /// Resolves the primary <see cref="ClassProperty"/> of the data entity type.
        /// </summary>
        /// <param name="entityType">The type of the data entity.</param>
        /// <returns>The instance of the primary <see cref="ClassProperty"/> object.</returns>
        public ClassProperty Resolve(Type entityType)
        {
            var properties = PropertyCache.Get(entityType);

            // Check for the properties
            if (properties == null)
            {
                return(null);
            }

            // Get the first entry with Primary attribute
            var property = properties
                           .FirstOrDefault(p => p.GetPrimaryAttribute() != null);

            // Get from the implicit mapping
            if (property == null)
            {
                property = PrimaryMapper.Get(entityType);
            }

            // Id Property
            if (property == null)
            {
                property = properties
                           .FirstOrDefault(p =>
                                           string.Equals(p.PropertyInfo.Name, "id", StringComparison.OrdinalIgnoreCase));
            }

            // Type.Name + Id
            if (property == null)
            {
                property = properties
                           .FirstOrDefault(p =>
                                           string.Equals(p.PropertyInfo.Name, string.Concat(p.GetDeclaringType().Name, "id"), StringComparison.OrdinalIgnoreCase));
            }

            // Mapping.Name + Id
            if (property == null)
            {
                property = properties
                           .FirstOrDefault(p =>
                                           string.Equals(p.PropertyInfo.Name, string.Concat(ClassMappedNameCache.Get(p.GetDeclaringType()), "id"), StringComparison.OrdinalIgnoreCase));
            }

            // Return the instance
            return(property);
        }
예제 #7
0
        public void Cleanup()
        {
            ClassMapper.Clear();
            PropertyMapper.Clear();
            PrimaryMapper.Clear();
            IdentityMapper.Clear();
            TypeMapper.Clear();
            //PropertyHandlerMapper.Clear();
            PropertyValueAttributeMapper.Clear();

            ClassMappedNameCache.Flush();
            PropertyCache.Flush();
            PrimaryCache.Flush();
            IdentityCache.Flush();
            TypeMapCache.Flush();
            //PropertyHandlerMapper.Clear();
            PropertyValueAttributeCache.Flush();
        }
예제 #8
0
        public void TestPrimaryMapperMappingViaFieldWithMapAttribute()
        {
            // Setup
            PrimaryMapper.Add <PrimaryMapperTestWithAttributeClass>(new Field("ColumnInt"));

            // Act
            var actual   = PrimaryMapper.Get <PrimaryMapperTestWithAttributeClass>();
            var expected = "ColumnInt";

            // Assert
            Assert.IsTrue(actual?.IsPrimary() == true);
            Assert.AreEqual(expected, actual?.GetMappedName());

            // Act
            actual   = PrimaryCache.Get <PrimaryMapperTestWithAttributeClass>();
            expected = "ColumnString";

            // Assert
            Assert.IsTrue(actual?.IsPrimary() == true);
            Assert.AreEqual(expected, actual?.GetMappedName());
        }
예제 #9
0
 public void ThrowExceptionOnPrimaryMapperViaFieldThatIsIsMissing()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(new Field("Whatever"));
 }
예제 #10
0
 public void ThrowExceptionOnPrimaryMapperViaPropertyNameThatIsMissing()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>("Whatever");
 }
예제 #11
0
 public void ThrowExceptionOnPrimaryMapperViaFieldThatIsEmptySpaces()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(field: new Field("  "));
 }
예제 #12
0
 public void ThrowExceptionOnPrimaryMapperViaPropertyNameThatIsEmptySpaces()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(propertyName: "  ");
 }
예제 #13
0
 public void ThrowExceptionOnPrimaryMapperViaExpressionThatIsNull()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(expression: null);
 }
예제 #14
0
 public void Cleanup()
 {
     PrimaryCache.Flush();
     PrimaryMapper.Clear();
 }
예제 #15
0
 public void ThrowExceptionOnPrimaryMapperViaExpressionThatIsAlreadyExisting()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(e => e.ColumnInt);
     PrimaryMapper.Add <PrimaryMapperTestClass>(e => e.ColumnString);
 }
예제 #16
0
 public void ThrowExceptionOnPrimaryMapperViaFieldThatIsAlreadyExisting()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(new Field("ColumnInt"));
     PrimaryMapper.Add <PrimaryMapperTestClass>(new Field("ColumnString"));
 }
예제 #17
0
 public void ThrowExceptionOnPrimaryMapperViaPropertyNameThatIsAlreadyExisting()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>("ColumnInt");
     PrimaryMapper.Add <PrimaryMapperTestClass>("ColumnString");
 }
예제 #18
0
 public void ThrowExceptionOnClassMapPrimaryMappingThatIsAlreadyExisting()
 {
     // Setup
     PrimaryMapper.Add <ClassMapperTestClass>(e => e.RowId);
 }
예제 #19
0
 public void ThrowExceptionOnPrimaryMapperViaPropertyNameThatIsNull()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(propertyName: null);
 }
예제 #20
0
 public void ThrowExceptionOnPrimaryMapperViaFieldThatIsNull()
 {
     // Setup
     PrimaryMapper.Add <PrimaryMapperTestClass>(field: null);
 }