public void OidColumnShouldntBeRemappedWithAssembyWideColumnAttribute() { NDOMapping mapping = NDOMapping.Create(null); var cls = mapping.AddStandardClass("TestClass", "TestAssembly", null); Assert.AreEqual("ID", cls.Oid.OidColumns.First().Name); var attr = new OidColumnAttribute() { Name = "newColumnName", IsAssemblyWideDefinition = true }; cls.Oid.RemapOidColumns(new[] { attr }); Assert.AreEqual("ID", cls.Oid.OidColumns.First().Name); }
public void AssembyWideColumnAttributeOverwritesDefaultValues() { NDOMapping mapping = NDOMapping.Create(null); var cls = mapping.AddStandardClass("TestClass", "TestAssembly", null); Assert.AreEqual(1, cls.Oid.OidColumns.First().AutoIncrementStart); var attr = new OidColumnAttribute() { Name = "newColumnName", AutoIncrementStart = 2, IsAssemblyWideDefinition = true }; cls.Oid.RemapOidColumns(new[] { attr }); Assert.AreEqual(2, cls.Oid.OidColumns.First().AutoIncrementStart); }
public void RemapOidColumnsWorks() { NDOMapping mapping = NDOMapping.Create(null); var cls = mapping.AddStandardClass("TestClass", "TestAssembly", null); Assert.AreEqual("ID", cls.Oid.OidColumns.First().Name); var attr = new OidColumnAttribute() { Name = "newColumnName" }; cls.Oid.RemapOidColumns(new[] { attr }); Assert.AreEqual("newColumnName", cls.Oid.OidColumns.First().Name); }
private void CheckOidAttributes() { List <OidColumnAttribute> collectedAttributes = new List <OidColumnAttribute>(); object[] attributes = this.classType.GetCustomAttributes(typeof(OidColumnAttribute), true); if (attributes.Length > 0) { if (this.classType.GetCustomAttributes(typeof(NDOOidTypeAttribute), true).Length > 0) { new MessageAdapter().WriteLine("Warning: Can't mix OidColumnAttribute and NDOOidTypeAttribute in type " + this.name + ". The NDOOidTypeAttribute is ignored."); } foreach (OidColumnAttribute ca in attributes) { collectedAttributes.Add(ca); } } else // Try to implement the old mapping { // The attribute is collected from the first base class defining it attributes = this.classType.GetCustomAttributes(typeof(NDOOidTypeAttribute), true); if (attributes.Length > 0) { collectedAttributes.Add(new OidColumnAttribute(((NDOOidTypeAttribute)attributes[0]).OidType)); } } FieldMap fieldMap = new FieldMap(this.classType); foreach (var de in fieldMap.PersistentFields) { FieldInfo fi = de.Value as FieldInfo; if (fi == null) { continue; } #pragma warning disable 0618 if (fi.GetCustomAttributes(typeof(NDOObjectIdAttribute), false).Length > 0) { OidColumnAttribute ca = new OidColumnAttribute(); ca.FieldName = fi.Name; collectedAttributes.Add(ca); } #pragma warning restore 0618 } // If no attribute is assigned to the class, look for attributes assigned to the assembly if (collectedAttributes.Count == 0) { attributes = this.classType.Assembly.GetCustomAttributes(typeof(OidColumnAttribute), false); foreach (OidColumnAttribute ca in attributes) { ca.IsAssemblyWideDefinition = true; collectedAttributes.Add(ca); } } if (collectedAttributes.Count == 0) { attributes = this.classType.Assembly.GetCustomAttributes(typeof(NDOOidTypeAttribute), false); // The old mapping only allowed 1 NDOOidAttribute, so let's take the first one found if (attributes.Length > 0) { collectedAttributes.Add(new OidColumnAttribute(((NDOOidTypeAttribute)attributes[0]).OidType) { IsAssemblyWideDefinition = true }); } } if (collectedAttributes.Count > 0) { this.columnAttributes = new OidColumnAttribute[collectedAttributes.Count]; collectedAttributes.CopyTo(this.columnAttributes, 0); } }