public void GetPropertyType() { Assert.AreEqual(typeof(string), PropertyAccessorData.GetPropertyType(MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector)), "Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name"), "Property value type"); Assert.AreEqual(typeof(ObjectList <Company>), PropertyAccessorData.GetPropertyType(MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector)), "Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies"), "Related object collection type - bidirectional relation 1:n, 1 side"); Assert.AreEqual(typeof(IndustrialSector), PropertyAccessorData.GetPropertyType(MappingConfiguration.Current.GetTypeDefinition(typeof(Company)), "Remotion.Data.DomainObjects.UnitTests.TestDomain.Company.IndustrialSector"), "Related object type - bidirectional relation 1:n, n side"); Assert.AreEqual(typeof(Computer), PropertyAccessorData.GetPropertyType(MappingConfiguration.Current.GetTypeDefinition(typeof(Employee)), "Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Computer"), "Related object type - bidirectional relation 1:1, referenced side"); Assert.AreEqual(typeof(Employee), PropertyAccessorData.GetPropertyType(MappingConfiguration.Current.GetTypeDefinition(typeof(Computer)), "Remotion.Data.DomainObjects.UnitTests.TestDomain.Computer.Employee"), "Related object type - bidirectional relation 1:1, foreign key side"); Assert.AreEqual(typeof(Client), PropertyAccessorData.GetPropertyType(MappingConfiguration.Current.GetTypeDefinition(typeof(Client)), "Remotion.Data.DomainObjects.UnitTests.TestDomain.Client.ParentClient"), "Related object type - unidirectional relation 1:n, 1 side"); }
private static PropertyAccessor CreateAccessor(DomainObject domainObject, string shortIdentifier) { string propertyIdentifier = domainObject.GetPublicDomainObjectType().FullName + "." + shortIdentifier; var data = new PropertyAccessorData(domainObject.ID.ClassDefinition, propertyIdentifier); return(new PropertyAccessor(domainObject, data, ClientTransaction.Current)); }
public void InstancePropertyObjects_StringProperty() { PropertyAccessorData accessor = CreateAccessorData(typeof(IndustrialSector), "Name"); Assert.That(accessor.PropertyDefinition, Is.Not.Null); Assert.That(accessor.PropertyDefinition, Is.SameAs(MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector)) .GetPropertyDefinition("Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name"))); Assert.That(accessor.RelationEndPointDefinition, Is.Null); }
public void GetPropertyObjects_OneOne_RealSide() { var classDefinition = MappingConfiguration.Current.GetTypeDefinition(typeof(Computer)); var propertyIdentifier = GetPropertyIdentifier(classDefinition, "Employee"); var propertyObjects = PropertyAccessorData.GetPropertyDefinitionObjects(classDefinition, propertyIdentifier); Assert.That(propertyObjects.Item2, Is.Not.Null); Assert.That(propertyObjects.Item2.ClassDefinition, Is.SameAs(classDefinition)); Assert.That(propertyObjects.Item2.PropertyName, Is.EqualTo(propertyIdentifier)); }
public void GetPropertyObjects_CollectionProperty_BackReference() { var classDefinition = MappingConfiguration.Current.GetTypeDefinition(typeof(Company)); var propertyIdentifier = GetPropertyIdentifier(classDefinition, "IndustrialSector"); var propertyObjects = PropertyAccessorData.GetPropertyDefinitionObjects(classDefinition, propertyIdentifier); Assert.That(propertyObjects.Item2, Is.Not.Null); Assert.That(propertyObjects.Item2.ClassDefinition, Is.SameAs(classDefinition)); Assert.That(propertyObjects.Item2.PropertyName, Is.EqualTo(propertyIdentifier)); }
public void InstancePropertyObjects_CollectionProperty() { PropertyAccessorData accessor = CreateAccessorData(typeof(IndustrialSector), "Companies"); Assert.That(accessor.ClassDefinition, Is.SameAs(MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector)))); Assert.That(accessor.PropertyIdentifier, Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies")); Assert.That(accessor.PropertyDefinition, Is.Null); Assert.That(accessor.RelationEndPointDefinition, Is.Not.Null); Assert.That(accessor.RelationEndPointDefinition, Is.SameAs(MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector)) .GetRelationEndPointDefinition("Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies"))); }
public void GetPropertyObjects_StringProperty() { var classDefinition = MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector)); var propertyIdentifier = GetPropertyIdentifier(classDefinition, "Name"); var propertyObjects = PropertyAccessorData.GetPropertyDefinitionObjects(classDefinition, propertyIdentifier); Assert.That(propertyObjects.Item1, Is.Not.Null); Assert.That(propertyObjects.Item1.ClassDefinition, Is.SameAs(classDefinition)); Assert.That(propertyObjects.Item1.PropertyName, Is.EqualTo(propertyIdentifier)); Assert.That(propertyObjects.Item2, Is.Null); }
public void InstancePropertyObjects_OneOneProperty_RealSide() { PropertyAccessorData accessor = CreateAccessorData(typeof(Computer), "Employee"); Assert.That(accessor.PropertyDefinition, Is.Not.Null); Assert.That(accessor.PropertyDefinition, Is.SameAs(MappingConfiguration.Current.GetTypeDefinition(typeof(Computer)) .GetPropertyDefinition("Remotion.Data.DomainObjects.UnitTests.TestDomain.Computer.Employee"))); Assert.That(accessor.RelationEndPointDefinition, Is.Not.Null); Assert.That(accessor.RelationEndPointDefinition, Is.SameAs(MappingConfiguration.Current.GetTypeDefinition(typeof(Computer)) .GetRelationEndPointDefinition("Remotion.Data.DomainObjects.UnitTests.TestDomain.Computer.Employee"))); }
public void Construction() { var transaction = ClientTransaction.CreateRootTransaction(); IndustrialSector sector; using (transaction.EnterNonDiscardingScope()) { sector = IndustrialSector.NewObject(); } var data = new PropertyAccessorData(sector.ID.ClassDefinition, typeof(IndustrialSector).FullName + ".Name"); var propertyAccessor = new PropertyAccessor(sector, data, transaction); Assert.That(propertyAccessor.DomainObject, Is.SameAs(sector)); Assert.That(propertyAccessor.PropertyData, Is.SameAs(data)); Assert.That(propertyAccessor.ClientTransaction, Is.SameAs(transaction)); }
public void GetValue_SetValue_WithTransaction() { var transaction = ClientTransaction.CreateRootTransaction(); IndustrialSector sector; using (transaction.EnterNonDiscardingScope()) { sector = IndustrialSector.NewObject(); sector.Name = "Foo"; } var data = new PropertyAccessorData(sector.ID.ClassDefinition, typeof(IndustrialSector).FullName + ".Name"); var accessor = new PropertyAccessor(sector, data, transaction); Assert.That(accessor.GetValue <string> (), Is.EqualTo("Foo")); accessor.SetValue("Bar"); using (transaction.EnterNonDiscardingScope()) { Assert.That(sector.Name, Is.EqualTo("Bar")); } }
public PropertyAccessorData FindPropertyAccessorData([NotNull] Type typeToStartSearch, [NotNull] string shortPropertyName) { ArgumentUtility.CheckNotNull("typeToStartSearch", typeToStartSearch); // The first loop already checks the shortPropertyName argument. ArgumentUtility.DebugCheckNotNullOrEmpty("shortPropertyName", shortPropertyName); Type currentType = typeToStartSearch; PropertyAccessorData propertyAccessorData = null; while (currentType != null && (propertyAccessorData = GetPropertyAccessorData(currentType, shortPropertyName)) == null) { if (currentType.IsGenericType && !currentType.IsGenericTypeDefinition) { currentType = currentType.GetGenericTypeDefinition(); } else { currentType = currentType.BaseType; } } return(propertyAccessorData); }
public void GetPropertyObjects_ThrowsOnInvalidPropertyID2() { PropertyAccessorData.GetPropertyDefinitionObjects( MappingConfiguration.Current.GetTypeDefinition(typeof(Company)), "Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies"); }
public void GetPropertyObjects_ThrowsOnInvalidPropertyID1() { PropertyAccessorData.GetPropertyDefinitionObjects( MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector)), "Bla"); }