infobip / infobip-api-csharp-client

Infobip API client library in C#, distributed as a NuGet package.
https://www.infobip.com/docs/api
MIT License
11 stars 17 forks source link

Is there a way to create instances of SmsReport and SmsInbound Message? #12

Closed fenton-nick closed 2 years ago

fenton-nick commented 2 years ago

Both of these models have readonly properties. I'm having difficulty writing tests for our webhook endpoints using the Infobip.Api.Client.Model namespaces. Do you have any suggestions?

josipk-ib commented 2 years ago

Hi Nick, thank you for reporting this. It is indeed strange and unintended behaviour caused by our code generation process. We will try to fix it in our next sprint. I will let you know when we start working on this issue. Sorry for the inconvenience.

josipk-ib commented 2 years ago

Hi Nick,

to save you from waiting while we're fixing this I can suggest the alternative approach - use the JSON deserialisation to create objects. Here is an example how to create SmsReport object.

string json = @"
    {
        ""bulkId"": ""BULK-ID-123-xyz"",
        ""messageId"": ""MESSAGE-ID-123-xyz"",
        ""to"": ""41793026727"",
        ""sentAt"": ""2019-11-09T16:00:00.000+0000"",
        ""doneAt"": ""2019-11-09T16:00:00.000+0000"",
        ""smsCount"": 1,
        ""price"": {
            ""pricePerMessage"": 0.01,
            ""currency"": ""EUR""
        },
        ""status"": {
            ""groupId"": 3,
            ""groupName"": ""DELIVERED"",
            ""id"": 5,
            ""name"": ""DELIVERED_TO_HANDSET"",
            ""description"": ""Message delivered to handset""
        },
        ""error"": {
        ""groupId"": 0,
        ""groupName"": ""Ok"",
        ""id"": 0,
        ""name"": ""NO_ERROR"",
        ""description"": ""No Error"",
        ""permanent"": false
        }
    }";

var report = Newtonsoft.Json.JsonConvert.DeserializeObject<SmsReport>(json);
Console.WriteLine(report.Status.Description);

I hope you'll find this helpful.

fenton-nick commented 2 years ago

This is what I ended up doing. A little awkward but it works. Thank you for the follow up.