public async void TestChildOf() { IBranch master = await Fixture.Repository.MasterAsync(); JObject nodeObj1 = new JObject( new JProperty("title", "Node1") ); INode node1 = (INode)await master.CreateNodeAsync(nodeObj1); JObject nodeObj2 = new JObject( new JProperty("title", "Node2") ); INode node2 = (INode)await master.CreateNodeAsync(nodeObj2); IAssociation association = await node1.ChildOfAsync(node2); Assert.NotNull(association); Assert.Equal(Directionality.DIRECTED, association.Directionality); INode source = await association.ReadSourceNodeAsync(); Assert.Equal(node2.Id, source.Id); INode target = await association.ReadTargetNodeAsync(); Assert.Equal(node1.Id, target.Id); }
public async void TestNodeCrud() { IBranch branch = await Fixture.Repository.ReadBranchAsync("master"); JObject nodeObj = new JObject( new JProperty("title", "MyNode") ); IBaseNode node = await branch.CreateNodeAsync(nodeObj); string expectedRef = "node://" + node.PlatformId + "/" + node.RepositoryId + "/" + node.BranchId + "/" + node.Id; Assert.Equal(expectedRef, node.Ref.Ref); Assert.NotNull(node.QName); Assert.Equal("n:node", node.TypeQName.ToString()); IBaseNode nodeRead = await branch.ReadNodeAsync(node.Id); Assert.Equal(node.Data, nodeRead.Data); node.Data["title"] = "New title"; await node.UpdateAsync(); await nodeRead.ReloadAsync(); Assert.Equal(node.Data["title"], nodeRead.Data["title"]); await node.DeleteAsync(); nodeRead = await branch.ReadNodeAsync(node.Id); Assert.Null(nodeRead); }
public async void TestVersions() { IBranch master = await Fixture.Repository.MasterAsync(); JObject nodeObj = new JObject( new JProperty("title", "Test Node") ); IBaseNode node = await master.CreateNodeAsync(nodeObj); string firstChangeset = node.Data.SelectToken("_system.changeset").ToString(); node.Data["title"] = "new stuff"; await node.UpdateAsync(); await node.ReloadAsync(); Assert.Equal("new stuff", node.Data.GetValue("title").ToString()); List <IBaseNode> versions = await node.ListVersionsAsync(); Assert.Equal(2, versions.Count); IBaseNode firstVersion = await node.ReadVersionAsync(firstChangeset); Assert.Equal("Test Node", firstVersion.Data["title"].ToString()); IBaseNode restoredVersion = await node.RestoreVersionAsync(firstChangeset); Assert.Equal("Test Node", restoredVersion.Data["title"].ToString()); }
public async void TestFeatures() { IBranch branch = await Fixture.Repository.ReadBranchAsync("master"); IBaseNode node = await branch.CreateNodeAsync(new JObject()); List <string> featureIds = node.GetFeatureIds(); Assert.NotEmpty(featureIds); JObject filenameObj = new JObject( new JProperty("filename", "file1") ); await node.AddFeatureAsync("f:filename", filenameObj); featureIds = node.GetFeatureIds(); Assert.Contains("f:filename", featureIds); Assert.True(node.HasFeature("f:filename")); JObject featureObj = node.GetFeature("f:filename"); Assert.Equal("file1", featureObj.GetValue("filename")); await node.RemoveFeatureAsync("f:filename"); featureIds = node.GetFeatureIds(); Assert.DoesNotContain("f:filename", featureIds); Assert.False(node.HasFeature("f:filename")); Assert.Null(node.GetFeature("f:filename")); }
public async void TestAttachmentBytes() { var assembly = Assembly.GetExecutingAssembly(); Stream cloudcmsStream = assembly.GetManifestResourceStream("CloudCMS.res.cloudcms.png"); byte[] cloudcmsImage = ReadStreamBytes(cloudcmsStream); Stream headphonesStream = assembly.GetManifestResourceStream("CloudCMS.res.headphones.png"); byte[] headphonesImage = ReadStreamBytes(headphonesStream); IBranch branch = await Fixture.Repository.ReadBranchAsync("master"); INode node = (INode)await branch.CreateNodeAsync(); await node.UploadAttachmentAsync("default", cloudcmsImage, "image/png", "myImage"); List <IAttachment> attachments = await node.ListAttachments(); IAttachment attachment = attachments[0]; Assert.Equal("default", attachment.Id); Assert.Equal("myImage", attachment.Filename); Assert.Equal("image/png", attachment.ContentType); Assert.True(attachment.Length > 0); Assert.NotNull(attachment.ObjectId); byte[] download = await node.DownloadAttachmentBytesAsync(); Assert.NotEmpty(download); byte[] downloadCopy = await attachment.DownloadAsync(); Assert.Equal(download.Length, downloadCopy.Length); Dictionary <string, AttachmentContent> attachmentContents = new Dictionary <string, AttachmentContent>(); attachmentContents.Add("another", new AttachmentContent(headphonesImage, "image/png")); await node.UploadAttachmentsAsync(attachmentContents); attachments = await node.ListAttachments(); Assert.Equal(2, attachments.Count); await node.DeleteAttachmentAsync("default"); attachments = await node.ListAttachments(); Assert.Single(attachments); attachment = attachments[0]; Assert.Equal("another", attachment.Id); Assert.Equal("another", attachment.Filename); Assert.Equal("image/png", attachment.ContentType); Assert.True(attachment.Length > 0); Assert.NotNull(attachment.ObjectId); }
public async void TestChangeQName() { IBranch master = await Fixture.Repository.MasterAsync(); JObject nodeObj = new JObject( new JProperty("_type", "n:node"), new JProperty("title", "Test Node") ); IBaseNode node = await master.CreateNodeAsync(nodeObj); await node.ChangeQNameAsync(QName.create("o:blah")); await node.ReloadAsync(); QName newQName = node.QName; Assert.Equal("o:blah", newQName.ToString()); }
private async Task <INode> createFile(IBranch branch, INode parent, string filename, bool isFolder) { JObject nodeObj = new JObject(new JProperty("title", filename)); INode node = (INode)await branch.CreateNodeAsync(nodeObj); JObject fileObj = new JObject(); fileObj.Add("filename", filename); await node.AddFeatureAsync("f:filename", fileObj); if (isFolder) { await node.AddFeatureAsync("f:container", new JObject()); } await parent.AssociateAsync(node, QName.create("a:child"), Directionality.DIRECTED); return(node); }
public async void TestAssociateUnassociate() { IBranch master = await Fixture.Repository.MasterAsync(); JObject nodeObj1 = new JObject( new JProperty("title", "Node1") ); INode node1 = (INode)await master.CreateNodeAsync(nodeObj1); JObject nodeObj2 = new JObject( new JProperty("title", "Node2") ); INode node2 = (INode)await master.CreateNodeAsync(nodeObj2); JObject nodeObj3 = new JObject( new JProperty("title", "Node3") ); INode node3 = (INode)await master.CreateNodeAsync(nodeObj3); // Associate node 1 directed to node 2 with a:child IAssociation association1 = await node1.AssociateAsync(node2, QName.create("a:child")); string expectedRef = "association://" + association1.PlatformId + "/" + association1.RepositoryId + "/" + association1.BranchId + "/" + association1.Id; Assert.Equal(expectedRef, association1.Ref.Ref); Assert.Equal(Directionality.DIRECTED, association1.Directionality); Assert.Equal(node1.Id, association1.SourceNodeId); Assert.Equal(node2.Id, association1.TargetNodeId); INode source = await association1.ReadSourceNodeAsync(); Assert.Equal(node1.Id, source.Id); INode target = await association1.ReadTargetNodeAsync(); Assert.Equal(node2.Id, target.Id); // Associate node 1 undirected to node 3 with a:linked JObject associationData = new JObject( new JProperty("test", "field") ); IAssociation association2 = await node1.AssociateAsync(node3, QName.create("a:linked"), Directionality.UNDIRECTED, associationData); Assert.Equal(Directionality.UNDIRECTED, association2.Directionality); Assert.Equal(node1.Id, association2.SourceNodeId); Assert.Equal(node3.Id, association2.TargetNodeId); // Check all associations List <IAssociation> allAssociations = await node1.AssociationsAsync(); Assert.Equal(3, allAssociations.Count); // will include a has_role association // Outgoing associations List <IAssociation> outgoingAssociations = await node1.AssociationsAsync(Direction.OUTGOING); Assert.Equal(2, outgoingAssociations.Count); // undirected counts as incoming // Incoming associations List <IAssociation> incomingAssociations = await node1.AssociationsAsync(Direction.INCOMING); Assert.Equal(2, incomingAssociations.Count); // will include has_role // Child Associations List <IAssociation> childAssociations = await node1.AssociationsAsync(QName.create("a:child")); Assert.Single(childAssociations); // Unassociate the two associations await node1.UnassociateAsync(node2, QName.create("a:child")); await node1.UnassociateAsync(node3, QName.create("a:linked"), Directionality.UNDIRECTED); allAssociations = await node1.AssociationsAsync(); Assert.Single(allAssociations); // will include a has_role association }
public async void TestNodeQuerySearchFind() { IBranch branch = await Fixture.Repository.ReadBranchAsync("master"); JObject nodeObj1 = new JObject( new JProperty("title", "Cheese burger"), new JProperty("meal", "lunch") ); JObject nodeObj2 = new JObject( new JProperty("title", "Ham burger"), new JProperty("meal", "lunch") ); JObject nodeObj3 = new JObject( new JProperty("title", "Turkey sandwich"), new JProperty("meal", "lunch") ); JObject nodeObj4 = new JObject( new JProperty("title", "Oatmeal"), new JProperty("meal", "breakfast") ); IBaseNode node1 = await branch.CreateNodeAsync(nodeObj1); IBaseNode node2 = await branch.CreateNodeAsync(nodeObj2); IBaseNode node3 = await branch.CreateNodeAsync(nodeObj3); IBaseNode node4 = await branch.CreateNodeAsync(nodeObj4); // Wait for nodes to index Thread.Sleep(5000); JObject query = new JObject( new JProperty("meal", "lunch") ); List <IBaseNode> queryNodes = await branch.QueryNodesAsync(query); var queryNodesIds = queryNodes.Select(node => node.Id); Assert.Equal(3, queryNodes.Count); Assert.Contains(node1.Id, queryNodesIds); Assert.Contains(node2.Id, queryNodesIds); Assert.Contains(node3.Id, queryNodesIds); JObject find = new JObject( new JProperty("search", "burger") ); List <IBaseNode> findNodes = await branch.FindNodesAsync(find); var findNodesIds = findNodes.Select(node => node.Id); Assert.Equal(2, findNodes.Count); Assert.Contains(node1.Id, findNodesIds); Assert.Contains(node2.Id, findNodesIds); // search List <IBaseNode> searchNodes = await branch.SearchNodesAsync("burger"); var searchNodesIds = searchNodes.Select(node => node.Id); Assert.Equal(2, searchNodes.Count); Assert.Contains(node1.Id, searchNodesIds); Assert.Contains(node2.Id, searchNodesIds); await node1.DeleteAsync(); await node2.DeleteAsync(); await node3.DeleteAsync(); await node4.DeleteAsync(); }