///////////////////////////////////////////////////////////////////////////// /// <summary> /// Tests word processor document creation and deletion /// </summary> [Test] public void CreateDocumentTest() { //set up a text/plain file string tempFile = Directory.GetCurrentDirectory(); tempFile = tempFile + Path.DirectorySeparatorChar + "docs_live_test.txt"; //Console.WriteLine("Creating temporary document at: " + tempFile); using (StreamWriter sw = File.CreateText(tempFile)) { sw.WriteLine("My name is Ozymandias, king of kings:"); sw.WriteLine("Look on my works, ye mighty, and despair!"); sw.Close(); } DocumentsService service = new DocumentsService(this.ApplicationName); if (this.userName != null) { service.Credentials = new GDataCredentials(this.userName, this.passWord); } service.RequestFactory = this.factory; //pick a unique document name string documentTitle = "Ozy " + Guid.NewGuid().ToString(); DocumentEntry entry = service.UploadDocument(tempFile, documentTitle); Assert.IsNotNull(entry, "Should get a valid entry back from the server."); Assert.AreEqual(documentTitle, entry.Title.Text, "Title on document should be what we provided."); Assert.IsTrue(entry.IsDocument, "What we uploaded should come back as a text document type."); Assert.IsTrue(entry.AccessControlList != null, "We should get an ACL list back"); try { Uri uri = new Uri(entry.AccessControlList); Assert.IsTrue(uri.AbsoluteUri == entry.AccessControlList); } catch (Exception e) { throw e; } //try to delete the document we created entry.Delete(); //clean up the file we created File.Delete(tempFile); }
[Test] public void CreateSpreadsheetTest() { //set up a text/csv file string tempFile = Directory.GetCurrentDirectory(); tempFile = tempFile + Path.DirectorySeparatorChar + "docs_live_test.csv"; //Console.WriteLine("Creating temporary document at: " + tempFile); using (StreamWriter sw = File.CreateText(tempFile)) { sw.WriteLine("foo,bar,baz"); sw.WriteLine("1,2,3"); sw.Close(); } DocumentsService service = new DocumentsService(this.ApplicationName); if (this.userName != null) { service.Credentials = new GDataCredentials(this.userName, this.passWord); } service.RequestFactory = this.factory; //pick a unique document name string documentTitle = "Simple " + Guid.NewGuid().ToString(); DocumentEntry entry = service.UploadDocument(tempFile, documentTitle); Assert.IsNotNull(entry, "Should get a valid entry back from the server."); Assert.AreEqual(documentTitle, entry.Title.Text, "Title on document should be what we provided."); Assert.IsTrue(entry.IsSpreadsheet, "What we uploaded should come back as a spreadsheet document type."); //try to delete the document we created entry.Delete(); //clean up the file we created File.Delete(tempFile); }