public void DefaultConstructor_WithoutMessageIdsInResult()
        {
            // Arrange
            string content = "content";
            bool ensureMessageIdsInResult = false;

            // Act
            RestResource resource = new MessageDispatcherResource(content, ensureMessageIdsInResult);

            // Assert
            Assert.AreEqual(content, resource.Content);
            Assert.AreEqual("messagedispatcher", resource.ResourcePath);
        }
        public void DefaultConstructor_WithMessageIdsInResult()
        {
            // Arrange
            var content = "content";
            var ensureMessageIdsInResult = true;

            // Act
            RestResource resource = new MessageDispatcherResource(content, ensureMessageIdsInResult);

            // Assert
            Assert.AreEqual(content, resource.Content);
            Assert.AreEqual("messagedispatcher?returnmessageheaders=true", resource.ResourcePath);
        }
        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 SendVoiceMessageCollection_RestClientReturnsNull_ReturnsNull()
        {
            // Arrange
            VoiceMessage message = new VoiceMessage("recipients", "body", "accountReference");
            VoiceMessageCollection messages = new VoiceMessageCollection(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);
        }
        public void SendScheduledMessages_WithVoiceMessage_ReturnsBatchIdResult()
        {
            // Arrange
            var timestamp = DateTime.UtcNow;

            var message = new VoiceMessage("recipients", "body", "accountReference");
            var messages = new VoiceMessageCollection(message) {SendAt = timestamp};

            var serialisedMessage = "serialisedMessage";

            RestResource resource = new MessageDispatcherResource(serialisedMessage, false);

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

            var 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
            var actualResult = service.SendScheduledMessages(messages, timestamp);

            // Assert
            Assert.IsNotNull(actualResult);
            Assert.AreEqual(expectedResult.BatchId, actualResult.BatchId);
            Assert.AreEqual(0, actualResult.MessageIds.Count());
        }