public void Test_0100_LogOut_OK()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.setStandardResponse(client);

            // LogIn
            KiiUser user = KiiUser.LogIn("kii1234", "pass1234");

            Assert.AreEqual("abcd", user.ID);

            // check User
            user = KiiUser.CurrentUser;
            Assert.IsNotNull(user);

            // LogOut
            KiiUser.LogOut();

            // check User
            user = KiiUser.CurrentUser;
            Assert.IsNull(user);
        }
 public void TearDown()
 {
     if (KiiUser.CurrentUser != null)
     {
         KiiUser.LogOut();
     }
 }
Beispiel #3
0
        public void Test_0100_LogOut_OK()
        {
            this.setStandardResponse();

            KiiUser   target = null;
            Exception exp    = null;

            KiiUser.LogIn("kii1234", "pass1234", (KiiUser user, Exception e) => {
                target = user;
                exp    = e;
            });
            Assert.IsNotNull(target);
            Assert.AreEqual("abcd", target.ID);
            Assert.IsNull(exp);

            // check User
            KiiUser currentUser = KiiUser.CurrentUser;

            Assert.IsNotNull(currentUser);
            Assert.AreEqual("abcd", currentUser.ID);

            // LogOut
            KiiUser.LogOut();

            // check User
            currentUser = KiiUser.CurrentUser;
            Assert.IsNull(currentUser);
        }
        public void Test_AnonymousSync()
        {
            KiiUser.LogOut();
            string   topicName = "test_topic";
            KiiTopic topic     = Kii.Topic(topicName);

            topic.Exists();
        }
Beispiel #5
0
        public void RegisterGroupWithIDWhenNotLoggedinSyncTest()
        {
            KiiUser.LogOut();
            string groupID   = GetGroupID();
            string groupName = "group-" + DateTime.Now.Ticks.ToString();

            KiiGroup.RegisterGroupWithID(groupID, groupName, null);
        }
 public virtual void TearDown()
 {
     if (KiiUser.CurrentUser != null)
     {
         try {
             KiiUser.CurrentUser.Delete();
         } catch (Exception) {
             // Nothing to do
         }
     }
     KiiUser.LogOut();
 }
        public void SetUp()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory      = factory;
            Kii.AsyncHttpClientFactory = factory;
            client = (MockHttpClient)factory.Client;
            if (KiiUser.CurrentUser != null)
            {
                KiiUser.LogOut();
            }
        }
        public void Test_AnonymousASync()
        {
            KiiUser.LogOut();
            AddMockResponse(200, new string[] {}, null);
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(topics);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(InvalidOperationException), exception);
        }
        public void Test_AnonymousASync()
        {
            KiiUser.LogOut();
            string         topicName = "test_topic";
            KiiTopic       topic     = Kii.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.HasValue);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(InvalidOperationException), exception);
        }
Beispiel #10
0
        public void RegisterGroupWithIDWhenNotLoggedinASyncTest()
        {
            KiiUser.LogOut();
            string         groupID   = GetGroupID();
            string         groupName = "group-" + DateTime.Now.Ticks.ToString();
            CountDownLatch cd        = new CountDownLatch(1);
            KiiGroup       group     = null;
            Exception      exception = null;

            KiiGroup.RegisterGroupWithID(groupID, groupName, null, (KiiGroup result, Exception e) => {
                group     = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(group);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(InvalidOperationException), exception);
        }
Beispiel #11
0
        public void Test_0101_RemoveMyself_FromGroupMember()
        {
            // Create KiiUser for group member
            long    milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            string  memberName   = "kiiGroupMember-" + milliseconds;
            KiiUser member       = KiiUser.BuilderWithName(memberName).Build();

            member.Register("pass1234");
            string memberToken = KiiUser.AccessToken;

            // Create KiiUser for group member
            string  ownerName = "kiiGroupOwner-" + milliseconds;
            KiiUser owner     = KiiUser.BuilderWithName(ownerName).Build();

            owner.Register("pass1234");

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

            // Add member and save
            group.AddUser(member);
            group.Save();

            // Auth as member
            KiiUser.LogOut();
            KiiUser.LoginWithToken(memberToken);

            // Try to remove myself from the group
            group.RemoveUser(KiiUser.CurrentUser);
            group.Save();

            // 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(0, removeUsers.Count);
        }
Beispiel #12
0
        public void Test_FindUserByEmail_Asynchronous_ForEscapingAtmark()
        {
            // Create KiiUser to find
            string  emailDomain    = "@testkii.com";
            string  emailLocalPart = "kiiuserfindmail." + CurrentTimeMillis();
            string  emailAddress   = emailLocalPart + emailDomain;
            KiiUser findUser       = KiiUser.BuilderWithEmail(emailAddress).Build();

            findUser.Register("123456");
            string findUserUriStr = findUser.Uri.ToString();

            KiiUser.LogOut();

            // Create new user
            string uname = "kiiuserfindtest-" + CurrentTimeMillis();

            AppUtil.CreateNewUser(uname, "123456");

            CountDownLatch cd      = new CountDownLatch(1);
            KiiUser        outUser = null;
            Exception      outExp  = null;

            KiiUser.FindUserByEmail(emailAddress, (KiiUser retUser, Exception retExp) => {
                outUser = retUser;
                outExp  = retExp;
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.IsNull(outExp);
            Assert.IsNotNull(outUser);
            Assert.AreEqual(emailAddress, outUser.Email);
            Assert.AreEqual(findUserUriStr, outUser.Uri.ToString());
        }
Beispiel #13
0
        public void Test_FindUserByEmail_Synchronous_ForEscapingAtmark()
        {
            // Create KiiUser to find
            string  emailDomain    = "@testkii.com";
            string  emailLocalPart = "kiiuserfindmail." + CurrentTimeMillis();
            string  emailAddress   = emailLocalPart + emailDomain;
            KiiUser findUser       = KiiUser.BuilderWithEmail(emailAddress).Build();

            findUser.Register("123456");
            string findUserUriStr = findUser.Uri.ToString();

            KiiUser.LogOut();

            // Create new user
            string uname = "kiiuserfindtest-" + CurrentTimeMillis();

            AppUtil.CreateNewUser(uname, "123456");

            KiiUser searchUser = KiiUser.FindUserByEmail(emailAddress);

            Assert.IsNotNull(searchUser);
            Assert.AreEqual(emailAddress, searchUser.Email);
            Assert.AreEqual(findUserUriStr, searchUser.Uri.ToString());
        }
Beispiel #14
0
 public void TearDown()
 {
     KiiUser.LogOut();
 }
 public void Test_AnonymousSync()
 {
     KiiUser.LogOut();
     AddMockResponse(200, new string[] {}, null);
     Kii.ListTopics();
 }
Beispiel #16
0
 void OnGUI()
 {
     this.entryNameValue = gui.TextField(
         10,
         10,
         300,
         50,
         this.entryNameValue);
     this.versionValue = gui.TextField(
         10,
         70,
         300,
         50,
         this.versionValue);
     if (gui.Button(
             10,
             130,
             300,
             60,
             "ServerCodeEntry(entryName)"))
     {
         try {
             execEntry(Kii.ServerCodeEntry(this.entryNameValue));
         } catch (Exception e) {
             this.labelText = e.ToString();
         }
     }
     if (gui.Button(
             10,
             200,
             300,
             60,
             "ServerCodeEntry(entryName, version)"))
     {
         try {
             execEntry(Kii.ServerCodeEntry(this.entryNameValue,
                                           this.versionValue));
         } catch (Exception e) {
             this.labelText = e.ToString();
         }
     }
     if (gui.Button(
             10,
             270,
             145,
             60,
             "User login"))
     {
         this.labelText = "";
         string  username = "******" + DateTime.Now.Ticks.ToString();
         KiiUser user     = KiiUser.BuilderWithName(username).Build();
         user.Register("pa$$sword", (KiiUser u, Exception e1) => {
             if (e1 == null)
             {
                 this.labelText = "SUCCESS:\nuser="******"User logout"))
     {
         KiiUser.LogOut();
         this.labelText = "User logged out";
     }
     gui.TextField(
         10,
         350,
         300,
         120,
         this.labelText);
 }