public void PropertyWithoutColumnAttributeIsIgnored() { var mappingConvention = new AttributeMappingConvention(); var objectInfo = mappingConvention.CreateObjectInfo(typeof(AssignedCustomer)); Assert.False(objectInfo.TableInfo.Columns.Any(c => c.ColumnName == "UnMappedProperty")); }
public void TableInfoColumnsAreMappedCorrectlyForDbGeneratedIdentifier() { var mappingConvention = new AttributeMappingConvention(); var objectInfo = mappingConvention.CreateObjectInfo(typeof(DbGeneratedCustomer)); var columns = objectInfo.TableInfo.Columns.ToArray(); Assert.Equal(6, columns.Length); Assert.Equal("Created", columns[0].ColumnName); Assert.True(columns[0].AllowInsert); Assert.False(columns[0].AllowUpdate); Assert.Equal(DbType.DateTime, columns[0].DbType); Assert.False(columns[0].IsIdentifier); Assert.Equal(typeof(DbGeneratedCustomer).GetProperty("Created"), columns[0].PropertyInfo); Assert.Null(columns[0].SequenceName); Assert.Equal("DoB", columns[1].ColumnName); Assert.True(columns[1].AllowInsert); Assert.True(columns[1].AllowUpdate); Assert.Equal(DbType.DateTime, columns[1].DbType); Assert.False(columns[1].IsIdentifier); Assert.Equal(typeof(DbGeneratedCustomer).GetProperty("DateOfBirth"), columns[1].PropertyInfo); Assert.Null(columns[1].SequenceName); Assert.Equal("CustomerId", columns[2].ColumnName); Assert.False(columns[2].AllowInsert); Assert.False(columns[2].AllowUpdate); Assert.Equal(DbType.Int32, columns[2].DbType); Assert.True(columns[2].IsIdentifier); Assert.Equal(typeof(DbGeneratedCustomer).GetProperty("Id"), columns[2].PropertyInfo); Assert.Null(columns[2].SequenceName); Assert.Equal("Name", columns[3].ColumnName); Assert.True(columns[3].AllowInsert); Assert.True(columns[3].AllowUpdate); Assert.Equal(DbType.String, columns[3].DbType); Assert.False(columns[3].IsIdentifier); Assert.Equal(typeof(DbGeneratedCustomer).GetProperty("Name"), columns[3].PropertyInfo); Assert.Null(columns[3].SequenceName); Assert.Equal("StatusId", columns[4].ColumnName); Assert.True(columns[4].AllowInsert); Assert.True(columns[4].AllowUpdate); Assert.Equal(DbType.Int32, columns[4].DbType); Assert.False(columns[4].IsIdentifier); Assert.Equal(typeof(DbGeneratedCustomer).GetProperty("Status"), columns[4].PropertyInfo); Assert.Null(columns[4].SequenceName); Assert.Equal("Updated", columns[5].ColumnName); Assert.False(columns[5].AllowInsert); Assert.True(columns[5].AllowUpdate); Assert.Equal(DbType.DateTime, columns[5].DbType); Assert.False(columns[5].IsIdentifier); Assert.Equal(typeof(DbGeneratedCustomer).GetProperty("Updated"), columns[5].PropertyInfo); Assert.Null(columns[5].SequenceName); }
public void CreateObjectInfoThrowsArgumentNullExceptionForNullType() { var mappingConvention = new AttributeMappingConvention(); var exception = Assert.Throws <ArgumentNullException>( () => mappingConvention.CreateObjectInfo(null)); Assert.Equal("forType", exception.ParamName); }
public void AMicroLiteExceptionIsThrown() { var mappingConvention = new AttributeMappingConvention(); var exception = Assert.Throws <MappingException>( () => mappingConvention.CreateObjectInfo(typeof(CustomerWithNoTableAttribute))); Assert.Equal(ExceptionMessages.AttributeMappingConvention_NoTableAttribute.FormatWith(typeof(CustomerWithNoTableAttribute).FullName), exception.Message); }
public void TableInfoColumnsAreMappedCorrectlyForAssignedIdentifier() { var mappingConvention = new AttributeMappingConvention(); var objectInfo = mappingConvention.CreateObjectInfo(typeof(AssignedCustomer)); var columns = objectInfo.TableInfo.Columns.ToArray(); Assert.Equal(6, columns.Length); Assert.Equal("Created", columns[0].ColumnName); Assert.True(columns[0].AllowInsert); Assert.False(columns[0].AllowUpdate); Assert.Equal(DbType.DateTime2, columns[0].DbType); Assert.False(columns[0].IsIdentifier); Assert.Equal(typeof(AssignedCustomer).GetProperty("Created"), columns[0].PropertyInfo); Assert.Null(columns[0].SequenceName); Assert.Equal("DoB", columns[1].ColumnName); Assert.True(columns[1].AllowInsert); Assert.True(columns[1].AllowUpdate); Assert.Equal(DbType.DateTime2, columns[1].DbType); Assert.False(columns[1].IsIdentifier); Assert.Equal(typeof(AssignedCustomer).GetProperty("DateOfBirth"), columns[1].PropertyInfo); Assert.Null(columns[1].SequenceName); Assert.Equal("CustomerId", columns[2].ColumnName); Assert.True(columns[2].AllowInsert); Assert.False(columns[2].AllowUpdate); Assert.Equal(DbType.Int32, columns[2].DbType); Assert.True(columns[2].IsIdentifier); Assert.Equal(typeof(AssignedCustomer).GetProperty("Id"), columns[2].PropertyInfo); Assert.Null(columns[2].SequenceName); Assert.Equal("Name", columns[3].ColumnName); Assert.True(columns[3].AllowInsert); Assert.True(columns[3].AllowUpdate); Assert.Equal(DbType.String, columns[3].DbType); Assert.False(columns[3].IsIdentifier); Assert.Equal(typeof(AssignedCustomer).GetProperty("Name"), columns[3].PropertyInfo); Assert.Null(columns[3].SequenceName); Assert.Equal("StatusId", columns[4].ColumnName); Assert.True(columns[4].AllowInsert); Assert.True(columns[4].AllowUpdate); Assert.Equal(DbType.Int32, columns[4].DbType); Assert.False(columns[4].IsIdentifier); Assert.Equal(typeof(AssignedCustomer).GetProperty("Status"), columns[4].PropertyInfo); Assert.Null(columns[4].SequenceName); Assert.Equal("Updated", columns[5].ColumnName); Assert.False(columns[5].AllowInsert); Assert.True(columns[5].AllowUpdate); Assert.Equal(DbType.DateTime2, columns[5].DbType); Assert.False(columns[5].IsIdentifier); Assert.Equal(typeof(AssignedCustomer).GetProperty("Updated"), columns[5].PropertyInfo); Assert.Null(columns[5].SequenceName); }
public void TableInfoHasCorrectPropertiesForDbGenerated() { var mappingConvention = new AttributeMappingConvention(); var objectInfo = mappingConvention.CreateObjectInfo(typeof(DbGeneratedCustomer)); Assert.Equal("CustomerId", objectInfo.TableInfo.IdentifierColumn.ColumnName); Assert.Equal(IdentifierStrategy.DbGenerated, objectInfo.TableInfo.IdentifierStrategy); Assert.Equal("Customers", objectInfo.TableInfo.Name); Assert.Equal("Sales", objectInfo.TableInfo.Schema); }
public void CreateObjectInfoThrowsArgumentNullExceptionForNullType() { var mappingConvention = new AttributeMappingConvention(); var exception = Assert.Throws<ArgumentNullException>( () => mappingConvention.CreateObjectInfo(null)); Assert.Equal("forType", exception.ParamName); }
public void AMicroLiteExceptionIsThrown() { var mappingConvention = new AttributeMappingConvention(); var exception = Assert.Throws<MappingException>( () => mappingConvention.CreateObjectInfo(typeof(CustomerWithNoTableAttribute))); Assert.Equal(ExceptionMessages.AttributeMappingConvention_NoTableAttribute.FormatWith(typeof(CustomerWithNoTableAttribute).FullName), exception.Message); }