public IDocument CreateTextDocument(IFolder parent, string name, string content)
        {
            IDictionary <string, object> props = new Dictionary <string, object>();

            props[PropertyIds.Name]         = name;
            props[PropertyIds.ObjectTypeId] = "cmis:document";

            IContentStream contentStream = ContentStreamUtils.CreateTextContentStream(name, content);

            return(parent.CreateDocument(props, contentStream, VersioningState.None));
        }
        public void TestUpdateContent()
        {
            IDocument doc = null;

            try
            {
                // create document
                string contentString1 = "11111";
                doc = CreateTextDocument(Session.GetRootFolder(), "test.txt", contentString1);
                Assert.IsNotNull(doc);

                // get content
                IContentStream content1 = doc.GetContentStream();
                Assert.IsNotNull(content1);
                Assert.IsNotNull(content1.Stream);

                Assert.AreEqual(contentString1, ConvertStreamToString(content1.Stream));

                // update content
                string contentString2 = "22222";
                doc.SetContentStream(ContentStreamUtils.CreateTextContentStream("test2.txt", contentString2), true);

                // get content again
                IContentStream content2 = doc.GetContentStream();
                Assert.IsNotNull(content2);
                Assert.IsNotNull(content2.MimeType);
                Assert.IsTrue(content2.MimeType.StartsWith("text/plain", System.StringComparison.InvariantCultureIgnoreCase));
                Assert.IsNotNull(content2.Stream);

                Assert.AreEqual(contentString2, ConvertStreamToString(content2.Stream));

                // delete the content stream
                doc.DeleteContentStream(true);
                Assert.IsNull(doc.ContentStreamLength);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Delete();
                    Assert.IsFalse(Session.Exists(doc));
                }
            }
        }
        public IDocument CreateTextDocument(IFolder parent, string name, string content)
        {
            IDictionary <string, object> props = new Dictionary <string, object>();

            props[PropertyIds.Name]         = name;
            props[PropertyIds.ObjectTypeId] = "cmis:document";

            IContentStream contentStream = ContentStreamUtils.CreateTextContentStream(name, content);

            IDocument newDoc = parent.CreateDocument(props, contentStream, VersioningState.None);


            Assert.IsNotNull(newDoc);
            Assert.AreEqual(BaseTypeId.CmisDocument, newDoc.BaseTypeId);
            Assert.AreEqual("cmis:document", newDoc.DocumentType.Id);
            Assert.AreEqual(name, newDoc.Name);
            Assert.AreEqual(parent.Id, newDoc.Parents[0].Id);
            Assert.IsNotNull(newDoc.CreationDate);
            Assert.IsNotNull(newDoc.CreatedBy);
            Assert.IsNotNull(newDoc.LastModificationDate);
            Assert.IsNotNull(newDoc.LastModifiedBy);

            return(newDoc);
        }
        public void TestVersioning()
        {
            IOperationContext noCacheOC = OperationContextUtils.CreateMaximumOperationContext();

            noCacheOC.CacheEnabled = false;

            IFolder   rootFolder = Session.GetRootFolder();
            IDocument doc        = null;

            try
            {
                // create document
                string         name1          = "versioned1.txt";
                IContentStream contentStream1 = ContentStreamUtils.CreateTextContentStream(name1, "v1");

                IDictionary <string, object> props = new Dictionary <string, object>();
                props[PropertyIds.Name]         = name1;
                props[PropertyIds.ObjectTypeId] = "VersionableType";

                doc = rootFolder.CreateDocument(props, contentStream1, VersioningState.Major);

                // create next version
                string         name2          = "versioned2.txt";
                IContentStream contentStream2 = ContentStreamUtils.CreateTextContentStream(name2, "v2");

                IObjectId pwcId = doc.CheckOut();
                IDocument pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);
                Assert.AreEqual(true, pwc.IsPrivateWorkingCopy);

                pwc.Rename(name2);

                IObjectId newVersId = pwc.CheckIn(true, null, contentStream2, "version 2");
                IDocument newVers   = (IDocument)Session.GetObject(newVersId, noCacheOC);

                Assert.AreEqual(name2, newVers.Name);
                Assert.AreEqual("v2", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(true, newVers.IsMajorVersion);

                IDocument latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // create next version
                string         name3          = "versioned3.txt";
                IContentStream contentStream3 = ContentStreamUtils.CreateTextContentStream(name3, "v3");

                pwcId = newVers.CheckOut();
                pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);

                pwc.Rename(name3);

                newVersId = pwc.CheckIn(true, null, contentStream3, "version 3");
                newVers   = (IDocument)Session.GetObject(newVersId);

                Assert.AreEqual(name3, newVers.Name);
                Assert.AreEqual("v3", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(true, newVers.IsMajorVersion);

                latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // create next (minor) version
                string         name4          = "versioned4.txt";
                IContentStream contentStream4 = ContentStreamUtils.CreateTextContentStream(name4, "v3.1");

                pwcId = newVers.CheckOut();
                pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);

                pwc.Rename(name4);

                newVersId = pwc.CheckIn(false, null, contentStream4, "version 3.1");
                newVers   = (IDocument)Session.GetObject(newVersId);

                Assert.AreEqual(name4, newVers.Name);
                Assert.AreEqual("v3.1", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(false, newVers.IsMajorVersion);

                latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // check version history
                IList <IDocument> versions = doc.GetAllVersions();
                Assert.AreEqual(4, versions.Count);

                Assert.AreEqual(latestVersion.Id, versions[0].Id);
                Assert.AreEqual(doc.Id, versions[3].Id);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Delete();
                    Assert.IsFalse(Session.Exists(doc));
                }
            }
        }