Beispiel #1
0
        public void TestMethod1()
        {
            string fileContents = "This is a test file.";

            File.WriteAllText("testFile.txt", fileContents);
            Parse.ParseFile parseFile = new Parse.ParseFile("testFile.txt");
            Parse.ParseFile testFile  = localClient.CreateFile(parseFile);

            //Test to make sure test file is returned after creation.
            Assert.IsNotNull(testFile);

            Parse.ParseObject testObject = new Parse.ParseObject("ClassOne");
            testObject["foo"] = "bar";
            //Create a new object
            testObject = localClient.CreateObject(testObject);

            //Test to make sure we returned a ParseObject
            Assert.IsNotNull(testObject);
            //Test to make sure we were assigned an object id and the object was actually remotely created
            Assert.IsNotNull(testObject.objectId);

            //Search for the newly-created object on the server
            Parse.ParseObject searchObject = localClient.GetObject("ClassOne", testObject.objectId);
            //Test to make sure the same object was returned
            Assert.AreEqual(testObject.objectId, searchObject.objectId);

            testObject["foo"] = "notbar";
            //Change a value on the server
            localClient.UpdateObject(testObject);

            searchObject = localClient.GetObject("ClassOne", testObject.objectId);
            //Test to make sure the object was updated on the server
            Assert.AreEqual("notbar", searchObject["foo"]);

            //Test to make sure we can retrieve objects from Parse
            Parse.ParseObject[] objList = localClient.GetObjectsWithQuery("ClassOne", new { foo = "notbar" });
            Assert.IsNotNull(objList);

            //Test to make sure the same object was returned
            Assert.AreEqual(objList.First()["objectId"], testObject.objectId);



            //Cleanup
            localClient.DeleteObject(testObject);
        }
Beispiel #2
0
        public void TestGetObject()
        {
            Parse.ParseObject[] objects = new Parse.ParseObject[20];

            var levelName = string.Format("Level-{0}", random.Next());

            Console.WriteLine("Creating...");
            for (int i = 0; i < 20; i++)
            {
                var parseObject = new Parse.ParseObject("LevelScore");
                parseObject["Level"] = levelName;
                parseObject["Score"] = i;
                objects[i]           = localClient.CreateObject(parseObject);
                Assert.IsNotNull(objects[i].objectId);
            }


            // Retrieve the first 10 scores for this level
            Console.WriteLine("Retrieving...");
            foreach (var o in objects)
            {
                var parseObject = localClient.GetObject("LevelScore", o.objectId);

                Assert.IsNotNull(parseObject);
                Assert.AreEqual(o["Level"], parseObject["Level"]);
                Assert.AreEqual(o["Score"], parseObject["Score"]);
            }


            // Let's clean up
            Console.WriteLine("Cleaning up...");
            foreach (var o in objects)
            {
                localClient.DeleteObject(o);
            }
        }
Beispiel #3
0
        public void TestMethod1()
        {
            string fileContents      = "This is a test file.";
            string testFileLocalPath = "testFile.txt";

            File.WriteAllText(testFileLocalPath, fileContents);
            Parse.ParseFile parseFile = new Parse.ParseFile(testFileLocalPath);
            Parse.ParseFile testFile  = localClient.CreateFile(parseFile);
            //Test to make sure test file is returned after creation.
            Assert.IsNotNull(testFile);
            Console.WriteLine(testFileLocalPath + " uploaded to :" + testFile.Url);
            //access the file outside the parse api
            WebRequest fileRequest = WebRequest.Create(testFile.Url);

            fileRequest.Method = "GET";
            HttpWebResponse foundTestFile = (HttpWebResponse)fileRequest.GetResponse();

            // we don't have to stream the body content - just check the status code
            Assert.AreEqual(HttpStatusCode.OK, foundTestFile.StatusCode);

            Parse.ParseObject testObject = new Parse.ParseObject("ClassOne");
            testObject["foo"] = "bar";
            //Create a new object
            testObject = localClient.CreateObject(testObject);

            //Test to make sure we returned a ParseObject
            Assert.IsNotNull(testObject);
            //Test to make sure we were assigned an object id and the object was actually remotely created
            Assert.IsNotNull(testObject.objectId);

            //Search for the newly-created object on the server
            Parse.ParseObject searchObject = localClient.GetObject("ClassOne", testObject.objectId);
            //Test to make sure the same object was returned
            Assert.AreEqual(testObject.objectId, searchObject.objectId);

            testObject["foo"] = "notbar";
            //Change a value on the server
            localClient.UpdateObject(testObject);

            searchObject = localClient.GetObject("ClassOne", testObject.objectId);
            //Test to make sure the object was updated on the server
            Assert.AreEqual("notbar", searchObject["foo"]);

            //Test to make sure we can retrieve objects from Parse
            Parse.ParseObject[] objList = localClient.GetObjectsWithQuery("ClassOne", new { foo = "notbar" });
            Assert.IsNotNull(objList);

            // Test to make sure the same object was returned
            // We can't assume that the first object will be the one we've just
            // sent, since some other people may be running tests as well.
            Assert.IsTrue(objList.Any(x => (string)x["objectId"] == testObject.objectId));

            //Cleanup
            localClient.DeleteObject(testObject);

            localClient.DeleteFile(testFile);
            //verify that the deleted file is no longer accessible
            try {
                WebRequest deletedFileRequest = WebRequest.Create(testFile.Url);
                deletedFileRequest.Method = "GET";
                HttpWebResponse deletedTestFile = (HttpWebResponse)deletedFileRequest.GetResponse();
                Assert.That(deletedTestFile.StatusCode == HttpStatusCode.Forbidden || deletedTestFile.StatusCode == HttpStatusCode.NotFound);
            } catch (WebException accessException) {
                Assert.That(accessException.Message.Contains("403") || accessException.Message.Contains("404"));
            }
        }