public void Linq_MultiReference() { var path1 = TestRoot2.Path + "/Neighbor1"; var path2 = TestRoot2.Path + "/Neighbor2"; var names = new[] { "Mother1", "Mother2", "Child1", "Child2", "Child3" }; try { var node1 = Node.Load <RefTestNode>(path1); if (node1 == null) { node1 = new RefTestNode(TestRoot2); node1.Name = "Neighbor1"; node1.Save(); var refNodes = names.Select(n => Node.Load <RefTestNode>(RepositoryPath.Combine(TestRoot2.Path, n))).ToArray(); node1.Neighbors = refNodes; node1.Save(); } var node2 = Node.Load <RefTestNode>(path2); if (node2 == null) { node2 = new RefTestNode(TestRoot2); node2.Name = "Neighbor2"; node2.Save(); var refNodes = (new[] { "Mother1", "Child1" }).Select(n => Node.Load <RefTestNode>(RepositoryPath.Combine(TestRoot2.Path, n))).ToArray(); node2.Neighbors = refNodes; node2.Save(); } //-------- var child2 = Node.LoadNode(TestRoot2.Path + "/Child2"); var result = Content.All.DisableAutofilters().Where(c => ((RefTestNode)c.ContentHandler).Neighbors.Contains(child2)).ToArray(); Assert.IsTrue(result.Length == 1, String.Format("result.Length is {0}, expected: 1.", result.Length)); Assert.IsTrue(result.First().Name == "Neighbor1", String.Format("result.First().Name is {0}, expected: 'Neighbor1'.", result.First().Name)); } finally { Node.ForceDelete(path1); Node.ForceDelete(path2); } }
public static void InitializePlayground(TestContext testContext) { var content = Content.Create(User.Administrator); if (((IEnumerable <Node>)content["Manager"]).Count() <= 0) { content["Manager"] = User.Administrator; content["Email"] = "*****@*****.**"; content.Save(); } //======================================================================================= var groups = Content.CreateNew("Folder", TestRoot, "Groups").ContentHandler; groups.Save(); var htmlContents = Content.CreateNew("Folder", TestRoot, "HTMLContents").ContentHandler; htmlContents.Save(); var cars = Content.CreateNew("Folder", TestRoot, "Cars").ContentHandler; cars.Save(); for (int i = 1; i <= 4; i++) { content = Content.CreateNew("Group", groups, "Group" + i); content["Index"] = i; content.Save(); content = Content.CreateNew("HTMLContent", htmlContents, "HTMLContent" + i); content["Index"] = i; content.Save(); content = Content.CreateNew("Car", cars, "Car" + i); content["Index"] = i; content.Save(); } //======================================================================================= if (ContentType.GetByName("RefTestNode") == null) { ContentTypeInstaller.InstallContentType(RefTestNode.ContentTypeDefinition); } var mother1 = new RefTestNode(TestRoot2); mother1.Name = "Mother1"; mother1.Save(); var mother2 = new RefTestNode(TestRoot2); mother2.Name = "Mother2"; mother2.Save(); var child1 = new RefTestNode(TestRoot2); child1.Name = "Child1"; child1.Mother = mother1; child1.Save(); var child2 = new RefTestNode(TestRoot2); child2.Name = "Child2"; child2.Mother = mother2; child2.Save(); var child3 = new RefTestNode(TestRoot2); child3.Name = "Child3"; child3.Save(); mother1.Index = 42; mother1.Save(); }