public TypedEntity() { //v2: create the relation proxy collection RelationProxies = new RelationProxyCollection(this); //create the attributes Func <TypedAttribute, bool> validateAdd = x => { //if (FixedAttributeDefinitionAliases.AllAliases.Contains(x.AttributeDefinition.Alias)) // return true; // TODO: Better validation here if (EntitySchema == null) { return(true); } var composite = EntitySchema as CompositeEntitySchema; if (composite != null) { return(composite.AllAttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias)); } return(EntitySchema.AttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias)); }; Attributes = new TypedAttributeCollection(validateAdd); Attributes.CollectionChanged += AttributesCollectionChanged; }
public void AddingItemsManually_AsParent_CountIsCorrect() { // Arrange var disconnectedParent = HiveModelCreationHelper.MockTypedEntity(); var disconnectedChild = HiveModelCreationHelper.MockTypedEntity(); var rpc = new RelationProxyCollection(disconnectedChild); // Act rpc.EnlistParent(disconnectedParent, FixedRelationTypes.DefaultRelationType); // Assert Assert.AreEqual(1, rpc.Count()); Assert.AreEqual(1, rpc.GetManualProxies().Count()); }
public EntitySchema() { AttributeDefinitions = new EntityCollection <AttributeDefinition>(); _attributeGroups = new EntityCollection <AttributeGroup>() { OnRemove = EnsureAttributeDefsRemoved }; _attributeGroups.CollectionChanged += AttributeGroupsCollectionChanged; EnsureXmlConfigSetup(); //v2: create the relation proxy collection RelationProxies = new RelationProxyCollection(this); SchemaType = FixedSchemaTypes.GenericUnknown; }
public void AddingItemsManually_AsParent_ThenAsChild_ThrowsDueToInfiniteCycle() { // Arrange var connectedParent = HiveModelCreationHelper.MockTypedEntity(); var middleItem = HiveModelCreationHelper.MockTypedEntity(); connectedParent.Id = HiveId.ConvertIntToGuid(1); // It's connected with a lazy-loader so it should have an Id middleItem.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id var rpc = new RelationProxyCollection(middleItem); // Act // Add parent to this item rpc.EnlistParent(connectedParent, FixedRelationTypes.DefaultRelationType); // Assert // Try to add the parent as a child of the middle item, hoping it throws Assert.Throws<InvalidOperationException>(() => rpc.EnlistChild(connectedParent, FixedRelationTypes.DefaultRelationType)); }
public void AddingItemsLazily_AsParent_CountIsCorrect() { // Arrange var connectedChild = HiveModelCreationHelper.MockTypedEntity(); connectedChild.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id var rpc = new RelationProxyCollection(connectedChild); // Act rpc.LazyLoadDelegate = ownerIdOfProxyColl => { var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfProxyColl, FixedRelationTypes.DefaultRelationType, 0); return new RelationProxyBucket(new[] { parent }, Enumerable.Empty<RelationById>()); }; // Assert Assert.AreEqual(1, rpc.Count()); Assert.AreEqual(0, rpc.GetManualProxies().Count()); }
public void AddingItemsManually_AsParent_ThenAsChild_ThrowsDueToInfiniteCycle() { // Arrange var connectedParent = HiveModelCreationHelper.MockTypedEntity(); var middleItem = HiveModelCreationHelper.MockTypedEntity(); connectedParent.Id = HiveId.ConvertIntToGuid(1); // It's connected with a lazy-loader so it should have an Id middleItem.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id var rpc = new RelationProxyCollection(middleItem); // Act // Add parent to this item rpc.EnlistParent(connectedParent, FixedRelationTypes.DefaultRelationType); // Assert // Try to add the parent as a child of the middle item, hoping it throws Assert.Throws <InvalidOperationException>(() => rpc.EnlistChild(connectedParent, FixedRelationTypes.DefaultRelationType)); }
public void AddingItemsLazily_AsParent_CountIsCorrect() { // Arrange var connectedChild = HiveModelCreationHelper.MockTypedEntity(); connectedChild.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id var rpc = new RelationProxyCollection(connectedChild); // Act rpc.LazyLoadDelegate = ownerIdOfProxyColl => { var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfProxyColl, FixedRelationTypes.DefaultRelationType, 0); return(new RelationProxyBucket(new[] { parent }, Enumerable.Empty <RelationById>())); }; // Assert Assert.AreEqual(1, rpc.Count()); Assert.AreEqual(0, rpc.GetManualProxies().Count()); }
public void AddingItemsLazily_AndManually_AsParent_CountIsCorrect() { // Arrange var existingItemForParent = HiveModelCreationHelper.MockTypedEntity(); var unsavedItemForAddingAsParent = HiveModelCreationHelper.MockTypedEntity(); var connectedChild = HiveModelCreationHelper.MockTypedEntity(); existingItemForParent.Id = HiveId.ConvertIntToGuid(1); // Assign Ids to mimic a lazy-loading valid scenario connectedChild.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id var rpc = new RelationProxyCollection(connectedChild); // Act // This delegate mimics a lazy-loader, which returns RelationById to stipulate that // the lazy loader must return existing items from the datastore rpc.LazyLoadDelegate = ownerIdOfCollection => { var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0); var parentShouldOverrideManuallyAdded = new RelationById(existingItemForParent.Id, ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0); return(new RelationProxyBucket(new[] { parent, parentShouldOverrideManuallyAdded }, Enumerable.Empty <RelationById>())); }; rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); // Assert Assert.AreEqual(1, rpc.Count()); Assert.AreEqual(0, rpc.GetManualProxies().Count()); // Try adding more; count should not be affected rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); Assert.AreEqual(1, rpc.Count()); Assert.AreEqual(0, rpc.GetManualProxies().Count()); // This is a second parent so should affect count rpc.EnlistParent(unsavedItemForAddingAsParent, FixedRelationTypes.DefaultRelationType); Assert.AreEqual(2, rpc.Count()); Assert.AreEqual(1, rpc.GetManualProxies().Count()); }
public TypedEntity() { //v2: create the relation proxy collection RelationProxies = new RelationProxyCollection(this); //create the attributes Func<TypedAttribute, bool> validateAdd = x => { //if (FixedAttributeDefinitionAliases.AllAliases.Contains(x.AttributeDefinition.Alias)) // return true; // TODO: Better validation here if (EntitySchema == null) return true; var composite = EntitySchema as CompositeEntitySchema; if (composite != null) { return composite.AllAttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias); } return EntitySchema.AttributeDefinitions.Any(y => y.Alias == x.AttributeDefinition.Alias); }; Attributes = new TypedAttributeCollection(validateAdd); }
public StubRelatableEntity(HiveId id) { Id = id; RelationProxies = new RelationProxyCollection(this); }
public void AddingItemsLazily_AndManually_AsParent_CountIsCorrect() { // Arrange var existingItemForParent = HiveModelCreationHelper.MockTypedEntity(); var unsavedItemForAddingAsParent = HiveModelCreationHelper.MockTypedEntity(); var connectedChild = HiveModelCreationHelper.MockTypedEntity(); existingItemForParent.Id = HiveId.ConvertIntToGuid(1); // Assign Ids to mimic a lazy-loading valid scenario connectedChild.Id = HiveId.ConvertIntToGuid(2); // It's connected with a lazy-loader so it should have an Id var rpc = new RelationProxyCollection(connectedChild); // Act // This delegate mimics a lazy-loader, which returns RelationById to stipulate that // the lazy loader must return existing items from the datastore rpc.LazyLoadDelegate = ownerIdOfCollection => { var parent = new RelationById(HiveId.ConvertIntToGuid(1), ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0); var parentShouldOverrideManuallyAdded = new RelationById(existingItemForParent.Id, ownerIdOfCollection, FixedRelationTypes.DefaultRelationType, 0); return new RelationProxyBucket(new[] { parent, parentShouldOverrideManuallyAdded }, Enumerable.Empty<RelationById>()); }; rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); // Assert Assert.AreEqual(1, rpc.Count()); Assert.AreEqual(0, rpc.GetManualProxies().Count()); // Try adding more; count should not be affected rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); rpc.EnlistParent(existingItemForParent, FixedRelationTypes.DefaultRelationType); Assert.AreEqual(1, rpc.Count()); Assert.AreEqual(0, rpc.GetManualProxies().Count()); // This is a second parent so should affect count rpc.EnlistParent(unsavedItemForAddingAsParent, FixedRelationTypes.DefaultRelationType); Assert.AreEqual(2, rpc.Count()); Assert.AreEqual(1, rpc.GetManualProxies().Count()); }