public void ConvertActivityWithFileAttachmentAndTextToOmniWhatsAppFailoverMessage()
        {
            var attachment = new Attachment {
                ContentUrl = "http://dummy-file.com", ContentType = "application/pdf"
            };

            _activity.Attachments = new List <Attachment> {
                attachment
            };
            _activity.Text = "Test text";

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Single(whatsAppMessages);

            var whatsAppMessage = whatsAppMessages.Single();

            Assert.NotNull(whatsAppMessage);
            Assert.Equal(whatsAppMessage.Text, _activity.Text);
            Assert.Equal(whatsAppMessage.FileUrl, attachment.ContentUrl);
            Assert.Null(whatsAppMessage.LocationName);
            Assert.Null(whatsAppMessage.AudioUrl);
            Assert.Null(whatsAppMessage.Address);
            Assert.Null(whatsAppMessage.Latitude);
            Assert.Null(whatsAppMessage.Longitude);
            Assert.Null(whatsAppMessage.ImageUrl);
            Assert.Null(whatsAppMessage.VideoUrl);
            Assert.Null(whatsAppMessage.TemplateNamespace);
            Assert.Null(whatsAppMessage.TemplateData);
            Assert.Null(whatsAppMessage.TemplateName);
            Assert.Null(whatsAppMessage.Language);
            Assert.Null(whatsAppMessage.MediaTemplateData);
        }
        public void ConvertTextActivityToOmniWhatsAppFailoverMessage()
        {
            _activity.Text = "Test text";

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Single(whatsAppMessages);

            var whatsAppMessage = whatsAppMessages.Single();

            Assert.NotNull(whatsAppMessage);
            Assert.Equal(whatsAppMessage.Text, _activity.Text);
            Assert.Null(whatsAppMessage.FileUrl);
            Assert.Null(whatsAppMessage.LocationName);
            Assert.Null(whatsAppMessage.AudioUrl);
            Assert.Null(whatsAppMessage.Address);
            Assert.Null(whatsAppMessage.Latitude);
            Assert.Null(whatsAppMessage.Longitude);
            Assert.Null(whatsAppMessage.ImageUrl);
            Assert.Null(whatsAppMessage.VideoUrl);
            Assert.Null(whatsAppMessage.TemplateNamespace);
            Assert.Null(whatsAppMessage.TemplateData);
            Assert.Null(whatsAppMessage.TemplateName);
            Assert.Null(whatsAppMessage.Language);
            Assert.Null(whatsAppMessage.MediaTemplateData);
        }
        public void ConvertActivityWithTemplateAttachmentToOmniWhatsAppFailoverMessage()
        {
            var templateMessage = new InfobipWhatsAppTemplateMessage
            {
                TemplateNamespace = "template_namespace",
                TemplateData      = new[] { "one", "two" },
                TemplateName      = "template_name",
                Language          = "en",
                MediaTemplateData = new InfobipWhatsAppMediaTemplateData
                {
                    MediaTemplateHeader = new InfobipWhatsAppMediaTemplateHeader
                    {
                        DocumentFilename = "Test file name"
                    },
                    MediaTemplateBody = new InfobipWhatsAppMediaTemplateBody
                    {
                        Placeholders = new[] { "three", "four" }
                    }
                }
            };

            _activity.AddInfobipWhatsAppTemplateMessage(templateMessage);

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Single(whatsAppMessages);

            var whatsAppMessage = whatsAppMessages.Single();

            Assert.NotNull(whatsAppMessage);
            Assert.Null(whatsAppMessage.Text);
            Assert.Null(whatsAppMessage.FileUrl);
            Assert.Null(whatsAppMessage.LocationName);
            Assert.Null(whatsAppMessage.AudioUrl);
            Assert.Null(whatsAppMessage.Address);
            Assert.Null(whatsAppMessage.Latitude);
            Assert.Null(whatsAppMessage.Longitude);
            Assert.Null(whatsAppMessage.ImageUrl);
            Assert.Null(whatsAppMessage.VideoUrl);
            Assert.Equal(whatsAppMessage.TemplateNamespace, templateMessage.TemplateNamespace);
            Assert.NotNull(whatsAppMessage.TemplateData);
            Assert.Equal(whatsAppMessage.TemplateData.Length, templateMessage.TemplateData.Length);
            Assert.Equal(whatsAppMessage.TemplateName, templateMessage.TemplateName);
            Assert.Equal(whatsAppMessage.Language, templateMessage.Language);
            Assert.NotNull(whatsAppMessage.MediaTemplateData);
            Assert.Equal(whatsAppMessage.MediaTemplateData.MediaTemplateBody.Placeholders.Length, templateMessage.MediaTemplateData.MediaTemplateBody.Placeholders.Length);
            Assert.Equal(whatsAppMessage.MediaTemplateData.MediaTemplateHeader.DocumentFilename, templateMessage.MediaTemplateData.MediaTemplateHeader.DocumentFilename);
            Assert.Null(whatsAppMessage.MediaTemplateData.MediaTemplateHeader.Latitude);
            Assert.Null(whatsAppMessage.MediaTemplateData.MediaTemplateHeader.Longitude);
            Assert.Null(whatsAppMessage.MediaTemplateData.MediaTemplateHeader.ImageUrl);
            Assert.Null(whatsAppMessage.MediaTemplateData.MediaTemplateHeader.DocumentUrl);
            Assert.Null(whatsAppMessage.MediaTemplateData.MediaTemplateHeader.TextPlaceholder);
            Assert.Null(whatsAppMessage.MediaTemplateData.MediaTemplateHeader.VideoUrl);
        }
        public void ConvertActivityWithTextAndMultipleAttachmentsToOmniWhatsAppFailoverMessage()
        {
            var attachment = new Attachment {
                ContentUrl = "http://dummy-video.com", ContentType = "video/mp4"
            };
            var attachment2 = new Attachment {
                ContentUrl = "http://dummy-image.com", ContentType = "image/jpeg"
            };

            _activity.Attachments = new List <Attachment> {
                attachment, attachment2
            };
            _activity.Text = "Test text";

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Equal(2, whatsAppMessages.Count);

            var whatsAppMessage = whatsAppMessages.First();

            Assert.NotNull(whatsAppMessage);
            Assert.Equal(whatsAppMessage.Text, _activity.Text);
            Assert.Null(whatsAppMessage.FileUrl);
            Assert.Null(whatsAppMessage.LocationName);
            Assert.Null(whatsAppMessage.AudioUrl);
            Assert.Null(whatsAppMessage.Address);
            Assert.Null(whatsAppMessage.Latitude);
            Assert.Null(whatsAppMessage.Longitude);
            Assert.Null(whatsAppMessage.ImageUrl);
            Assert.Equal(whatsAppMessage.VideoUrl, attachment.ContentUrl);
            Assert.Null(whatsAppMessage.TemplateNamespace);
            Assert.Null(whatsAppMessage.TemplateData);
            Assert.Null(whatsAppMessage.TemplateName);
            Assert.Null(whatsAppMessage.Language);
            Assert.Null(whatsAppMessage.MediaTemplateData);

            var whatsAppMessage2 = whatsAppMessages.ElementAt(1);

            Assert.NotNull(whatsAppMessage2);
            Assert.Null(whatsAppMessage2.Text);
            Assert.Null(whatsAppMessage2.FileUrl);
            Assert.Null(whatsAppMessage2.LocationName);
            Assert.Null(whatsAppMessage2.AudioUrl);
            Assert.Null(whatsAppMessage2.Address);
            Assert.Null(whatsAppMessage2.Latitude);
            Assert.Null(whatsAppMessage2.Longitude);
            Assert.Equal(whatsAppMessage2.ImageUrl, attachment2.ContentUrl);
            Assert.Null(whatsAppMessage2.VideoUrl);
            Assert.Null(whatsAppMessage2.TemplateNamespace);
            Assert.Null(whatsAppMessage2.TemplateData);
            Assert.Null(whatsAppMessage2.TemplateName);
            Assert.Null(whatsAppMessage2.Language);
            Assert.Null(whatsAppMessage2.MediaTemplateData);
        }
        public void ConvertActivityWithSinglePlaceEntityWithNonStringAddressOmniWhatsAppFailoverMessage()
        {
            _activity.Entities = new List <Entity>
            {
                new Place
                {
                    Address = new { Key = "value" }
                }
            };

            Assert.Throws <Exception>(() => InfobipOmniWhatsAppMessageFactory.Create(_activity));
        }
        public void ConvertActivityWithSingleGeoCoordinateEntityToOmniWhatsAppFailoverMessage()
        {
            _activity.Entities = new List <Entity> {
                new GeoCoordinates {
                    Latitude = 12.3456789, Longitude = 23.456789, Name = "Test"
                }
            };

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Single(whatsAppMessages);

            var whatsAppMessage = whatsAppMessages.First();

            CheckLocationMessage(whatsAppMessage, _activity.Entities.First().GetAs <GeoCoordinates>());
        }
        public void ConvertActivityWithAudioAttachmentToOmniWhatsAppFailoverMessage()
        {
            var attachment = new Attachment {
                ContentUrl = "http://dummy-audio.com", ContentType = "audio/mp3"
            };

            _activity.Attachments = new List <Attachment> {
                attachment
            };

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Single(whatsAppMessages);

            var whatsAppMessage = whatsAppMessages.First();

            CheckAudioMessage(whatsAppMessage, attachment);
        }
        public void ConvertActivityWithMultipleGeoCoordinateEntityToOmniWhatsAppFailoverMessage()
        {
            _activity.Entities = new List <Entity>
            {
                new GeoCoordinates {
                    Latitude = 12.3456789, Longitude = 23.456789, Name = "Test"
                },
                new GeoCoordinates {
                    Latitude = 45.56789, Longitude = 87.12345, Name = "Test2"
                }
            };

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Equal(2, whatsAppMessages.Count);

            for (var i = 0; i < whatsAppMessages.Count; i++)
            {
                CheckLocationMessage(whatsAppMessages.ElementAt(i), _activity.Entities.ElementAt(i).GetAs <GeoCoordinates>());
            }
        }
        public void ConvertActivityWithAudioAttachmentAndTextToOmniWhatsAppFailoverMessage()
        {
            var attachment = new Attachment {
                ContentUrl = "http://dummy-audio.com", ContentType = "audio/mp3"
            };

            _activity.Attachments = new List <Attachment> {
                attachment
            };
            _activity.Text = "Test text";

            var whatsAppMessages = InfobipOmniWhatsAppMessageFactory.Create(_activity);

            Assert.NotNull(whatsAppMessages);
            Assert.Equal(2, whatsAppMessages.Count);

            var whatsAppMessage = whatsAppMessages.First();

            Assert.NotNull(whatsAppMessage);
            Assert.Equal(whatsAppMessage.Text, _activity.Text);
            Assert.Null(whatsAppMessage.FileUrl);
            Assert.Null(whatsAppMessage.LocationName);
            Assert.Null(whatsAppMessage.AudioUrl);
            Assert.Null(whatsAppMessage.Address);
            Assert.Null(whatsAppMessage.Latitude);
            Assert.Null(whatsAppMessage.Longitude);
            Assert.Null(whatsAppMessage.ImageUrl);
            Assert.Null(whatsAppMessage.VideoUrl);
            Assert.Null(whatsAppMessage.TemplateNamespace);
            Assert.Null(whatsAppMessage.TemplateData);
            Assert.Null(whatsAppMessage.TemplateName);
            Assert.Null(whatsAppMessage.Language);
            Assert.Null(whatsAppMessage.MediaTemplateData);

            CheckAudioMessage(whatsAppMessages.ElementAt(1), attachment);
        }