public void InitiateAlert(bool passCreds)
        {
            //ARRANGE
            var request = new ShortCode.AlertRequest
            {
                to = "15555551212"
            };
            var customValues = new Dictionary <string, string>
            {
                { "mcount", "xyz123" }
            };
            var uri = $"{RestUrl}/sc/us/alert/json?to={request.to}&mcount={customValues["mcount"]}&api_key={ApiKey}&api_secret={ApiSecret}&";
            var ExpectedResponse = "{\"message-count\":\"1\",\"messages\":[{\"message-id\":\"02000000AE70FFFF\",\"to\":\"15555551212\",\"remaining-balance\":7.546,\"message-price\":0.0048,\"ok\":true,\"status\":\"0\",\"msisdn\":\"15555551212\",\"network\":\"US-FIXED\",\"messageId\":\"02000000AE70FFFF\",\"remainingBalance\":7.546,\"messagePrice\":0.0048}]}";

            Setup(uri: uri, responseContent: ExpectedResponse);

            //ACT
            var creds = new Request.Credentials {
                ApiKey = ApiKey, ApiSecret = ApiSecret
            };
            var client = new Client(creds);

            SMS.SMSResponse response;
            if (passCreds)
            {
                response = client.ShortCode.RequestAlert(request, customValues, creds);
            }
            else
            {
                response = client.ShortCode.RequestAlert(request, customValues);
            }

            Assert.Equal("1", response.message_count);
            Assert.Equal("15555551212", response.messages.First().to);
        }
Esempio n. 2
0
        public void should_initiate_alert()
        {
            var request = new ShortCode.AlertRequest
            {
                to = "15555551212"
            };
            var customValues = new Dictionary <string, string>
            {
                { "mcount", "xyz123" }
            };

            SetExpect($"{RestUrl}/sc/us/alert/json?to={request.to}&api_key={ApiKey}&api_secret={ApiSecret}&mcount={customValues["mcount"]}&",
                      "{\"message-count\":\"1\",\"messages\":[{\"message-id\":\"02000000AE70FFFF\",\"to\":\"15555551212\",\"remaining-balance\":7.546,\"message-price\":0.0048,\"ok\":true,\"status\":\"0\",\"msisdn\":\"15555551212\",\"network\":\"US-FIXED\",\"messageId\":\"02000000AE70FFFF\",\"remainingBalance\":7.546,\"messagePrice\":0.0048}]}");

            var response = ShortCode.RequestAlert(request, customValues);

            Assert.AreEqual("1", response.message_count);
            Assert.AreEqual("15555551212", response.messages.First().to);
        }
Esempio n. 3
0
        public void should_initiate_alert()
        {
            var resp = new Mock <IWebResponse>();

            resp.Setup(e => e.GetResponseStream()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("{\"message-count\":\"1\",\"messages\":[{\"message-id\":\"02000000AE70FFFF\",\"to\":\"15555551212\",\"remaining-balance\":7.546,\"message-price\":0.0048,\"ok\":true,\"status\":\"0\",\"msisdn\":\"15555551212\",\"network\":\"US-FIXED\",\"messageId\":\"02000000AE70FFFF\",\"remainingBalance\":7.546,\"messagePrice\":0.0048}]}")));
            _request.Setup(e => e.GetResponse()).Returns(resp.Object);
            var request = new ShortCode.AlertRequest
            {
                to = "15555551212"
            };
            var customValues = new Dictionary <string, string>
            {
                { "mcount", "xyz123" }
            };
            var response = ShortCode.RequestAlert(request, customValues);

            _mock.Verify(h => h.CreateHttp(new Uri(
                                               string.Format("{0}/sc/us/alert/json?to={1}&api_key={2}&api_secret={3}&mcount={4}&", RestUrl, request.to, ApiKey, ApiSecret, customValues["mcount"]))),
                         Times.Once);
            Assert.AreEqual("1", response.message_count);
            Assert.AreEqual("15555551212", response.messages.First().to);
        }