public void SerialiseSmsMessage()
        {
            // Arrange
            try
            {
                SmsMessage smsMessage = new SmsMessage();

                string xml = "";

                // Act - Assert
                XmlSchema schema = GetEmbeddedSchema(MessageSchemas.DispatcherRequestSchemaName);
                
                XmlReaderSettings settings = new XmlReaderSettings()
                {
                    ValidationType = ValidationType.Schema,
                    ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings
                };

                settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler);
                settings.Schemas.Add(schema);

                XmlReader reader = XmlReader.Create(new StringReader(xml), settings);

                while (reader.Read()) { }

            }
            catch (XmlException)
            {
                Assert.Fail();
            }
        }
예제 #2
0
        public void SendMessage(string from, PhoneNumber to, string message)
        {
            var smsMessage = new SmsMessage(to, message, _account);
                smsMessage.Originator = from;

                _dispatcher.SendMessage(smsMessage);
        }
        public void WhenCharacterSetIsDefaultItIsNotSerialised()
        {
            var message = new SmsMessage();
            var serialiser = new XmlSerialiser();
            var serialisedMessage = serialiser.Serialise(message);

            Assert.That(serialisedMessage, Is.Not.StringContaining("characterset"));
        }
        public void WhenSmsMessageIsSerializedThenTheCharacterSetIsSerialisedAsExpected(CharacterSet characterSet, string expectedXml)
        {
            var message = new SmsMessage {CharacterSet = characterSet};

            var serialiser = new XmlSerialiser();
            var serialisedMessage = serialiser.Serialise(message);

            Assert.That(serialisedMessage, Is.EqualTo(expectedXml));
        }
        public void WhenCharacterSetIsSetShouldBeSerialised([Values(CharacterSet.Auto, CharacterSet.GSM, CharacterSet.Unicode)] CharacterSet characterSet)
        {
            var message = new SmsMessage();
            message.CharacterSet = characterSet;

            var serialiser = new XmlSerialiser();
            var serialisedMessage = serialiser.Serialise(message);

            Assert.That(serialiser.Deserialise<SmsMessage>(serialisedMessage).CharacterSet, Is.EqualTo(characterSet));
        }
예제 #6
0
        public void SmsMessageCollection_ConstructorWithSmsMessage()
        {
            // Arrange
            string recipients = "recipients";
            string body = "body";
            string accountReference = "accountReference";

            SmsMessage message = new SmsMessage(recipients, body, accountReference);

            // Act
            SmsMessageCollection messagesInstance = new SmsMessageCollection(message);

            // Assert
            Assert.AreEqual(message, messagesInstance.Items.ElementAt(0));
        }
예제 #7
0
        public void SendMessagesToSantas(IEnumerable<SantaEntry> entries, string messageTemplate, string originator, string account)
        {
            foreach (var entry in entries)
            {
                var santaChosenName = NickOrFirstname(entry.Santa);
                var reciverChosenName = NickOrFirstname(entry.Receiver);

                var fullMessage = string.Format(messageTemplate, santaChosenName, reciverChosenName);

                var smsMessage = new SmsMessage(entry.Santa.PhoneNumber, fullMessage, account);
                smsMessage.Originator = originator;

               _dispatcher.SendMessage(smsMessage);
            }
        }
예제 #8
0
        public void SmsMessage_DefaultDIConstructor()
        {
            // Arrange
            var recipients = "recipients";
            var body = "body";
            var accountReference = "accountReference";

            // Act
            var messageInstance = new SmsMessage(recipients, body, accountReference);

            // Assert
            Assert.AreEqual(accountReference, messageInstance.AccountReference);
            Assert.AreEqual(body, messageInstance.Body);
            Assert.AreEqual(recipients, messageInstance.Recipients);
        }
        public void SendMessages_WithSmsMessage_ReturnsBatchIdResult()
        {
            // Arrange
            SmsMessage message = new SmsMessage("recipients", "body", "accountReference");
            SmsMessageCollection messages = new SmsMessageCollection(message);

            string serialisedMessage = "serialisedMessage";

            RestResource resource = new MessageDispatcherResource(serialisedMessage, false);

            RestResponse response = new RestResponse()
            {
                StatusCode = HttpStatusCode.OK,
                Content = "serialisedResponse"
            };

            MessagingResult expectedResult = new MessagingResult()
            {
                BatchId = Guid.NewGuid(),
                MessageIds = new List<ResourceLink>()
            };

            mockSerialiser
                .Setup(s => s.Serialise(messages))
                .Returns(serialisedMessage);

            mockRestClient
                .Setup(rc => rc.Post(resource))
                .Returns(response);

            mockSerialiser
                .Setup(s => s.Deserialise<MessagingResult>(response.Content))
                .Returns(expectedResult);

            // Act
            MessagingResult actualResult = service.SendMessages(messages);

            // Assert
            Assert.IsNotNull(actualResult);
            Assert.AreEqual(expectedResult.BatchId, actualResult.BatchId);
            Assert.AreEqual(0, actualResult.MessageIds.Count());
        }
        public void Message_WithOriginator_SerialisesOriginator()
        {
            // Arrange
            SmsMessage message = new SmsMessage()
            {
                Originator = "07000000000"
            };

            XmlSerialiser serialiser = new XmlSerialiser();

            // Act
            string serialisedXml = serialiser.Serialise(message);

            // Assert
            var document = XDocument.Parse(serialisedXml);

            var originator = document.Element("message").Element("from");

            Assert.IsNotNull(originator);
            Assert.AreEqual(message.Originator, originator.Value);
        }
        public void Message_WithoutBlankOriginator_ShouldNotSerialiseOriginator()
        {
            // Arrange
            var message = new SmsMessage
            {
                Originator = string.Empty
            };

            var serialiser = new XmlSerialiser();

            // Act
            var serialisedXml = serialiser.Serialise(message);

            // Assert
            var document = XDocument.Parse(serialisedXml);

            var originator = document.Element("message")
                                     .Element("from");

            Assert.IsNull(originator);
        }
예제 #12
0
        public void SmsMessage_DefaultDIConstructor_WithNullOrEmptyParams()
        {
            // Arrange
            string recipients = string.Empty;
            string body = null;
            string accountReference = string.Empty;

            // Act
            try
            {
                SmsMessage messageInstance = new SmsMessage(recipients, body, accountReference);

                Assert.Fail();
            }
            // Assert
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("recipients", ex.ParamName);
            }
        }
        public void SendSmsMessageCollection_RestClientReturnsNull_ReturnsNull()
        {
            // Arrange
            SmsMessage message = new SmsMessage("recipients", "body", "accountReference");
            SmsMessageCollection messages = new SmsMessageCollection(message);

            string serialisedMessage = "serialisedMessage";

            RestResource resource = new MessageDispatcherResource(serialisedMessage, false);

            RestResponse response = null;

            mockSerialiser
                .Setup(s => s.Serialise(messages))
                .Returns(serialisedMessage);

            mockRestClient
                .Setup(rc => rc.Post(resource))
                .Returns(response);

            // Act
            MessagingResult actualResult = service.SendMessages(messages);

            // Assert
            Assert.IsNull(actualResult);
        }
예제 #14
0
        private static void SendMessageExample(EsendexCredentials credentials)
        {
            var message = new SmsMessage(_sendTo, "This is a test message from the .Net SDK...", _accountReference);

            var messagingService = new MessagingService(true, credentials);

            try
            {
                var messageResult = messagingService.SendMessage(message);

                Console.WriteLine("\tMessage Batch Id: {0}", messageResult.BatchId);

                foreach (var messageId in messageResult.MessageIds)
                {
                    Console.WriteLine("\t\tMessage Uri: {0}", messageId.Uri);
                }
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
            }
        }
예제 #15
0
        /// <summary>
        /// Sends a com.esendex.sdk.messaging.SmsMessage instance and returns a com.esendex.sdk.messaging.MessagingResult instance.
        /// </summary>
        /// <param name="message">A com.esendex.sdk.messaging.SmsMessage instance that contains the SMS message.</param>
        /// <returns>A com.esendex.sdk.messaging.MessagingResult instance that contains the message batch Id.</returns>
        /// <exception cref="System.Net.WebException"></exception>
        public MessagingResult SendMessage(SmsMessage message)
        {
            var messages = new SmsMessageCollection(message);

            return(SendMessages <SmsMessageCollection>(messages));
        }
예제 #16
-1
        private static void SendMessageExample()
        {
            SmsMessage message = new SmsMessage("07000000000", "This is a test...", accountReference);

            MessagingService messagingService = new MessagingService(true, Credentials);

            try
            {
                MessagingResult messageResult = messagingService.SendMessage(message);

                Console.WriteLine("Message Batch Id: {0}", messageResult.BatchId);

                foreach (ResourceLink messageId in messageResult.MessageIds)
                {
                    Console.WriteLine("Message Uri: {0}", messageId.Uri);
                }
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
            }
        }