Exemplo n.º 1
0
        public async Task GetConnectedObjectsWithSortingSupportTest()
        {
            // Create 5 connected objects and request page 2 with page size of 2.
            // With sorting, it should return specific objects.
            var root = await ObjectHelper.CreateNewAsync();

            List <APObject> children = new List <APObject>();

            children.Add(ObjectHelper.NewInstance());
            children.Add(ObjectHelper.NewInstance());
            children.Add(ObjectHelper.NewInstance());
            children.Add(ObjectHelper.NewInstance());
            children.Add(ObjectHelper.NewInstance());

            var tasks = children.ConvertAll(x =>
                                            APConnection.New("sibling").FromExistingObject("object", root.Id).ToNewObject("object", x).SaveAsync());

            #if NET40
            await TaskEx.WhenAll(tasks);
            #else
            await Task.WhenAll(tasks);
            #endif

            children = children.OrderBy(x => x.Id).ToList();
            var results = await root.GetConnectedObjectsAsync("sibling", orderBy : "__id", sortOrder : SortOrder.Ascending,
                                                              pageSize : 2, pageNumber : 2);

            Assert.IsTrue(results.Count == 2);
            Assert.IsTrue(results[0].Id == children[2].Id);
            Assert.IsTrue(results[1].Id == children[3].Id);
        }
Exemplo n.º 2
0
        public async Task UpdateConnectionAsyncTest()
        {
            dynamic conn = APConnection
                           .New("sibling")
                           .FromNewObject("object", ObjectHelper.NewInstance())
                           .ToNewObject("object", ObjectHelper.NewInstance());

            conn.field1 = "test";
            conn.field2 = 15L;
            await conn.SaveAsync();

            Console.WriteLine("Created connection with id: {0}", conn.Id);

            // Update the connection
            conn.field1 = "updated";
            conn.field2 = 11L;
            await conn.SaveAsync();

            // Get the connection
            APConnection read = await APConnections.GetAsync("sibling", conn.Id);

            // Asserts
            Assert.IsTrue(read.Get <string>("field1") == "updated");
            Assert.IsTrue(read.Get <int>("field2") == 11L);
        }
Exemplo n.º 3
0
        public async Task GetConnectedObjectsAsyncTest()
        {
            // Create objects
            var obj1 = await ObjectHelper.CreateNewAsync();

            var obj2 = await ObjectHelper.CreateNewAsync();

            var obj3 = await ObjectHelper.CreateNewAsync();

            var obj4 = await ObjectHelper.CreateNewAsync();

            var obj5 = await ObjectHelper.CreateNewAsync();

            // Create connections
            await APConnection.New("sibling").FromExistingObject("object", obj1.Id).ToExistingObject("object", obj2.Id).SaveAsync();

            await APConnection.New("sibling").FromExistingObject("object", obj1.Id).ToExistingObject("object", obj3.Id).SaveAsync();

            await APConnection.New("sibling").FromExistingObject("object", obj1.Id).ToExistingObject("object", obj4.Id).SaveAsync();

            await APConnection.New("sibling").FromExistingObject("object", obj1.Id).ToExistingObject("object", obj5.Id).SaveAsync();

            // Get connected
            var connectedObjects = await obj1.GetConnectedObjectsAsync("sibling");

            Assert.IsTrue(connectedObjects != null);
            Assert.IsTrue(connectedObjects.TotalRecords == 4);
            Assert.IsTrue(connectedObjects.Select(x => x.Id).Intersect(new[] { obj2.Id, obj3.Id, obj4.Id, obj5.Id }).Count() == 4);
        }
Exemplo n.º 4
0
        public async Task GetConnectedObjectsOnConnectionWithSameTypeAndDifferentLabels()
        {
            var parent = await ObjectHelper.CreateNewAsync();

            var child1 = await ObjectHelper.CreateNewAsync();

            var child2 = await ObjectHelper.CreateNewAsync();

            // Create connections
            await APConnection.New("link")
            .FromExistingObject("parent", parent.Id)
            .ToExistingObject("child", child1.Id)
            .SaveAsync();

            await APConnection.New("link")
            .FromExistingObject("parent", parent.Id)
            .ToExistingObject("child", child2.Id)
            .SaveAsync();

            // Get connected objects
            var objects = await parent.GetConnectedObjectsAsync("link", label : "child");

            Assert.IsTrue(objects.Count == 2);
            Assert.IsTrue(objects.Select(a => a.Id).Intersect(new[] { child1.Id, child2.Id }).Count() == 2);
        }
Exemplo n.º 5
0
        public async Task GetConnectedObjectsForSameTypeAndDifferentLabelsWithoutLabelTest()
        {
            var parent = await ObjectHelper.CreateNewAsync();

            var child1 = await ObjectHelper.CreateNewAsync();

            var child2 = await ObjectHelper.CreateNewAsync();

            // Create connections
            await APConnection.New("link")
            .FromExistingObject("parent", parent.Id)
            .ToExistingObject("child", child1.Id)
            .SaveAsync();

            await APConnection.New("link")
            .FromExistingObject("parent", parent.Id)
            .ToExistingObject("child", child2.Id)
            .SaveAsync();

            // Get connected objects
            try
            {
                var objects = await parent.GetConnectedObjectsAsync("link");

                Assert.Fail("This call should have failed since we did not specify the label to retreive.");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message == "Label is required for edge 'link'.");
            }
        }
Exemplo n.º 6
0
        public async Task ConnectionsTest()
        {
            var parent = ObjectHelper.NewInstance();

            parent["stringfield"] = "parent";
            var child = ObjectHelper.NewInstance();

            child["stringfield"] = "child";
            var conn = APConnection.New("link").FromNewObject("parent", parent).ToNewObject("child", child);
            await conn.SaveAsync();

            var parent2 = await conn.Endpoints["parent"].GetObjectAsync();
            var child2  = await conn.Endpoints["child"].GetObjectAsync();

            Assert.IsTrue(parent2 != null && child2 != null);
            Assert.IsTrue(parent2.Get <string>("stringfield") == "parent");
            Assert.IsTrue(child2.Get <string>("stringfield") == "child");

            // Swap and test
            parent = ObjectHelper.NewInstance();
            parent["stringfield"] = "parent";
            child = ObjectHelper.NewInstance();
            child["stringfield"] = "child";
            conn = APConnection.New("link").FromNewObject("child", child).ToNewObject("parent", parent);
            await conn.SaveAsync();

            parent2 = await conn.Endpoints["parent"].GetObjectAsync();
            child2  = await conn.Endpoints["child"].GetObjectAsync();
            Assert.IsTrue(parent2 != null && child2 != null);
            Assert.IsTrue(parent2.Get <string>("stringfield") == "parent");
            Assert.IsTrue(child2.Get <string>("stringfield") == "child");
        }
Exemplo n.º 7
0
        public async Task CreateConnectionWithNewUserAndNewDevice()
        {
            var device = DeviceHelper.NewDevice();
            var user   = UserHelper.NewUser();
            var conn   = APConnection.New("my_device")
                         .FromNewObject("device", device)
                         .ToNewObject("user", user);
            await conn.SaveAsync();

            Assert.IsTrue(string.IsNullOrWhiteSpace(conn.Id) == false);
            Console.WriteLine("Created connection with id: {0}", conn.Id);
        }
        public async Task ProjectWithArgsTest()
        {
            // Create sample data
            string val1 = Unique.String, val2 = Unique.String;
            var    root = await ObjectHelper.CreateNewAsync();

            var level1Child = ObjectHelper.NewInstance();

            level1Child.Set <string>("stringfield", val1);
            var level1Edge = APConnection.New("link").FromExistingObject("parent", root.Id).ToNewObject("child", level1Child);
            await level1Edge.SaveAsync();

            var level2Child = ObjectHelper.NewInstance();

            level2Child.Set <string>("stringfield", val2);
            var level2Edge = APConnection.New("link").FromExistingObject("parent", level1Child.Id).ToNewObject("child", level2Child);
            await level2Edge.SaveAsync();

            // Run filter
            var results = await Graph.Select("sample_project",
                                             new [] { root.Id },
                                             new Dictionary <string, string> {
                { "level1_filter", val1 }, { "level2_filter", val2 }
            });

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].Object != null);
            Assert.IsTrue(results[0].Object.Id == root.Id);

            var level1Children = results[0].GetChildren("level1_children");

            Assert.IsTrue(level1Children.Count == 1);
            Assert.IsTrue(level1Children[0].Object != null);
            Assert.IsTrue(level1Children[0].Object.Id == level1Child.Id);
            Assert.IsTrue(level1Children[0].Connection != null);
            Assert.IsTrue(level1Children[0].Connection.Id == level1Edge.Id);
            Assert.IsTrue(level1Children[0].Connection.Endpoints["parent"].ObjectId == root.Id);
            Assert.IsTrue(level1Children[0].Connection.Endpoints["child"].ObjectId == level1Child.Id);

            var level2Children = level1Children[0].GetChildren("level2_children");

            Assert.IsTrue(level2Children.Count == 1);
            Assert.IsTrue(level2Children[0].Object != null);
            Assert.IsTrue(level2Children[0].Object.Id == level2Child.Id);
            Assert.IsTrue(level2Children[0].Connection != null);
            Assert.IsTrue(level2Children[0].Connection.Id == level2Edge.Id);
            Assert.IsTrue(level2Children[0].Connection.Endpoints["parent"].ObjectId == level1Child.Id);
            Assert.IsTrue(level2Children[0].Connection.Endpoints["child"].ObjectId == level2Child.Id);
        }
        public async static Task <APConnection> CreateNew(APConnection conn = null)
        {
            if (conn == null)
            {
                conn = APConnection
                       .New("sibling")
                       .FromNewObject("object", ObjectHelper.NewInstance())
                       .ToNewObject("object", ObjectHelper.NewInstance());
            }
            await conn.SaveAsync();

            Assert.IsTrue(string.IsNullOrWhiteSpace(conn.Id) == false);
            Console.WriteLine("Created connection with id: {0}", conn.Id);
            return(conn);
        }
Exemplo n.º 10
0
        public async Task CreateConnection2BetweenNewAndExistingObjectsAsyncTest()
        {
            var obj1 = await ObjectHelper.CreateNewAsync();

            var obj2 = new APObject("object");
            var conn = APConnection
                       .New("sibling")
                       .FromExistingObject("object", obj1.Id)
                       .ToNewObject("object", obj2);
            await conn.SaveAsync();

            Assert.IsTrue(string.IsNullOrWhiteSpace(conn.Id) == false);
            Console.WriteLine("Created connection with id: {0}", conn.Id);
            Assert.IsTrue(string.IsNullOrWhiteSpace(obj2.Id) == false);
            Console.WriteLine("Created new apObject with id: {0}", obj1.Id);
            // Ensure that the endpoint ids match
            Assert.IsTrue(conn.Endpoints.ToArray().Select(x => x.ObjectId).Intersect(new[] { obj1.Id, obj2.Id }).Count() == 2);
        }
Exemplo n.º 11
0
        public async Task CreateConnectionBetweenNewObjectsAsyncTest()
        {
            var obj1 = new APObject("object");
            var obj2 = new APObject("object");
            var conn = APConnection
                       .New("sibling")
                       .FromNewObject("object", obj1)
                       .ToNewObject("object", obj2);

            await conn.SaveAsync();

            Assert.IsTrue(string.IsNullOrWhiteSpace(conn.Id) == false);
            Console.WriteLine("Created connection with id: {0}", conn.Id);
            Assert.IsTrue(string.IsNullOrWhiteSpace(obj1.Id) == false);
            Console.WriteLine("Created new apObject with id: {0}", obj1.Id);
            Assert.IsTrue(string.IsNullOrWhiteSpace(obj2.Id) == false);
            Console.WriteLine("Created new apObject with id: {0}", obj2.Id);
        }
Exemplo n.º 12
0
        public async Task CreateDuplicateConnectionAsyncTest()
        {
            var o1   = new APObject("object");
            var o2   = new APObject("object");
            var conn = await APConnection
                       .New("sibling")
                       .FromNewObject("object", o1)
                       .ToNewObject("object", o2)
                       .SaveAsync();

            var dupe = await APConnection
                       .New("sibling")
                       .FromExistingObject("object", o1.Id)
                       .ToExistingObject("object", o2.Id)
                       .SaveAsync();

            Assert.AreEqual(conn.Id, dupe.Id);
        }
        public async Task FilterWithArgsTest()
        {
            var parent = await ObjectHelper.CreateNewAsync();

            var unique = Unique.String;
            var child  = ObjectHelper.NewInstance();

            child.Set <string>("stringfield", unique);
            var conn = APConnection.New("link").FromExistingObject("parent", parent.Id).ToNewObject("child", child);
            await conn.SaveAsync();

            // Run filter
            var results = await Graph.Query("sample_filter", new Dictionary <string, string> {
                { "search_value", unique }
            });

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0] == parent.Id);
        }
Exemplo n.º 14
0
        public async Task GetEndpointContentTest()
        {
            var existing = await ObjectHelper.CreateNewAsync();

            var newObj = ObjectHelper.NewInstance();
            var conn   = APConnection
                         .New("link")
                         .FromExistingObject("parent", existing.Id)
                         .ToNewObject("child", newObj);
            await conn.SaveAsync();

            Assert.IsTrue(conn.GetEndpointId("parent") == existing.Id);
            Assert.IsTrue(string.IsNullOrWhiteSpace(conn.GetEndpointId("child")) == false);

            // Get endpoints
            var child = await conn.GetEndpointObjectAsync("child");

            var parent = await conn.GetEndpointObjectAsync("parent");

            Assert.IsNotNull(child);
            Assert.IsNotNull(parent);
            Assert.IsTrue(parent.Id == existing.Id);
        }
Exemplo n.º 15
0
        public async Task UpdatePartialConnectionAsyncTest()
        {
            // Create new connection
            var obj1 = await ObjectHelper.CreateNewAsync();

            var obj2 = new APObject("object");
            var conn = APConnection
                       .New("sibling")
                       .FromExistingObject("object", obj1.Id)
                       .ToNewObject("object", obj2);
            await conn.SaveAsync();

            // Update
            var conn2 = new APConnection("sibling", conn.Id);
            var value = Guid.NewGuid().ToString();

            conn["field1"] = value;
            await conn.SaveAsync();

            var updated = await APConnections.GetAsync("sibling", conn.Id);

            Assert.IsTrue(updated.Get <string>("field1") == value);
        }
Exemplo n.º 16
0
        public async Task CreateDuplicateConnectionWithFaultAsyncTest()
        {
            var o1   = new APObject("object");
            var o2   = new APObject("object");
            var conn = await APConnection
                       .New("sibling")
                       .FromNewObject("object", o1)
                       .ToNewObject("object", o2)
                       .SaveAsync();

            try
            {
                var dupe = await APConnection
                           .New("sibling")
                           .FromExistingObject("object", o1.Id)
                           .ToExistingObject("object", o2.Id)
                           .SaveAsync(throwIfAlreadyExists: true);

                Assert.Fail("Duplicate connection creation did not fault.");
            }
            catch (DuplicateObjectException)
            {
            }
        }