public void AddsToAttachments()
            {
                var attachment = new SlackAttachment();
                int initial = _sut.Attachments.Count;

                _result = _sut.Attach(attachment);

                Assert.AreEqual(initial + 1, _sut.Attachments.Count);
            }
Beispiel #2
0
        public string GetJson(SlackMessage message)
        {
            var settings = new JsonSerializerSettings {ContractResolver = new LowerCaseContractResolver()
                , NullValueHandling = NullValueHandling.Ignore
            };
            //settings.Converters.Add(new LinkedItemConverter());

            return JsonConvert.SerializeObject(message, settings);
        }
Beispiel #3
0
        public void ComplicatedTalk()
        {
            var msg = new SlackMessage();

            msg.Title("Testing *title*")
                .FallBack("this is fallbacktext")
                .UsingLeftBarColor(Color.Orange)
                .WithMessageText("okayhhiuo *jim* ok - _italic?_ <mailto:[email protected]|Bob>")
                .AsAuthor("Louis")
                .AsUser("Some User")
                .Field("Coverage Result", "10%\n20%\n30%", true)
                .Field("Package Name", "godaddy.domain.cicd.trigger", true)
                .SetTextAsMarkDownField()
                ;

            sut.Send(msg);
        }
Beispiel #4
0
        public void MoreTalking()
        {
            DataTable dtable = new DataTable();
            dtable.Columns.Add("Class");
            dtable.Columns.Add("Errors/Failures/Totals");

            dtable.Rows.Add("BusinessObjects.Domains.Tests-nunitTestResults", "0/0/64");
            dtable.Rows.Add("BusinessObjects.Domains.Tests-nunitTestResults", "0/6/6");

            sut = new SlackClient(new Uri("https://hooks.slack.com/services/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").ToString());
            var msg = new SlackMessage();
            //msg.Attach(new SlackAttachment());
            msg.AddData(dtable)
                //.UsingLeftBarColor(Color.White)
                ;

            sut.Send(msg);
        }
            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);
            }
 public void Setup()
 {
     _testObject = new SlackMessageTestObject();
     _testObject.AddDefaultAttachment();
     _preText = Helpers.Random;
     _result = _testObject.Sut.Pretext(_preText);
 }
            public void CreateNewAttahmentWhenAttachmentEmpty()
            {
                _testObject.ResetAttachments();
                int initial = _testObject.Sut.Attachments.Count;

                _result = _testObject.Sut.Pretext(_preText);

                Assert.AreEqual(0, initial);
                Assert.AreEqual(1, _testObject.Sut.Attachments.Count);
            }
            public void Setup()
            {
                _title = Helpers.Random;
                _value = Helpers.Random;
                _short = true;

                _testObject = new SlackMessageTestObject();
                _testObject.AddDefaultAttachment();
                _result = _testObject.Sut.Field(_title, _value, _short);
            }
Beispiel #9
0
 public void Setup()
 {
     _slackMessage = new SlackMessage();
     _attachment = new SlackAttachment();
     _slackMessage.Attach(_attachment);
     settings = new JsonSerializerSettings { ContractResolver = new LowerCaseContractResolver() };
 }
 public void CreatesAttachmentIfNoCurrentAttachment()
 {
     var sut = new SlackMessage();
     sut.UsingLeftBarColor(Color.GreenYellow);
     Assert.AreEqual(1, sut.Attachments.Count);
 }
            public void Setup()
            {
                _testObject = new SlackMessageTestObject();
                _testObject.AddDefaultAttachment();
                _columcount = Helpers.RandomNumber(1, 4);
                _rowcount = Helpers.RandomNumber(1, 4);
                _columnNames = new List<string>();
                _data = new Dictionary<string, IList<string>>();
                testTable = new DataTable();

                for(int i=0; i < _columcount; i++)
                {
                    string name = Helpers.Random;
                    _columnNames.Add(name);
                    testTable.Columns.Add(name);
                    _data.Add(name, new List<string>());
                }

                for(int i=0; i < _rowcount; i++)
                {
                    DataRow drow = testTable.NewRow();
                    foreach(DataColumn dcol in testTable.Columns)
                    {
                        var value = Helpers.Random;
                        drow[dcol] = value;
                        _data[dcol.ColumnName].Add(value);
                    }
                    testTable.Rows.Add(drow);
                }
                _result = _testObject.Sut.AddData(testTable);
            }
            public void CreateNewAttachmentWhenAttachmentEmpty()
            {
                _testObject.ResetAttachments();
                int initial = _testObject.Sut.Attachments.Count;

                _result = _testObject.Sut.AddData(testTable);

                Assert.AreEqual(0, initial);
                Assert.AreEqual(1, _testObject.Sut.Attachments.Count);
            }
            public void AddsFieldPerColumn()
            {
                _testObject = new SlackMessageTestObject();
                _testObject.AddDefaultAttachment();
                var initial = _testObject.DefaultAttachment.Fields.Count;

                _result = _testObject.Sut.AddData(testTable);

                Assert.AreEqual(initial + _columcount,
                    _testObject.DefaultAttachment.Fields.Count,
                    "Added " + (initial + _columcount).ToString() + " Fields");
            }
 public void ReturnsNullWhenThereAreNoAttachments()
 {
     var sut = new SlackMessage();
     Assert.IsNull(sut.Author);
 }
 public void CreatesAttachmentIfNoCurrentAttachment()
 {
     var sut = new SlackMessage();
     sut.AsAuthor(AuthorName, AuthorIcon, AuthorLink);
     Assert.AreEqual(1, sut.Attachments.Count);
 }
 public void Setup()
 {
     _message = Helpers.Random;
     _result = _sut.WithMessageText(_message);
 }
            public void Setup()
            {
                _title = Helpers.Random;
                _randomUri = "http://" + Helpers.Random + ".com/";
                _sutObject = new SlackMessageTestObject();
                _sutObject.AddDefaultAttachment();

                _result = _sutObject.Sut.Title(_title, _randomUri);
            }
 public void Setup()
 {
     _testObject = new SlackMessageTestObject();
     _testObject.AddDefaultAttachment();
     _fallBack = Helpers.Random;
     _result = _testObject.Sut.FallBack(_fallBack);
 }
 internal void ResetAttachments()
 {
     Sut = new SlackMessage();
 }
            public void CreateAttachmentIfNoneExists()
            {
                _testObject.ResetAttachments();
                var initialCount = _testObject.Sut.Attachments.Count;
                _result = _testObject.Sut.Field(_title, _value, _short);

                Assert.AreEqual(0, initialCount);
                Assert.AreEqual(1, _testObject.Sut.Attachments.Count);
            }
Beispiel #21
0
 public void Send(SlackMessage message)
 {
     string text = GetJson(message);
     Say(text);
 }
            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);
            }