Skip to content

Commit

Permalink
Merge pull request #531 from XeroAPI/Fix-513-Dotnet-SDK
Browse files Browse the repository at this point in the history
Fix-513 | System.MissingMethodException with latest RestSharp client
  • Loading branch information
sangeet-joy-tw authored Aug 22, 2024
2 parents a29b8cf + 399fb37 commit 41d3580
Show file tree
Hide file tree
Showing 57 changed files with 1,362 additions and 1,050 deletions.
1 change: 0 additions & 1 deletion Xero.NetStandard.OAuth2.Test/Api/AccountingApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using RestSharp;
using Xunit;
using System.Threading.Tasks;
using AutoBogus;
Expand Down
1 change: 0 additions & 1 deletion Xero.NetStandard.OAuth2.Test/Api/BankFeedsApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using RestSharp;
using Xunit;

using Xero.NetStandard.OAuth2.Client;
Expand Down
1 change: 0 additions & 1 deletion Xero.NetStandard.OAuth2.Test/Api/PayrollAuApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using RestSharp;
using Xunit;

using Xero.NetStandard.OAuth2.Client;
Expand Down
1 change: 0 additions & 1 deletion Xero.NetStandard.OAuth2.Test/Api/PayrollNzApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using RestSharp;
using Xunit;

using Xero.NetStandard.OAuth2.Client;
Expand Down
1 change: 0 additions & 1 deletion Xero.NetStandard.OAuth2.Test/Client/ApiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using RestSharp;
using Xunit;
using System.Threading.Tasks;
using AutoBogus;
Expand Down
29 changes: 21 additions & 8 deletions Xero.NetStandard.OAuth2.Test/Helpers/JsonDoc.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using RestSharp;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xero.NetStandard.OAuth2.Client;
using Xunit;
using Xunit.Sdk;
Expand Down Expand Up @@ -75,23 +78,33 @@ public string GetJsonRepresentation()
}
}

public static void Assert<TModel, TProperty>(IJsonValue input, Func<TModel, TProperty> toProperty, TProperty shouldBe)
public static async Task Assert<TModel, TProperty>(IJsonValue input, Func<TModel, TProperty> toProperty, TProperty shouldBe)
{
var response = new RestResponse();

HttpResponseMessage response;
if (input is NotPresent)
{
response.Content = "{}";
response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("{}", Encoding.UTF8, "application/json")
};
}
else
{
response.Content = $@"{{
var jsonContent = $@"{{
""{input.PropertyName}"": {input.GetJsonRepresentation()}
}}";

response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};
}
response.StatusCode = System.Net.HttpStatusCode.OK;

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var output = deserializer.Deserialize<TModel>(response);
var output = await deserializer.Deserialize<TModel>(response);

Xunit.Assert.Equal(shouldBe, toProperty(output));
}
}
Expand Down
21 changes: 15 additions & 6 deletions Xero.NetStandard.OAuth2.Test/Model/Accounting/InvoiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Xero.NetStandard.OAuth2.Api;
using Xero.NetStandard.OAuth2.Model;
using Xero.NetStandard.OAuth2.Client;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using RestSharp;
using Xero.NetStandard.OAuth2.Model.Accounting;

namespace Xero.NetStandard.OAuth2.Test.Model.Accounting
Expand Down Expand Up @@ -193,16 +196,22 @@ public void PlannedPaymentDateTest()
[Theory]
[InlineData("20.00")]
[InlineData("20")]
public void CISDeduction_IsNumber_DeserializesCorrectly(string number)
public async Task CISDeduction_IsNumber_DeserializesCorrectly(string number)
{
var response = new RestResponse();
response.Content = $@"{{
string jsonContent = $@"{{
""CISDeduction"": {number}
}}";
response.StatusCode = System.Net.HttpStatusCode.OK;

var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var invoices = deserializer.Deserialize<Invoice>(response);
var invoices = await deserializer.Deserialize<Invoice>(response);


Assert.Equal(20, invoices.CISDeduction);
}
Expand Down
43 changes: 28 additions & 15 deletions Xero.NetStandard.OAuth2.Test/Model/Bankfeeds/CountryCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Xero.NetStandard.OAuth2.Api;
using Xero.NetStandard.OAuth2.Model.Bankfeeds;
using Xero.NetStandard.OAuth2.Client;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using RestSharp;

namespace Xero.NetStandard.OAuth2.Test.Model.Bankfeeds
{
Expand Down Expand Up @@ -50,31 +53,41 @@ public void Dispose()
[Theory]
[InlineData("AU", CountryCode.AU)]
[InlineData("NZ", CountryCode.NZ)]
public void CountryCode_ValidInput_Deserialises(string input, CountryCode expected)
public async Task CountryCode_ValidInput_Deserialises(string input, CountryCode expected)
{
var response = new RestResponse();
response.Content = $@"""{input}""";
response.StatusCode = System.Net.HttpStatusCode.OK;

string jsonContent = $@"""{input}""";

var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var actual = deserializer.Deserialize<CountryCode>(response);

var actual = await deserializer.Deserialize<CountryCode>(response);
Assert.Equal(expected, actual);
}

/// <summary>
/// Test that CountryCode can be deserialised from null into 0
/// </summary>
[Fact]
public void CountryCode_NullInput_Deserialises()
public async Task CountryCode_NullInput_Deserialises()
{
var response = new RestResponse();
response.Content = "null";
response.StatusCode = System.Net.HttpStatusCode.OK;

string jsonContent = "null";

var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var actual = deserializer.Deserialize<CountryCode>(response);

var actual = await deserializer.Deserialize<CountryCode>(response);
Assert.Equal(0, (int)actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Xero.NetStandard.OAuth2.Api;
using Xero.NetStandard.OAuth2.Model.Bankfeeds;
using Xero.NetStandard.OAuth2.Client;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using RestSharp;

namespace Xero.NetStandard.OAuth2.Test.Model.Bankfeeds
{
Expand Down Expand Up @@ -50,31 +53,41 @@ public void Dispose()
[Theory]
[InlineData("CREDIT", CreditDebitIndicator.CREDIT)]
[InlineData("DEBIT", CreditDebitIndicator.DEBIT)]
public void CreditDebitIndicator_ValidInput_Deserialises(string input, CreditDebitIndicator expected)
public async Task CreditDebitIndicator_ValidInput_Deserialises(string input, CreditDebitIndicator expected)
{
var response = new RestResponse();
response.Content = $@"""{input}""";
response.StatusCode = System.Net.HttpStatusCode.OK;

string jsonContent = $@"""{input}""";

var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var actual = deserializer.Deserialize<CreditDebitIndicator>(response);

var actual = await deserializer.Deserialize<CreditDebitIndicator>(response);
Assert.Equal(expected, actual);
}

/// <summary>
/// Test that CreditDebitIndicator can be deserialised from null into 0
/// </summary>
[Fact]
public void CreditDebitIndicator_NullInput_Deserialises()
public async Task CreditDebitIndicator_NullInput_Deserialises()
{
var response = new RestResponse();
response.Content = "null";
response.StatusCode = System.Net.HttpStatusCode.OK;

string jsonContent = "null";

var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var actual = deserializer.Deserialize<CreditDebitIndicator>(response);

var actual = await deserializer.Deserialize<CreditDebitIndicator>(response);
Assert.Equal(0, (int)actual);
}

Expand Down
43 changes: 28 additions & 15 deletions Xero.NetStandard.OAuth2.Test/Model/Bankfeeds/CurrencyCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Xero.NetStandard.OAuth2.Api;
using Xero.NetStandard.OAuth2.Model.Bankfeeds;
using Xero.NetStandard.OAuth2.Client;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using RestSharp;

namespace Xero.NetStandard.OAuth2.Test.Model.Bankfeeds
{
Expand Down Expand Up @@ -50,31 +53,41 @@ public void Dispose()
[Theory]
[InlineData("AUD", CurrencyCode.AUD)]
[InlineData("NZD", CurrencyCode.NZD)]
public void CurrencyCode_ValidInput_Deserialises(string input, CurrencyCode expected)
public async Task CurrencyCode_ValidInput_Deserialises(string input, CurrencyCode expected)
{
var response = new RestResponse();
response.Content = $@"""{input}""";
response.StatusCode = System.Net.HttpStatusCode.OK;

string jsonContent = $@"""{input}""";

var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var actual = deserializer.Deserialize<CurrencyCode>(response);

var actual = await deserializer.Deserialize<CurrencyCode>(response);
Assert.Equal(expected, actual);
}

/// <summary>
/// Test that CurrencyCode can be deserialised from null into 0
/// </summary>
[Fact]
public void CurrencyCode_NullInput_Deserialises()
public async Task CurrencyCode_NullInput_Deserialises()
{
var response = new RestResponse();
response.Content = "null";
response.StatusCode = System.Net.HttpStatusCode.OK;

string jsonContent = "null";

var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(jsonContent, Encoding.UTF8, "application/json")
};

response.EnsureSuccessStatusCode();

var deserializer = new CustomJsonCodec(new Configuration());
var actual = deserializer.Deserialize<CurrencyCode>(response);

var actual = await deserializer.Deserialize<CurrencyCode>(response);
Assert.Equal(0, (int)actual);
}

Expand Down
Loading

0 comments on commit 41d3580

Please sign in to comment.