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);
            });
        }
Ejemplo n.º 2
0
        public void Test_ValidateTimestampSendSmsResponseEntry()
        {
            var expectedCreation = DateTimeOffset.UtcNow;
            var expectedSent     = DateTimeOffset.Now.AddDays(1);

            var entry = new SendSmsResponseEntry
            {
                CreationTs = expectedCreation.ToUnixTimeSeconds(),
                SentTs     = expectedSent.ToUnixTimeSeconds()
            };

            Assert.Equal(expectedCreation.ToUnixTimeSeconds(), entry.CreationTs);
            Assert.Equal(expectedSent.ToUnixTimeSeconds(), entry.SentTs);

            Assert.Equal(DateTimeOffset.FromUnixTimeSeconds(entry.CreationTs).UtcDateTime, entry.CreationTimestamp);
            Assert.Equal(DateTimeOffset.FromUnixTimeSeconds(entry.SentTs).UtcDateTime, entry.SentTimestamp);
        }