コード例 #1
0
        public async Task TestMessagingClientMessageAsync()
        {
            var client = new MessagingClient(this.customerId,
                                             this.apiKey,
                                             string.Format("http://localhost:{0}", this.mockServer.Port));

            await client.MessageAsync("15555555555", "TestMessagingClientMessage", "ARN");

            Assert.AreEqual("POST", this.requests.Last().HttpMethod, "method is not as expected");
            Assert.AreEqual("/v1/messaging", this.requests.Last().RawUrl, "path is not as expected");
            Assert.AreEqual("phone_number=15555555555&message=TestMessagingClientMessage&message_type=ARN", this.requestBodies.Last());
            Assert.AreEqual("application/x-www-form-urlencoded", this.requestHeaders.Last()["Content-Type"],
                            "Content-Type header is not as expected");
            Assert.AreEqual("HMAC-SHA256", this.requestHeaders.Last()["x-ts-auth-method"],
                            "x-ts-auth-method header is not as expected");

            Guid dummyGuid;

            Assert.IsTrue(Guid.TryParse(this.requestHeaders.Last()["x-ts-nonce"], out dummyGuid),
                          "x-ts-nonce header is not a valid UUID");

            DateTime dummyDateTime;

            Assert.IsTrue(DateTime.TryParse(this.requestHeaders.Last()["Date"], out dummyDateTime),
                          "Date header is not valid rfc2616 format");

            Assert.IsNotNull(this.requestHeaders.Last()["Authorization"]);
        }