Пример #1
0
        public async Task testUploadPhoto()
        {
            string token = await getAppToken();

            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions", FBTestPhotoUploadPermissions);

            FBTestUser user = await createTestUser(parameters);

            StorageFolder appFolder =
                Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFile f = await appFolder.GetFileAsync(
                FBTestImagePath);

            IRandomAccessStreamWithContentType stream = await f.OpenReadAsync();

            Assert.IsNotNull(stream);

            FBMediaStream fbStream = new FBMediaStream(FBTestImageName,
                                                       stream);

            // Switch to user access token to post photo.
            parameters.Remove("access_token");
            parameters.Add("access_token", user.AccessToken);

            parameters.Add("source", fbStream);

            string path = "/" + user.Id + "/photos";

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBPhoto.FromJson));

            FBResult result = await sval.Post();

            Assert.IsTrue(result.Succeeded);

            try
            {
                FBPhoto pic = (FBPhoto)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                               "expected type (FBPhoto).");
            }
        }
Пример #2
0
        public async Task <FBResult> publishCustomStory(
            FBTestUser user,
            FBObject customObject
            )
        {
            PropertySet parameters = new PropertySet();
            string      path       = user.Id + "/logincs:verb";

            parameters.Add("noun", customObject.Id);
            parameters.Add("access_token", user.AccessToken);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            return(await sval.Post());
        }
Пример #3
0
        public async Task <FBResult> publishCustomUserObject(
            FBTestUser user
            )
        {
            PropertySet parameters = new PropertySet();
            string      path       = user.Id + "/objects/logincs:noun";

            Assert.IsNotNull(user.AccessToken);
            parameters.Add("access_token", user.AccessToken);
            parameters.Add("object", FBCustomObjectInstance);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            return(await sval.Post());
        }
Пример #4
0
        private async Task <FBTestUser> createTestUser(
            PropertySet Parameters
            )
        {
            FBTestUser user    = null;
            bool       success = false;

            // If you're creating/deleting test users frequently, like say in
            // a unit test suite, Facebook will occasionally fail this call with
            // the error code 1, type "OAuthException" and the message "An
            // unknown error occurred".  Throwing in a short delay and retrying
            // almost always alleviates the problem, so adding a few retries
            // here greatly increases the robustness of the test suite.
            for (int retries = 0; (success == false) && (retries < 5);
                 retries++)
            {
                string path = "/" + TestAppId + FBSDKTestUsersPath;

                FBSingleValue sval = new FBSingleValue(path, Parameters,
                                                       new FBJsonClassFactory(FBTestUser.FromJson));

                FBResult fbresult = await sval.Post();

                if ((fbresult.Succeeded == false) || (fbresult.Object == null))
                {
                    await Task.Delay(TEST_RETRY_DELAY);
                }
                else
                {
                    try
                    {
                        user    = (FBTestUser)fbresult.Object;
                        success = true;
                    }
                    catch (InvalidCastException)
                    {
                        Assert.IsTrue(false, "Item returned is not expected type" +
                                      " (FBTestUser)");
                    }
                }
            }

            Assert.IsNotNull(user);

            return(user);
        }
Пример #5
0
        private async Task <FBObject> postToFeed(
            FBTestUser User,
            string Message
            )
        {
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", User.AccessToken);
            parameters.Add("message", Message);

            string path = "/" + User.Id + FBFeedPath;

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            FBResult fbresult = await sval.Post();

            return((FBObject)fbresult.Object);
        }
Пример #6
0
        public async Task testLikeSomething()
        {
            string token = await getAppToken();

            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions",
                           "public_profile,publish_actions,user_photos");

            FBTestUser user = await createTestUser(parameters);

            string path = user.Id + "/og.likes";

            // Because *everybody* likes these, amirite?
            string likedObject =
                Uri.EscapeUriString("http://en.wikipedia.org/wiki/Brussels_sprout");

            parameters.Add("object", likedObject);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            FBResult result = await sval.Post();

            Assert.IsTrue(result.Succeeded);

            try
            {
                FBObject like = (FBObject)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                               "expected type (FBObject).");
            }
        }
Пример #7
0
        public async Task testLikeSomething()
        {
            string token = await getAppToken();
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions",
                "public_profile,publish_actions,user_photos");

            FBTestUser user = await createTestUser(parameters);

            string path = user.Id + "/og.likes";

            // Because *everybody* likes these, amirite?
            string likedObject =
                Uri.EscapeUriString("http://en.wikipedia.org/wiki/Brussels_sprout");

            parameters.Add("object", likedObject);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            FBResult result = await sval.Post();
            Assert.IsTrue(result.Succeeded);

            try
            {
                FBObject like = (FBObject)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                    "expected type (FBObject).");
            }
        }
Пример #8
0
        public async Task testUploadPhoto()
        {
            string token = await getAppToken();
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions", FBTestPhotoUploadPermissions);

            FBTestUser user = await createTestUser(parameters);

            StorageFolder appFolder = 
                Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFile f = await appFolder.GetFileAsync(
                FBTestImagePath);
            IRandomAccessStreamWithContentType stream = await f.OpenReadAsync();
            Assert.IsNotNull(stream);

            FBMediaStream fbStream = new FBMediaStream(FBTestImageName, 
                stream);

            // Switch to user access token to post photo.
            parameters.Remove("access_token");
            parameters.Add("access_token", user.AccessToken);

            parameters.Add("source", fbStream);

            string path = "/" + user.Id + "/photos";

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBPhoto.FromJson));

            FBResult result = await sval.Post();
            Assert.IsTrue(result.Succeeded);

            try
            {
                FBPhoto pic = (FBPhoto)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                    "expected type (FBPhoto).");
            }
        }
Пример #9
0
        public async Task<FBResult> publishCustomStory(
            FBTestUser user,
            FBObject customObject
            )
        {
            PropertySet parameters = new PropertySet();
            string path = user.Id + "/logincs:verb";

            parameters.Add("noun", customObject.Id);
            parameters.Add("access_token", user.AccessToken);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            return await sval.Post();
        }
Пример #10
0
        public async Task<FBResult> publishCustomUserObject(
            FBTestUser user
            )
        {
            PropertySet parameters = new PropertySet();
            string path = user.Id + "/objects/logincs:noun";

            Assert.IsNotNull(user.AccessToken);
            parameters.Add("access_token", user.AccessToken);
            parameters.Add("object", FBCustomObjectInstance);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            return await sval.Post();
        }
Пример #11
0
        private async Task<FBObject> postToFeed(
            FBTestUser User,
            string Message
            )
        {
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", User.AccessToken);
            parameters.Add("message", Message);

            string path = "/" + User.Id + FBFeedPath;

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            FBResult fbresult = await sval.Post();

            return (FBObject)fbresult.Object;
        }
Пример #12
0
        private async Task<FBTestUser> createTestUser(
            PropertySet Parameters 
            )
        {
            FBTestUser user = null;
            bool success = false;

            // If you're creating/deleting test users frequently, like say in
            // a unit test suite, Facebook will occasionally fail this call with 
            // the error code 1, type "OAuthException" and the message "An 
            // unknown error occurred".  Throwing in a short delay and retrying
            // almost always alleviates the problem, so adding a few retries
            // here greatly increases the robustness of the test suite.
            for (int retries = 0; (success == false) && (retries < 5); 
                retries++)
            {
                string path = "/" + TestAppId + FBSDKTestUsersPath;

                FBSingleValue sval = new FBSingleValue(path, Parameters,
                    new FBJsonClassFactory(FBTestUser.FromJson));

                FBResult fbresult = await sval.Post();
    
                if ((fbresult.Succeeded == false) || (fbresult.Object == null))
                {
                    await Task.Delay(TEST_RETRY_DELAY);
                }
                else
                {
                    try
                    {
                        user = (FBTestUser)fbresult.Object;
                        success = true;
                    }
                    catch (InvalidCastException)
                    {
                        Assert.IsTrue(false, "Item returned is not expected type" +
                            " (FBTestUser)");
                    }
                }
            }

            Assert.IsNotNull(user);

            return user;
        }