Пример #1
0
        public void FullMessageDeserializesToMessageAndBack()
        {
            var messageJson = @"
    {
        ""class"": ""secret"",
        ""message"": ""Hello world"",
        ""payload"": ""cGF5bG9hZCBlbmNvZGVkIGFzIGI2NAo="",
        ""label"": ""Deathstar inc."",
        ""recipients"": [
            {
                ""msisdn"": 1514654321
            },
            {
                ""msisdn"": 1514654322
            }
        ],
        ""sender"": ""Test Sender"",
        ""sendtime"": 1602370861,
        ""userref"": ""1234"",
        ""priority"": ""URGENT"",
        ""validity_period"": 78,
        ""encoding"": ""UTF8"",
        ""destaddr"": ""MOBILE"",
        ""udh"": ""BQQLhCPw"",
        ""callback_url"": ""https://example.com/cb?foo=bar""
    }
";
            var message     = Deserializer.DeserializeMessage(messageJson);

            AssertionHelpers.AssertTwoJsonStringsAreEqual(messageJson, message.ToJson());
        }
Пример #2
0
        public void FullMessageObjectSerializesToJson()
        {
            var message = new Message
            {
                CallbackUrl    = "https://example.com/cb?foo=bar",
                Class          = MessageClass.Secret,
                MessageContent = "Hello world",
                Payload        = "cGF5bG9hZCBlbmNvZGVkIGFzIGI2NAo=",
                Label          = "Deathstar inc.",
                Sender         = new StringMessageSender("Test Sender"),
                SendTime       = new DateTime(2020, 10, 10, 23, 01, 01),
                UserReference  = "1234",
                Priority       = Priority.Urgent,
                ValidityPeriod = TimeSpan.FromSeconds(78),
                Encoding       = SmsEncoding.GSM_03_38,
                Destination    = Destination.Mobile,
                UDH            = "BQQLhCPw",
                Recipients     = new Recipient[]
                {
                    new Recipient
                    {
                        PhoneNumber = PhoneNumber.Create(1514654321)
                    },
                    new Recipient
                    {
                        PhoneNumber = PhoneNumber.Create(1514654322)
                    }
                }
            };

            var messageJson = message.ToJson();
            var resultJson  = @"
    {
        ""class"": ""secret"",
        ""message"": ""Hello world"",
        ""payload"": ""cGF5bG9hZCBlbmNvZGVkIGFzIGI2NAo="",
        ""label"": ""Deathstar inc."",
        ""recipients"": [
            {
                ""msisdn"": 1514654321
            },
            {
                ""msisdn"": 1514654322
            }
        ],
        ""sender"": ""Test Sender"",
        ""sendtime"": 1602370861,
        ""userref"": ""1234"",
        ""priority"": ""URGENT"",
        ""validity_period"": 78,
        ""encoding"": ""UTF8"",
        ""destaddr"": ""MOBILE"",
        ""udh"": ""BQQLhCPw"",
        ""callback_url"": ""https://example.com/cb?foo=bar""
    }
";

            AssertionHelpers.AssertTwoJsonStringsAreEqual(messageJson, resultJson);
        }
Пример #3
0
        public void DeserializeUsageDetails()
        {
            var usageDetailsJson = @"
{
    ""currency"": ""DKK"",
    ""total_cost"": 0.32
}
";
            var usageDetails     = Deserializer.DeserializeUsageDetails(usageDetailsJson);

            AssertionHelpers.AssertTwoJsonStringsAreEqual(usageDetailsJson, usageDetails.ToJson());
        }
        public void DeserializeMessageStatus()
        {
            var messageStatusJson = @"
{
    ""id"": 1000001,
    ""msisdn"": 4587654321,
    ""time"": 1602370861,
    ""status"": ""DELIVERED"",
    ""userref"": ""foobar""
}
";
            var messageStatus     = Core.Helpers.Deserializer.DeserializeMessageStatus(messageStatusJson);

            AssertionHelpers.AssertTwoJsonStringsAreEqual(messageStatusJson, messageStatus.ToJson());
        }
Пример #5
0
        public void SerializeUsageDetailsToJson()
        {
            var usageDetails = new UsageDetails
            {
                Currency  = "DKK",
                TotalCost = 0.32m
            };

            var resultJson = @"
{
    ""currency"": ""DKK"",
    ""total_cost"": 0.32
}
";

            AssertionHelpers.AssertTwoJsonStringsAreEqual(resultJson, usageDetails.ToJson());
        }
Пример #6
0
        public void SmallMessageDeserializesToMessageAndBack()
        {
            var messageJson = @"
    {
        ""class"": ""standard"",
        ""message"": ""Hello world"",
        ""recipients"": [
            {
                ""msisdn"": 1514654321
            }
        ],
        ""sender"": ""4529641389"",
        ""priority"": ""URGENT"",
        ""encoding"": ""UTF8""
    }
";
            var message     = Deserializer.DeserializeMessage(messageJson);

            AssertionHelpers.AssertTwoJsonStringsAreEqual(messageJson, message.ToJson());
        }
        public void SerializeMessageStatusToJson()
        {
            var messageStatus = new MessageStatus
            {
                MessageId     = 1000001,
                Recipient     = PhoneNumber.Create(4587654321),
                SendTimestamp = new DateTime(2020, 10, 10, 23, 01, 01),
                Status        = MessageDeliveryStatus.Delivered,
                UserReference = "foobar"
            };

            var resultJson = @"
{
    ""id"": 1000001,
    ""msisdn"": 4587654321,
    ""time"": 1602370861,
    ""status"": ""DELIVERED"",
    ""userref"": ""foobar""
}
";

            AssertionHelpers.AssertTwoJsonStringsAreEqual(resultJson, messageStatus.ToJson());
        }
Пример #8
0
        public void SmallMessageObjectSerializesToJson()
        {
            var message = new Message
            {
                Class          = MessageClass.Standard,
                MessageContent = "Hello world",
                Sender         = new PhoneNumberMessageSender(PhoneNumber.Create("+4529641389")),
                Priority       = Priority.Urgent,
                Encoding       = SmsEncoding.GSM_03_38,
                Recipients     = new Recipient[]
                {
                    new Recipient
                    {
                        PhoneNumber = PhoneNumber.Create(1514654321)
                    }
                }
            };

            var messageJson = message.ToJson();
            var resultJson  = @"
    {
        ""class"": ""standard"",
        ""message"": ""Hello world"",
        ""recipients"": [
            {
                ""msisdn"": 1514654321
            }
        ],
        ""sender"": ""4529641389"",
        ""priority"": ""URGENT"",
        ""encoding"": ""UTF8""
    }
";

            AssertionHelpers.AssertTwoJsonStringsAreEqual(messageJson, resultJson);
        }