예제 #1
0
        public void TestDeleteKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Delete.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "768672"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test delete key",
                Permissions = permissions
            };
            var req = new NewKeyRequest {
                KeyInfo = data
            };

            var rsp = client.Execute(req);

            Console.WriteLine("key to delete has added:   " + rsp.Body);
            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Key);

            var c1   = new DefaultOneNETClient(url, appkey, "");
            var req1 = new DeleteKeyRequest {
                KeyString = rsp.Data.Key
            };
            var rsp1 = c1.Execute(req1);

            Assert.IsFalse(rsp1.IsError);
        }
예제 #2
0
        public void TestAddKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Post.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "776938"
                        },
                        new KeyResource {
                            Dev_Id = "776941"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test key from C#",
                Permissions = permissions
            };
            var req = new NewKeyRequest {
                KeyInfo = data
            };

            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Key);
        }