Exemplo n.º 1
0
 public HiveRelationCacheKey(RepositoryTypes repositoryType, HiveId entityId, Direction direction, RelationType relationType)
 {
     RepositoryType = repositoryType;
     EntityId = entityId;
     Direction = direction;
     RelationType = relationType;
 }
        public void RepositoryReadWriterTests_GetEntityWithRelations_ReturnsWithRelations()
        {
            //Arrange
            const string searchPattern = "*.dll,*.xml";

            var repo = StubIORepositoryReadWriter.CreateRepositoryReadWriter(searchPattern);
            var dir = new DirectoryInfo(repo.RootFolder);

            var relationType = new RelationType("TestRelation");

            var file1 = CreateFile("File1");
            var file2 = CreateFile("File2");
            file2.Relations.Add(new Relation(relationType, file1, file2, new[] {
                new RelationMetaDatum("size", "100")
            }));

            repo.AddOrUpdate(file1);
            repo.AddOrUpdate(file2);

            var lookedUpFile = repo.GetEntity<File>(file1.Id);
            var childRelations = lookedUpFile.Relations.Children<File>(relationType);

            Assert.IsTrue(childRelations.Count() == 1);

            var file4 = repo.GetEntity<File>(file2.Id);
            var relations2 = file4.Relations.Parent<File>(relationType);

            Assert.IsTrue(relations2 != null);
            Assert.IsTrue(relations2.Id.ToString(HiveIdFormatStyle.AsUri) == file1.Id.ToString(HiveIdFormatStyle.AsUri));
        }
Exemplo n.º 3
0
        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("}"));
        }