コード例 #1
0
        public async Task CreateConnectionWithNewObjectsAsyncTest()
        {

            var obj1 = ObjectHelper.NewInstance();
            var obj2 = ObjectHelper.NewInstance();
            dynamic conn = new APConnection("sibling", "object", obj1, "object", obj2);
            conn.field1 = Unique.String;
            conn.field2 = 123;

            var request = new CreateConnectionRequest() { Connection = conn };
            var response = await request.ExecuteAsync();
            ApiHelper.EnsureValidResponse(response);
            Assert.IsNotNull(response.Connection, "Connection in create connection response is null.");
            Assert.IsFalse(string.IsNullOrWhiteSpace(response.Connection.Id), "Connection id in response.connection is invalid.");
        }
コード例 #2
0
        public async Task CreateConnectionTest()
        {
            var obj1 = await ObjectHelper.CreateNewAsync();
            var obj2 = await ObjectHelper.CreateNewAsync();
            dynamic conn = new APConnection("sibling", "object", obj1.Id, "object", obj2.Id);
            conn.field1 = Unique.String;
            conn.field2 = 123;

            var request = new CreateConnectionRequest() { Connection = conn };
            var response = await request.ExecuteAsync();
            ApiHelper.EnsureValidResponse(response);
            Assert.IsNotNull(response.Connection, "Connection in create connection response is null.");
            Assert.IsFalse(string.IsNullOrWhiteSpace(response.Connection.Id), "Connection id in response.connection is invalid.");
            var endpoints = response.Connection.Endpoints.ToArray();
            Assert.IsNotNull(endpoints[0], "Endpoint A is null.");
            Assert.IsNotNull(endpoints[1], "Endpoint B is null.");
            Assert.IsTrue(endpoints.Select(x => x.ObjectId).Intersect(new[] { obj1.Id, obj2.Id }).Count() == 2);
        }
コード例 #3
0
        protected async override Task<Entity> CreateNewAsync(ApiOptions options)
        {
            // Handling for special case when endpoint contains a new object or device.
            // Since these cannot be created on the fly when creating a new connection.
            var endpoints = this.Endpoints.ToArray();
            for (int i = 0; i < endpoints.Length; i++)
            {
                if (endpoints[i].CreateEndpoint == false) continue;
                if (endpoints[i].Content.Type.Equals("user", StringComparison.OrdinalIgnoreCase) == true ||
                    endpoints[i].Content.Type.Equals("device", StringComparison.OrdinalIgnoreCase) == true)
                {
                    // Create the object
                    await endpoints[i].Content.SaveAsync(options: options);
                    // Update endpoint object ids
                    endpoints[i].ObjectId = endpoints[i].Content.Id;
                }
            }

            // Create a new object
            var request = new CreateConnectionRequest() { Connection = this };
            ApiOptions.Apply(request, options);
            var response = await request.ExecuteAsync();
            if (response.Status.IsSuccessful == false)
                throw response.Status.ToFault();
            Debug.Assert(response.Connection != null, "If status is successful, then created connection should not be null.");
            return response.Connection;
        }