private static void FlattenTitleProperty(JObject o, SlackAttachment attachment)
 {
     var titleProp = o.Children<JProperty>().FirstOrDefault(z => z.Name == "title");
     if (titleProp != null && attachment.Title != null)
     {
         titleProp.Value = attachment.Title.Name;
         if (attachment.Title.Link != null)
             titleProp.AddAfterSelf(new JProperty("title_link", attachment.Title.Link.OriginalString));
     }
 }
            public void AddsToAttachments()
            {
                var attachment = new SlackAttachment();
                int initial = _sut.Attachments.Count;

                _result = _sut.Attach(attachment);

                Assert.AreEqual(initial + 1, _sut.Attachments.Count);
            }
 private static void FlattenAuthorProperty(JObject o, SlackAttachment attachment)
 {
     var authorProp = o.Children<JProperty>().FirstOrDefault(z => z.Name == "author");
     if (authorProp != null && attachment.Author != null)
     {
         authorProp.AddAfterSelf(new JProperty("author_name", attachment.Author.Name));
         authorProp.AddAfterSelf(new JProperty("author_link", attachment.Author.Link));
         authorProp.AddAfterSelf(new JProperty("author_icon", attachment.Author.Icon));
         authorProp.Remove();
     }
 }
 private List<string> FlattenMarkdownField(SlackAttachment attachment)
 {
     List<string> markdownFields = new List<string>();
     if (attachment.MarkdownFields.HasFlag(SlackTextFields.Text))
     {
         markdownFields.Add("text");
     }
     if (attachment.MarkdownFields.HasFlag(SlackTextFields.Pretext))
     {
         markdownFields.Add("pretext");
     }
     if (attachment.MarkdownFields.HasFlag(SlackTextFields.Fields))
     {
         markdownFields.Add("fields");
     }
     return markdownFields;
 }
Example #5
0
 public SlackMessage Attach(SlackAttachment attachment)
 {
     _attachments.Add(attachment);
     return this;
 }
            public void SetsAttachmentTextWhenPossible()
            {
                var randomMessage = Helpers.Random;
                var attachment = new SlackAttachment{};
                var sut = new SlackMessage();
                sut.Attach(attachment);

                sut.WithMessageText(randomMessage);

                Assert.AreEqual(randomMessage, attachment.Text);
            }
Example #7
0
 public SlackMessage Attach(SlackAttachment attachment)
 {
     _attachments.Add(attachment);
     return(this);
 }
Example #8
0
 public void Setup()
 {
     _slackMessage = new SlackMessage();
     _attachment = new SlackAttachment();
     _slackMessage.Attach(_attachment);
     settings = new JsonSerializerSettings { ContractResolver = new LowerCaseContractResolver() };
 }
            public void Setup()
            {
                messageString = Helpers.Random;
                sut = new SlackClient(Helpers.RandomUri.OriginalString);
                _JsonPathAndValues = new Dictionary<string, string>
                {
                    {"attachments[0].fallback",Helpers.Random}
                    ,{"attachments[0].color",Color.Gold.ToHex()}
                    ,{"attachments[0].pretext",Helpers.Random}
                    ,{"attachments[0].text",messageString}
                    ,{"attachments[0].author_name",Helpers.Random}
                    ,{"attachments[0].author_icon",Helpers.RandomUri.OriginalString}
                    ,{"attachments[0].author_link",Helpers.RandomUri.OriginalString}
                    ,{"attachments[0].title",Helpers.Random}
                    ,{"attachments[0].title_link",Helpers.RandomUri.OriginalString}
                    ,{"attachments[0].fields[0].title",Helpers.Random}
                    ,{"attachments[0].fields[0].value",Helpers.Random}
                    ,{"attachments[0].fields[0].short","True"}
                    ,{"attachments[0].image_url",Helpers.RandomUri.OriginalString}
                    ,{"attachments[0].thumb_url",Helpers.RandomUri.OriginalString}
                    ,{"username",Helpers.Random}
                    , {"text",messageString }
                };
                _fallback = _JsonPathAndValues["attachments[0].fallback"];
                _pretext = _JsonPathAndValues["attachments[0].pretext"];
                _color =  _JsonPathAndValues["attachments[0].color"].ToColor();
                _authorIcon = new Uri(_JsonPathAndValues["attachments[0].author_icon"]);
                _authorName = _JsonPathAndValues["attachments[0].author_name"];
                _authorLink = new Uri(_JsonPathAndValues["attachments[0].author_link"]); ;
                _titleName = _JsonPathAndValues["attachments[0].title"];
                _titleLink = new Uri(_JsonPathAndValues["attachments[0].title_link"]);
                _text = _JsonPathAndValues["attachments[0].text"];
                _fieldTitle = _JsonPathAndValues["attachments[0].fields[0].title"];
                _fieldValue = _JsonPathAndValues["attachments[0].fields[0].value"];
                _fieldShort = bool.Parse(_JsonPathAndValues["attachments[0].fields[0].short"]);
                _thumbUrl = new Uri(_JsonPathAndValues["attachments[0].thumb_url"]);
                _imageUrl = new Uri(_JsonPathAndValues["attachments[0].image_url"]);
                _username = _JsonPathAndValues["username"];
                _attachment = new SlackAttachment
                {
                    Fallback = _fallback
                    ,Author = new SlackAuthor { Icon = _authorIcon, Link = _authorLink, Name = _authorName}
                    ,Color = _color
                    ,Pretext = _pretext
                    ,Title = new LinkedElement {Link = _titleLink, Name = _titleName}
                    ,Text = _text
                    ,ImageUri = _imageUrl
                    ,ThumbUri = _thumbUrl

                };
                _attachment.AddField(_fieldTitle, _fieldValue, _fieldShort);
                _message = new SlackMessage
                {
                };
                _message.WithMessageText(_text);
                _message.Attach(_attachment);
                _message.AsUser(_username);

                _json = sut.GetJson(_message);
            }