コード例 #1
0
        public void TaskACLClient()
        {
            clearTest();
            // Add one object to be sure the test will not fail because index is empty
            var res = _index.AddObject(JObject.Parse(@"{""name"":""San Francisco"", ""population"":805235}"), "myID");

            _index.WaitTask(res["taskID"].ToString());

            var key = _client.AddUserKey(new String[] { "search" });

            System.Threading.Thread.Sleep(5000);
            Assert.IsFalse(string.IsNullOrWhiteSpace(key["key"].ToString()));

            key = _client.AddApiKey(new String[] { "search" });
            System.Threading.Thread.Sleep(5000);
            Assert.IsFalse(string.IsNullOrWhiteSpace(key["key"].ToString()));

            var getKey = _client.GetUserKeyACL(key["key"].ToString());

            Assert.AreEqual(key["key"], getKey["value"]);

            getKey = _client.GetApiKeyACL(key["key"].ToString());
            Assert.AreEqual(key["key"], getKey["value"]);

            var keys = _client.ListUserKeys();

            Assert.IsTrue(Include((JArray)keys["keys"], "value", key["key"].ToString()));

            keys = _client.ListApiKeys();
            Assert.IsTrue(Include((JArray)keys["keys"], "value", key["key"].ToString()));

            _client.UpdateApiKey(key["key"].ToString(), new String[] { "addObject" });
            System.Threading.Thread.Sleep(5000);

            getKey = _client.GetUserKeyACL(key["key"].ToString());
            Assert.AreEqual((string)getKey["acl"][0], "addObject");

            getKey = _client.GetApiKeyACL(key["key"].ToString());
            Assert.AreEqual((string)getKey["acl"][0], "addObject");

            _client.DeleteApiKey(key["key"].ToString());
            System.Threading.Thread.Sleep(5000);

            keys = _client.ListApiKeys();
            Assert.IsFalse(Include((JArray)keys["keys"], "value", key["key"].ToString()));
        }