Smartsheet.Api.Internal.AssociatedDiscussionResourcesImpl.CreateDiscussion C# (CSharp) Method

CreateDiscussion() private method

private CreateDiscussion ( long objectId, Api.Models.Discussion discussion ) : Api.Models.Discussion
objectId long
discussion Api.Models.Discussion
return Api.Models.Discussion
        public virtual Discussion CreateDiscussion(long objectId, Discussion discussion)
        {
            throw new System.NotSupportedException();
        }

Usage Example

Example #1
0
        public virtual void TestCreateDiscussion()
        {
            server.setResponseBody("../../../TestSDK/resources/createDiscussion.json");

            // Test success
            IList <Comment> comments = new List <Comment>();
            Comment         comment  = new Comment();

            comment.Text        = "This is a test.";
            comment.Attachments = new List <Attachment>();
            comments.Add(comment);
            Discussion discussion = new Discussion();

            discussion.Title              = "New Discussion";
            discussion.Comments           = comments;
            discussion.LastCommentedUser  = new User();
            discussion.LastCommentedAt    = DateTime.Now;
            discussion.CommentAttachments = new List <Attachment>();
            Discussion newDiscussion = discussionResources.CreateDiscussion(1234L, discussion);

            Assert.NotNull(newDiscussion.Comments);
            Assert.True(newDiscussion.Comments.Count == 1);
            Assert.AreEqual("Brett Batie", newDiscussion.Comments[0].CreatedBy.Name);
            Assert.AreEqual("*****@*****.**", newDiscussion.Comments[0].CreatedBy.Email);


            // Test failure - CreatedBy not allowed & only one comment can be added when creating a discussion.
            server.Status = HttpStatusCode.BadRequest;
            server.setResponseBody("../../../TestSDK/resources/createDiscussion_1032.json");
            comment = new Comment();
            User user = new User();

            user.Name         = "John Doe";
            user.Email        = "*****@*****.**";
            comment.CreatedBy = user;
            comment.Text      = "This is a test.";
            comments.Add(comment);
            discussion.Comments = comments;
            try
            {
                discussionResources.CreateDiscussion(1234L, discussion);
                Assert.Fail("An exception should have been thrown");
            }
            catch (InvalidRequestException)
            {
                // expected
            }
        }