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)); }
public void SendScheduledMessage_WithSmsMessage_ReturnsBatchIdResult() { // Arrange DateTime timestamp = DateTime.UtcNow; SmsMessage message = new SmsMessage("recipients", "body", "accountReference"); SmsMessageCollection messages = new SmsMessageCollection(message) { SendAt = timestamp }; 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.SendScheduledMessage(message, timestamp); // Assert Assert.IsNotNull(actualResult); Assert.AreEqual(expectedResult.BatchId, actualResult.BatchId); Assert.AreEqual(0, actualResult.MessageIds.Count()); }
public void SmsMessageCollection_DefaultDIConstructor_WithNullCollectionAndEmptyAccountReference() { // Arrange // Act try { SmsMessageCollection messageInstances = new SmsMessageCollection(null, string.Empty); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("messages", ex.ParamName); } }
public void SmsMessageCollection_DefaultDIConstructor_WithNullCollectionAndEmptyAccountReference() { // Arrange // Act try { var messageInstances = new SmsMessageCollection(null, string.Empty); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("messages", ex.ParamName); } }
public void SmsMessageCollection_DefaultDIConstructor_WithNullMessage() { // Arrange SmsMessage message = null; // Act try { SmsMessageCollection messageInstances = new SmsMessageCollection(message); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("message", ex.ParamName); } }
public void SmsMessageCollection_DefaultDIConstructor_WithNullMessage() { // Arrange SmsMessage message = null; // Act try { var messageInstances = new SmsMessageCollection(message); Assert.Fail(); } // Assert catch (ArgumentNullException ex) { Assert.AreEqual("message", ex.ParamName); } }
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 MessageCollection_WithoutBlankOriginator_ShouldNotSerialiseOriginator() { // Arrange SmsMessageCollection message = new SmsMessageCollection() { Originator = string.Empty }; XmlSerialiser serialiser = new XmlSerialiser(); // Act string serialisedXml = serialiser.Serialise(message); // Assert var document = XDocument.Parse(serialisedXml); var originator = document.Element(ns + "messages").Element(ns + "from"); Assert.IsNull(originator); }
public void SmsMessageCollection_ConstructorWithSmsMessageArray() { // Arrange var recipients = "recipients"; var body = "body"; var accountReference = "accountReference"; SmsMessage[] messages = { new SmsMessage(recipients, body, accountReference), new SmsMessage(recipients, body, accountReference) }; // Act var messagesInstance = new SmsMessageCollection(messages, accountReference); // Assert Assert.AreEqual(messages[0], messagesInstance.Items.ElementAt(0)); Assert.AreEqual(messages[1], messagesInstance.Items.ElementAt(1)); }
public void MessageCollection_WithOriginator_SerialisesOriginator() { // Arrange SmsMessageCollection messages = new SmsMessageCollection() { Originator = "07000000000" }; XmlSerialiser serialiser = new XmlSerialiser(); // Act string serialisedXml = serialiser.Serialise(messages); // Assert var document = XDocument.Parse(serialisedXml); var originator = document.Element(ns + "messages").Element(ns + "from"); Assert.IsNotNull(originator); Assert.AreEqual(messages.Originator, originator.Value); }
private async Task <bool> SendSMSAsync(string number, string message) { var userName = Environment.GetEnvironmentVariable("clickSendUser"); var apiKey = Environment.GetEnvironmentVariable("clickSendApiKey"); var config = new IO.ClickSend.Client.Configuration(); config.Username = userName; config.Password = apiKey; var clickSend = new SMSApi(config); var smsMessage = new SmsMessage(null, message, number); var sms = new List <SmsMessage>() { smsMessage }; var collection = new SmsMessageCollection(sms); var responseTask = clickSend.SmsSendPostAsync(collection); var responseString = await responseTask; ClickSendResponse response = JsonSerializer.Deserialize <ClickSendResponse>(responseString); if (response.http_code == 200) { //TODO: there is a 'data' object in the deserializer that lets us know if the text went through if (_logger != null) { _logger.LogInformation($"We got a positive message back from Clicksend. They say the satus of the message is: {response.data.messages[0].status}"); } return(true); } if (_logger != null) { _logger.LogError($"Our attempt to send an sms message failed. Here's what we know. \nHttp response code: {response.http_code} \nResponse message:{response.response_msg}"); } return(false); }
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); }