public async Task Test_SendSmsAsync()
        {
            var methodName = "SendAsync";
            var smsMessage = new SmsMessage();
            var testUri    = "https://api.mailjet.com/v4/sms-send";
            var options    = MailjetOptions;
            var entry      = new SendSmsResponseEntry
            {
                CreationTs = DateTimeOffset.Now.ToUnixTimeSeconds(),
                SentTs     = DateTimeOffset.Now.ToUnixTimeSeconds(),
                From       = "Test SMS",
                Cost       = new SendSmsCost
                {
                    Value    = 123.321,
                    Currency = "EUR"
                },
                Status = new SendSmsStatus
                {
                    SmsStatus = (SmsStatus)2
                }
            };
            var smsResponse = new SendSmsResponse(entry, MailjetSerialiser.Serialise(entry).ToString(), 200, true);

            var httpResponse = new HttpResponseMessage((HttpStatusCode)smsResponse.StatusCode)
            {
                Content = new StringContent(smsResponse.RawResponse.ToString())
            };
            var messageHandler = new Mock <HttpMessageHandler>();

            messageHandler.Protected().Setup <Task <HttpResponseMessage> >(methodName,
                                                                           ItExpr.Is <HttpRequestMessage>(a => a.RequestUri.ToString() == testUri),
                                                                           ItExpr.IsAny <CancellationToken>()).Returns(Task.FromResult(httpResponse));

            var httpClient   = new HttpClient(messageHandler.Object);
            var simpleClient = new MailjetSimpleClient();

            simpleClient.UseHttpClient(httpClient);
            options.Token = "SomeToken";
            var smsClient = new MailjetSmsClient(simpleClient, options);

            var res = await smsClient.SendAsync(new [] { smsMessage, smsMessage });

            Assert.All(res, response =>
            {
                Assert.Equal(entry.CreationTs, response.Data.CreationTs);
            });
        }
        public void Test_SerialiseUrlTagsOfBaseEmailMessage()
        {
            var propertyName     = "URLTags";
            var emailWithUrlTags = new BaseEmailMessageMock()
            {
                UrlTags = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("test", "true"),
                    new KeyValuePair <string, string>("cool", "false")
                }
            };
            var emailWithoutUrlTags = new BaseEmailMessageMock();

            var serialisedWithTags    = MailjetSerialiser.Serialise(emailWithUrlTags);
            var serialisedWithoutTags = MailjetSerialiser.Serialise(emailWithoutUrlTags);

            Assert.Equal("test=true&cool=false", serialisedWithTags.Value <string>(propertyName));
            Assert.Null(serialisedWithoutTags.Value <string>(propertyName));
        }
Ejemplo n.º 3
0
 protected void SetRequestBody(object obj, JsonSerializer jsonSerializer = null)
 {
     RequestBody = MailjetSerialiser.Serialise(obj, jsonSerializer);
 }