public void TestAsyncGetAuthenticationToken()
        {
            BoxManager manager = new BoxManager(ApplicationKey, ServiceUrl, null);
            string ticket;
            ManualResetEvent wait = new ManualResetEvent(false);
            bool callbackWasExecuted = false;
            const int state = 874532489;

            OperationFinished<GetAuthenticationTokenResponse> callback = resp =>
                                                                         	{
                                                                                Assert.IsNull(resp.Error);

                                                                                Assert.IsInstanceOfType(typeof(int), resp.UserState);

                                                                                Assert.AreEqual(state, (int) resp.UserState);

                                                                                Assert.AreEqual(GetAuthenticationTokenStatus.Successful, resp.Status);

                                                                                Assert.IsNotNull(resp.AuthenticationToken);
                                                                                Assert.IsNotNull(resp.AuthenticatedUser);

                                                                                Assert.IsNotNull(resp.AuthenticatedUser.Email);
                                                                                Assert.IsNotNull(resp.AuthenticatedUser.Login);
                                                                                StringAssert.IsMatch(Login, resp.AuthenticatedUser.Login);
                                                                                Assert.AreNotEqual(0, resp.AuthenticatedUser.AccessID);
                                                                                Assert.AreNotEqual(0, resp.AuthenticatedUser.ID);
                                                                                //Assert.AreNotEqual(0, resp.AuthenticatedUser.MaxUploadSize);
                                                                                Assert.AreNotEqual(0, resp.AuthenticatedUser.SpaceAmount);
                                                                                Assert.AreNotEqual(0, resp.AuthenticatedUser.SpaceUsed);

                                                                         		callbackWasExecuted = true;
                                                                         		wait.Reset();
                                                                         	};

            manager.GetTicket(out ticket);

            SubmitAuthenticationInformation(ticket);

            manager.GetAuthenticationToken(ticket, callback, state);
            wait.WaitOne(30000);

            Assert.IsTrue(callbackWasExecuted, "Callback was not executed. The operation has timed out");
        }
        protected void InitializeContext()
        {
            BoxManager manager = new BoxManager(ApplicationKey, ServiceUrl, null);
            string ticket;
            string token;
            User user;

            manager.GetTicket(out ticket);

            SubmitAuthenticationInformation(ticket);

            manager.GetAuthenticationToken(ticket, out token, out user);

            Context = new TestContext
                      	{
                      		AuthenticatedUser = user,
                      		Manager = manager,
                      		Ticket = ticket,
                      		Token = token
                      	};
        }
        public void TestAsyncGetAuthenticationTokenIfUserIsNotLoggedIn()
        {
            BoxManager manager = new BoxManager(ApplicationKey, ServiceUrl, null);
            string ticket;
            ManualResetEvent wait = new ManualResetEvent(false);
            bool callbackWasExecuted = false;
            const int state = 874524489;

            OperationFinished<GetAuthenticationTokenResponse> callback = resp =>
                                                                         	{
                                                                         		Assert.IsNull(resp.Error);

                                                                         		Assert.IsInstanceOfType(typeof (int), resp.UserState);

                                                                         		Assert.AreEqual(state, (int) resp.UserState);

                                                                                Assert.AreEqual(GetAuthenticationTokenStatus.NotLoggedID, resp.Status);

                                                                                Assert.IsEmpty(resp.AuthenticationToken);
                                                                                Assert.IsNull(resp.AuthenticatedUser);

                                                                         		callbackWasExecuted = true;
                                                                         		wait.Reset();
                                                                         	};

            manager.GetTicket(out ticket);

            manager.GetAuthenticationToken(ticket, callback, state);
            wait.WaitOne(30000);

            Assert.IsTrue(callbackWasExecuted, "Callback was not executed. The operation has timed out");
        }
        public void TestSyncGetAuthenticationTokenWithWrongTicket()
        {
            BoxManager manager = new BoxManager(ApplicationKey, ServiceUrl, null);
            string ticket;
            string token;
            User user;

            manager.GetTicket(out ticket);

            SubmitAuthenticationInformation(ticket);

            GetAuthenticationTokenStatus status = manager.GetAuthenticationToken(Guid.Empty.ToString(), out token, out user);

            Assert.AreEqual(GetAuthenticationTokenStatus.Failed, status);

            Assert.IsEmpty(token);
            Assert.IsNull(user);
        }
        public void TestSyncGetAuthenticationTokenIfUserIsNotLoggedIn()
        {
            BoxManager manager = new BoxManager(ApplicationKey, ServiceUrl, null);
            string ticket;
            string token;
            User user;

            manager.GetTicket(out ticket);

            GetAuthenticationTokenStatus status = manager.GetAuthenticationToken(ticket, out token, out user);

            Assert.AreEqual(GetAuthenticationTokenStatus.NotLoggedID, status);

            Assert.IsEmpty(token);
            Assert.IsNull(user);
        }
        public void TestSyncGetAuthenticationToken()
        {
            BoxManager manager = new BoxManager(ApplicationKey, ServiceUrl, null);
            string ticket;
            string token;
            User user;

            manager.GetTicket(out ticket);

            SubmitAuthenticationInformation(ticket);

            GetAuthenticationTokenStatus status = manager.GetAuthenticationToken(ticket, out token, out user);

            Assert.AreEqual(GetAuthenticationTokenStatus.Successful, status);

            Assert.IsNotNull(token);
            Assert.IsNotNull(user);

            Assert.IsNotNull(user.Email);
            Assert.IsNotNull(user.Login);
            StringAssert.IsMatch(Login, user.Login);
            Assert.AreNotEqual(0, user.AccessID);
            Assert.AreNotEqual(0, user.ID);
            //Assert.AreNotEqual(0, user.MaxUploadSize);
            Assert.AreNotEqual(0, user.SpaceAmount);
            Assert.AreNotEqual(0, user.SpaceUsed);
        }
        public void TestAsyncGetAuthenticationTokenWithNoCallbackDelegate()
        {
            BoxManager manager = new BoxManager(ApplicationKey, ServiceUrl, null);
            string ticket;

            manager.GetTicket(out ticket);

            SubmitAuthenticationInformation(ticket);

            try
            {
                manager.GetAuthenticationToken(ticket, null);

                Assert.Fail("GetAuthenticationToken(ticket, null) has to fail");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(ArgumentException), ex);
            }
        }