public void CanSerializeCacheValueOfListOfRelations() { var relation1 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var relation2 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var relation3 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var list = new List <IRelationById> { relation1, relation2, relation3 }; var cacheValueOf = new CacheValueOf <List <IRelationById> >(list); //Serialize var serializedKey = SerializationService.ToStream(cacheValueOf); var keyJson = serializedKey.ResultStream.ToJsonString(); //Deserialize var keyBack = SerializationService.FromStream(serializedKey.ResultStream, typeof(CacheValueOf <List <IRelationById> >)); //Serialize again var serializedKeyBack = SerializationService.ToStream(keyBack); var keyJsonTwice = serializedKeyBack.ResultStream.ToJsonString(); Assert.That(keyBack, Is.Not.Null); Assert.That(keyJson, Is.EqualTo(keyJsonTwice)); }
public void RelationById_EqualityCheck() { // Arrange var item1 = new RelationById(HiveId.ConvertIntToGuid(5), HiveId.ConvertIntToGuid(10), FixedRelationTypes.DefaultRelationType, 0); var item2 = new RelationById(HiveId.ConvertIntToGuid(5), HiveId.ConvertIntToGuid(10), FixedRelationTypes.DefaultRelationType, 0); var item3 = new RelationById(HiveId.ConvertIntToGuid(2), HiveId.ConvertIntToGuid(10), FixedRelationTypes.DefaultRelationType, 0); // Assert Assert.AreEqual(item1, item2); Assert.AreNotEqual(item1, item3); }
private void EnsureNotifyRelationCache(HiveId fileId) { // Get the parents (remember we can have other parents because we have the relation xml too) var parents = PerformGetParentRelations(fileId, FixedRelationTypes.DefaultRelationType).ToArray(); foreach (var parent in parents) { var fakeRelation = new RelationById(parent.SourceId, fileId, FixedRelationTypes.DefaultRelationType, 0); base.NotifyRelationCache(fakeRelation); } }
public void RelationById_Setting_Ids_In_Constructor_Works() { //Arrange var sourceId = new HiveId(1); var destinationId = new HiveId(2); var relationType = new RelationType("TestRelationType"); //Act var relation = new RelationById(sourceId, destinationId, relationType, 0); //Assert Assert.IsTrue(relation.SourceId.ToString(HiveIdFormatStyle.AsUri) == sourceId.ToString(HiveIdFormatStyle.AsUri)); Assert.IsTrue(relation.DestinationId.ToString(HiveIdFormatStyle.AsUri) == destinationId.ToString(HiveIdFormatStyle.AsUri)); }
public void CanSerializeCacheValueOfIRelationById() { var relation1 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var cacheValue = new CacheValueOf <IRelationById>(relation1); var json = SerializationService.ToJson(cacheValue); Assert.That(json, Is.Not.Empty); var rehydrate = SerializationService.FromJson <CacheValueOf <IRelationById> >(json); Assert.That(rehydrate, Is.Not.Null); Assert.That(rehydrate, Is.EqualTo(cacheValue)); }
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 CanSerializeRelationToJson() { var sourceId = new HiveId(Guid.NewGuid()); var destinationId = new HiveId(Guid.NewGuid()); var relationType = new RelationType("DefaultRelation"); var relation = new RelationById(sourceId, destinationId, relationType, 0); var result = SerializationService.ToStream(relation); Assert.That(result.Success, Is.True); Assert.That(result.ResultStream, Is.Not.Null); string json = result.ResultStream.ToJsonString(); Assert.That(json, Is.Not.Empty); Assert.That(json.StartsWith("{"), Is.True); Assert.That(json.EndsWith("}")); }
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 static IRelationById FromXml(string xmlString) { var xml = XDocument.Parse(xmlString); var relation = new RelationById( HiveId.Parse(xml.Root.Attribute("sourceId").Value), HiveId.Parse(xml.Root.Attribute("destinationId").Value), // TODO: Might be something other than RelationType new RelationType(xml.Root.Attribute("type").Value), Int32.Parse(xml.Root.Attribute("ordinal").Value) ); if(xml.Root.HasElements) { foreach (var metaDatum in xml.Root.Elements("metaDatum")) { relation.MetaData.Add(new RelationMetaDatum(metaDatum.Attribute("key").Value, metaDatum.Attribute("value").Value)); } } return relation; }
public static IRelationById FromXml(string xmlString) { var xml = XDocument.Parse(xmlString); var relation = new RelationById( HiveId.Parse(xml.Root.Attribute("sourceId").Value), HiveId.Parse(xml.Root.Attribute("destinationId").Value), // TODO: Might be something other than RelationType new RelationType(xml.Root.Attribute("type").Value), Int32.Parse(xml.Root.Attribute("ordinal").Value) ); if (xml.Root.HasElements) { foreach (var metaDatum in xml.Root.Elements("metaDatum")) { relation.MetaData.Add(new RelationMetaDatum(metaDatum.Attribute("key").Value, metaDatum.Attribute("value").Value)); } } return(relation); }
public void CanSerializeCacheValueOfListOfRelations() { var relation1 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var relation2 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var relation3 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var list = new List<IRelationById> {relation1, relation2, relation3}; var cacheValueOf = new CacheValueOf<List<IRelationById>>(list); //Serialize var serializedKey = SerializationService.ToStream(cacheValueOf); var keyJson = serializedKey.ResultStream.ToJsonString(); //Deserialize var keyBack = SerializationService.FromStream(serializedKey.ResultStream, typeof(CacheValueOf<List<IRelationById>>)); //Serialize again var serializedKeyBack = SerializationService.ToStream(keyBack); var keyJsonTwice = serializedKeyBack.ResultStream.ToJsonString(); Assert.That(keyBack, Is.Not.Null); Assert.That(keyJson, Is.EqualTo(keyJsonTwice)); }
public void CanSerializeCacheValueOfIRelationById() { var relation1 = new RelationById(new HiveId(Guid.NewGuid()), new HiveId(Guid.NewGuid()), FixedRelationTypes.DefaultRelationType, 0); var cacheValue = new CacheValueOf<IRelationById>(relation1); var json = SerializationService.ToJson(cacheValue); Assert.That(json, Is.Not.Empty); var rehydrate = SerializationService.FromJson<CacheValueOf<IRelationById>>(json); Assert.That(rehydrate, Is.Not.Null); Assert.That(rehydrate, Is.EqualTo(cacheValue)); }
public void CanSerializeRelationToJson() { var sourceId = new HiveId(Guid.NewGuid()); var destinationId = new HiveId(Guid.NewGuid()); var relationType = new RelationType("DefaultRelation"); var relation = new RelationById(sourceId, destinationId, relationType, 0); var result = SerializationService.ToStream(relation); Assert.That(result.Success, Is.True); Assert.That(result.ResultStream, Is.Not.Null); string json = result.ResultStream.ToJsonString(); Assert.That(json, Is.Not.Empty); Assert.That(json.StartsWith("{"), Is.True); Assert.That(json.EndsWith("}")); }
public void RelationById_EqualityCheck() { // Arrange var item1 = new RelationById(HiveId.ConvertIntToGuid(5), HiveId.ConvertIntToGuid(10), FixedRelationTypes.DefaultRelationType, 0); var item2 = new RelationById(HiveId.ConvertIntToGuid(5), HiveId.ConvertIntToGuid(10), FixedRelationTypes.DefaultRelationType, 0); var item3 = new RelationById(HiveId.ConvertIntToGuid(2), HiveId.ConvertIntToGuid(10), FixedRelationTypes.DefaultRelationType, 0); // Assert Assert.AreEqual(item1, item2); Assert.AreNotEqual(item1, item3); }
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()); }