Example #1
0
        /// <summary>
        /// Creates KiiGroup by Uri
        /// </summary>
        /// <remarks>
        /// To get the latest information from server, need to call Refresh().
        /// </remarks>
        /// <returns>
        /// KiiGroup instance.
        /// </returns>
        /// <param name='uri'>
        /// Uri of KiiGroup
        /// </param>
        /// <exception cref='ArgumentException'>
        /// Is thrown when Uri is invalid.
        /// </exception>
        public static KiiGroup CreateByUri(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentException(ErrorInfo.KIIGROUP_URL_IS_NULL);
            }
            // check scheme
            string scheme = uri.Scheme;

            if (scheme != ConstantValues.URI_SCHEME)
            {
                throw new ArgumentException(ErrorInfo.KIIGROUP_URI_NO_SUPPORT + uri);
            }

            string authority = uri.Authority;

            if (authority != "groups")
            {
                throw new ArgumentException(ErrorInfo.KIIGROUP_URI_NO_SUPPORT + uri);
            }
            // check segments
            string[] segments = uri.Segments;
            if (segments.Length != 2)
            {
                throw new ArgumentException(ErrorInfo.KIIGROUP_URI_NO_SUPPORT + uri);
            }
            KiiGroup group = new KiiGroup(null, null);

            group.mId = Utils.RemoveLastSlash(segments[1]);
            return(group);
        }
Example #2
0
        public void Test_0205_Refresh_broken_no_owner()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(200, "{" +
                               "\"groupID\" : \"90def9aa-565e-4037-bde8-3a8704c7d806\"," +
                               "\"name\" : \"testing group\"}");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(refreshedException);
            Assert.IsNotNull(refreshedGroup);

            Assert.AreEqual("testing group", refreshedGroup.Name);
            Assert.AreEqual("90def9aa-565e-4037-bde8-3a8704c7d806", refreshedGroup.ID);
            Assert.IsNull(refreshedGroup.Owner);
        }
Example #3
0
        public void Test_0300_Delete()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(204, "");

            bool      done             = false;
            KiiGroup  deletedGroup     = null;
            Exception deletedException = null;

            group.Delete((KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                deletedGroup     = retGroup;
                deletedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(deletedException);
            Assert.IsNotNull(deletedGroup);

            Assert.IsNull(group.Uri);
        }
Example #4
0
        public void Test_0202_Refresh_broken_json()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(200, "broken");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is IllegalKiiBaseObjectFormatException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("group1234", refreshedGroup.ID);
        }
Example #5
0
        public void Test_0203_Refresh_broken_no_groupId()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(200, "{" +
                               "\"name\" : \"testing group\"," +
                               "\"owner\" : \"e3137ebe-2874-4d02-b7ef-6780bf8ecc1d\"}");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is IllegalKiiBaseObjectFormatException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("group1234", refreshedGroup.ID);
        }
Example #6
0
        public void Test_0103_ListMembers_empty_member()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // Set Response of no entry to throw exception from ListMembers request
            client.AddResponse(200, "{\"members\":[]}");

            bool            done          = false;
            IList <KiiUser> listMembers   = null;
            Exception       listException = null;

            group.ListMembers((IList <KiiUser> retUserList, Exception retExp) =>
            {
                done          = true;
                listMembers   = retUserList;
                listException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(listException);
            Assert.IsNotNull(listMembers);

            Assert.AreEqual(0, listMembers.Count);
        }
Example #7
0
        public void Test_0200_Refresh()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            this.SetStandardRefreshResponse();

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(refreshedException);
            Assert.IsNotNull(refreshedGroup);

            Assert.AreEqual("testing group", group.Name);
            Assert.AreEqual("kiicloud://users/e3137ebe-2874-4d02-b7ef-6780bf8ecc1d", group.Owner.Uri.ToString());
        }
Example #8
0
        public void TestGetIDAfterCreateFromURI()
        {
            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/dummyID"));

            Assert.IsNotNull(group.ID);
            Assert.AreEqual("dummyID", group.ID);
        }
Example #9
0
        public void Test_0000_CreateByUri()
        {
            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/abcd"));

            Assert.IsNotNull(group);
            Assert.AreEqual(null, group.Name);
        }
        public void Test_0504_remove_member()
        {
            // Create test user for group owner
            string  userID = TextUtils.generateUUID();
            KiiUser user   = KiiUser.CreateByUri(new Uri("kiicloud://users/" + userID));

            SDKTestHack.SetField(Kii.Instance, "mLoginUser", user);
            string authToken = TextUtils.generateUUID();

            KiiCloudEngine.UpdateAccessToken(authToken);

            // Prepare group
            string   groupName = TextUtils.randomAlphaNumeric(10);
            string   groupID   = TextUtils.randomAlphaNumeric(26);
            KiiGroup group     = Kii.Group(groupName);

            SDKTestHack.SetField(group, "mId", groupID);
            SDKTestHack.SetField(group, "mOwnerId", userID);

            // Prepare KiiUser for member
            string  memberID = TextUtils.generateUUID();
            KiiUser member   = KiiUser.CreateByUri(new Uri("kiicloud://users/" + memberID));

            group.RemoveUser(member);

            // Check value
            HashSet <KiiUser> addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            HashSet <KiiUser> removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");

            Assert.AreEqual(0, addUsers.Count);
            Assert.AreEqual(1, removeUsers.Count);

            // Prepare mock response for adding user
            client.AddResponse(204, "");

            // Save group
            group.Save();

            // Verify request
            Assert.AreEqual(1, client.RequestUrl.Count);
            Assert.AreEqual(1, client.RequestHeader.Count);
            string requestUrl = AppUtil.getUrlOfSite(AppConst.APP_SITE, AppConst.APP_ID, "groups", groupID, "members", memberID);

            Assert.AreEqual(requestUrl, client.RequestUrl[0]);
            Assert.AreEqual("DELETE", client.RequestMethod[0].ToString());
            IList <MockHttpHeaderList> headers = client.RequestHeader;

            Assert.AreEqual(AppConst.APP_ID, client.RequestHeader[0]["X-Kii-AppID"]);
            Assert.AreEqual(AppConst.APP_KEY, client.RequestHeader[0]["X-Kii-AppKey"]);
            Assert.AreEqual("Bearer " + authToken, client.RequestHeader[0]["Authorization"]);
            Assert.AreEqual(null, client.RequestBody[0]);

            // Verify
            Assert.AreEqual(groupID, group.ID);

            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(0, addUsers.Count);
            Assert.AreEqual(0, removeUsers.Count);
        }
        public void Test_GroupScopeFalseASync()
        {
            LogIn("test-user-00001");
            client.AddResponse(new NotFoundException("", null, "", NotFoundException.Reason.TOPIC_NOT_FOUND));
            string         groupID   = "test_group";
            string         topicName = "test_topic";
            KiiTopic       topic     = KiiGroup.GroupWithID(groupID).Topic(topicName);
            CountDownLatch cd        = new CountDownLatch(1);
            bool?          existence = null;
            Exception      exception = null;

            topic.Exists((bool?b, Exception e) => {
                existence = b;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsFalse(existence.Value);
            Assert.IsNull(exception);
            Assert.AreEqual(KiiHttpMethod.HEAD, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "groups", groupID, "topics", topicName), client.RequestUrl [0]);
        }
        public void Test_0023_Save_update_add_remove_server_error_partial()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.RemoveUser(user);

            user = KiiUser.CreateByUri(new Uri("kiicloud://users/user5678"));
            group.AddUser(user);

            // set Response
            client.RequestUrl.Clear();
            this.SetStandardSaveResponse(client);
            client.AddResponse(new CloudException(400, "{}"));

            try
            {
                group.Save();
            }
            catch (GroupOperationException e)
            {
                Assert.AreEqual(0, e.AddFailedUsers.Count);
                Assert.AreEqual(1, e.RemoveFailedUsers.Count);
            }
        }
Example #13
0
        public void Test_0403_Group_member_empty()
        {
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.US);
            KiiGroup group = Kii.Group("group1", new List <KiiUser>());

            Assert.AreEqual("group1", group.Name);
        }
Example #14
0
        public void Test_0402_Group_member_null()
        {
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.US);
            KiiGroup group = Kii.Group("group1", null);

            Assert.AreEqual("group1", group.Name);
        }
Example #15
0
        public void Test_0100_ListMembers()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            this.SetStandardListResponse();

            bool            done          = false;
            IList <KiiUser> listMembers   = null;
            Exception       listException = null;

            group.ListMembers((IList <KiiUser> retUserList, Exception retExp) =>
            {
                done          = true;
                listMembers   = retUserList;
                listException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(listException);
            Assert.IsNotNull(listMembers);

            Assert.AreEqual(4, listMembers.Count);
        }
Example #16
0
        public void TestGetIDAfterSave()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            MockHttpClient client = factory.Client;

            // login
            client.AddResponse(200, "{" +
                               "\"id\" : \"user1234\"," +
                               "\"access_token\" : \"cdef\"," +
                               "\"expires_in\" : 9223372036854775}");
            KiiUser.LogIn("kii1234", "pass1234");

            client.AddResponse(200, "{" +
                               "\"groupID\" : \"dummyId\"" +
                               "}");
            KiiGroup group = Kii.Group("MyGroup");

            group.Save();

            Assert.AreEqual("dummyId", group.ID);
            Assert.AreEqual("MyGroup", group.Name);
        }
Example #17
0
        public void Test_0101_ListMembers_NoID()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("newGroup");

            // set Response
            this.SetStandardListResponse();

            bool            done          = false;
            IList <KiiUser> listMembers   = null;
            Exception       listException = null;

            group.ListMembers((IList <KiiUser> retUserList, Exception retExp) =>
            {
                done          = true;
                listMembers   = retUserList;
                listException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(listException);
            Assert.IsTrue(listException is InvalidOperationException);
            Assert.IsNull(listMembers);
        }
Example #18
0
        public void Test_0401_ChangeName_null()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(204, "");

            bool      done             = false;
            KiiGroup  changedGroup     = null;
            Exception changedException = null;

            group.ChangeName(null, (KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                changedGroup     = retGroup;
                changedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(changedException);
            Assert.IsTrue(changedException is ArgumentException);
            Assert.IsNotNull(changedGroup);
            Assert.AreEqual("group1234", changedGroup.ID);
        }
Example #19
0
        public void Test_0105_ListMembers_empty_userId()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // Set Response of empty user ID to throw exception from ListMembers request
            client.AddResponse(200, "{\"members\":[" +
                               "{\"userID\":\"\"}" +
                               "]}");

            bool            done          = false;
            IList <KiiUser> listMembers   = null;
            Exception       listException = null;

            group.ListMembers((IList <KiiUser> retUserList, Exception retExp) =>
            {
                done          = true;
                listMembers   = retUserList;
                listException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(listException);
            Assert.IsTrue(listException is IllegalKiiBaseObjectFormatException);
            Assert.IsNull(listMembers);
        }
Example #20
0
        public void Test_0402_ChangeName_no_id()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("groupName");

            // set Response
            client.AddResponse(204, "");

            bool      done             = false;
            KiiGroup  changedGroup     = null;
            Exception changedException = null;

            group.ChangeName("newGroupName", (KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                changedGroup     = retGroup;
                changedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(changedException);
            Assert.IsTrue(changedException is InvalidOperationException);
            Assert.IsNotNull(changedGroup);
            Assert.AreEqual("groupName", changedGroup.Name);
        }
Example #21
0
        public void Test_0201_Refresh_no_ID()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("newGroup");

            // set Response
            this.SetStandardRefreshResponse();

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is InvalidOperationException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("newGroup", refreshedGroup.Name);
        }
Example #22
0
        public void Test_0001_Save_server_error()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("testGroup");

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.AddUser(user);

            // set Response
            client.AddResponse(new CloudException(400, "{ \"errorCode\" : \"INVALID_INPUT_DATA\", \"message\" : \"There are validation errors\", \"suppressed\" : [ ]}"));

            bool      done           = false;
            KiiGroup  savedGroup     = null;
            Exception savedException = null;

            group.Save((KiiGroup retGroup, Exception retExp) =>
            {
                done           = true;
                savedGroup     = retGroup;
                savedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(savedException);
            Assert.IsTrue(savedException is GroupOperationException);
            Assert.IsNotNull(savedGroup);
            Assert.AreEqual("testGroup", savedGroup.Name);
        }
Example #23
0
        public void Test_0000_Save()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("testGroup");

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.AddUser(user);

            // set Response
            this.SetStandardSaveResponse();

            bool      done           = false;
            KiiGroup  savedGroup     = null;
            Exception savedException = null;

            group.Save((KiiGroup retGroup, Exception retExp) =>
            {
                done           = true;
                savedGroup     = retGroup;
                savedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(savedException);
            Assert.AreEqual("0c4375c7-16f5-4ce6-9cd3-ec24bc0519e9", savedGroup.ID);
        }
Example #24
0
        public void Test_0403_ChangeName_server_error()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            group.Name = "testGroup";

            // set Response
            client.AddResponse(new CloudException(400, "{ \"errorCode\" : \"INVALID_INPUT_DATA\", \"message\" : \"There are validation errors\", \"suppressed\" : [ ]}"));

            bool      done             = false;
            KiiGroup  changedGroup     = null;
            Exception changedException = null;

            group.ChangeName("newGroupName", (KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                changedGroup     = retGroup;
                changedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(changedException);
            Assert.IsTrue(changedException is CloudException);
            Assert.IsNotNull(changedGroup);
            Assert.AreEqual("group1234", changedGroup.ID);
            Assert.AreEqual("testGroup", changedGroup.Name);
        }
Example #25
0
        public void Test_0204_Refresh_broken_no_name()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(200, "{" +
                               "\"groupID\" : \"90def9aa-565e-4037-bde8-3a8704c7d806\"," +
                               "\"owner\" : \"e3137ebe-2874-4d02-b7ef-6780bf8ecc1d\"}");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is IllegalKiiBaseObjectFormatException);
            Assert.IsNotNull(refreshedGroup);
            // We won't rollback the id change after the exception happens.
            Assert.AreEqual("90def9aa-565e-4037-bde8-3a8704c7d806", refreshedGroup.ID);
        }
Example #26
0
        public void Test_0002_Save_broken_json()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("testGroup");

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.AddUser(user);

            // set Response
            client.AddResponse(200, "{}");

            bool      done           = false;
            KiiGroup  savedGroup     = null;
            Exception savedException = null;

            group.Save((KiiGroup retGroup, Exception retExp) =>
            {
                done           = true;
                savedGroup     = retGroup;
                savedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(savedException);
            Assert.IsTrue(savedException is IllegalKiiBaseObjectFormatException);
            Assert.IsNotNull(savedGroup);
            Assert.AreEqual("testGroup", savedGroup.Name);
        }
Example #27
0
        public void Test_0206_Refresh_server_error()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(new CloudException(400, "{ \"errorCode\" : \"INVALID_INPUT_DATA\", \"message\" : \"There are validation errors\", \"suppressed\" : [ ]}"));

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is CloudException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("group1234", refreshedGroup.ID);
        }
Example #28
0
        public void Test_0012_Save_update_delete()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.RemoveUser(user);


            // set Response
            client.RequestUrl.Clear();
            this.SetStandardSaveResponse();

            bool      done           = false;
            KiiGroup  savedGroup     = null;
            Exception savedException = null;

            group.Save((KiiGroup retGroup, Exception retExp) =>
            {
                done           = true;
                savedGroup     = retGroup;
                savedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(savedException);
            Assert.IsNotNull(savedGroup);

            Assert.AreEqual(1, client.RequestUrl.Count);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/groups/group1234/members/user1234", client.RequestUrl [0]);
        }
Example #29
0
        public void Test_0301_Delete_no_ID()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("newGroup");

            // set Response
            client.AddResponse(204, "");

            bool      done             = false;
            KiiGroup  deletedGroup     = null;
            Exception deletedException = null;

            group.Delete((KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                deletedGroup     = retGroup;
                deletedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(deletedException);
            Assert.IsTrue(deletedException is InvalidOperationException);
            Assert.IsNotNull(deletedGroup);
            Assert.AreEqual("newGroup", deletedGroup.Name);
        }
Example #30
0
        public void Test_1_2_GroupWithID_ExistsInCloud_ListMembers()
        {
            // mock list members response.
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;
            MockHttpClient client = (MockHttpClient)factory.Client;

            client.AddResponse(200, "{" +
                               "\"members\":[{" +
                               "\"userID\" : \"dummyUser\"" +
                               "}]" +
                               "}");

            // create group
            string   groupId = "dummyId";
            KiiGroup group   = KiiGroup.GroupWithID(groupId);

            // list members
            IList <KiiUser> members = group.ListMembers();

            Assert.AreEqual(1, members.Count);

            //check request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId", "members");

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]);
            MockHttpHeaderList headerList = client.RequestHeader[0];

            Assert.AreEqual("appId", headerList["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]);
            Assert.AreEqual("Bearer token1234", client.RequestHeader[0]["Authorization"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }