-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6f8666
commit 0202a2e
Showing
14 changed files
with
207 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
FacadeFor3e.Tests/Resources/ExampleResponseFromODataExecute1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"@odata.context": "https://rdfin91tewa01.dentons.global/TE_3E_DEV_EU_REPORT/odata/$metadata#Office/$entity", | ||
"OfficeID": "29a69ad1-970b-4636-8ede-80d90cc0f222", | ||
"Code": "0000", | ||
"Description": "Default 2024-02-23T16:11:06", | ||
"OfficeTaxCodes": [], | ||
"OfficeAddressLangs": [], | ||
"OfficeTemplateTexts": [] | ||
} |
23 changes: 23 additions & 0 deletions
23
FacadeFor3e.Tests/Resources/ExampleResponseFromODataExecute2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"@odata.context":"https://rdfin91tewa01.elite.global/TE_3E_DEV_EU_REPORT/odata/$metadata#Proforma_ndt/$entity", | ||
"ProfMasterID":"54421a94-322c-470f-8224-2bda20a2264c", | ||
"ProfIndex":225360, | ||
"NxAttachments":[], | ||
"ProfMatters":[], | ||
"TRNValidationResultss":[], | ||
"ProfDetailTimes":[], | ||
"ProfDetailChrgs":[], | ||
"ProfDetailCosts":[], | ||
"ProfAdjusts":[], | ||
"ProfPayors":[], | ||
"ProfTrusts":[], | ||
"ProfUnallocateds":[], | ||
"ProfBOAs":[], | ||
"ProfTemplateOptions":[], | ||
"ProfPresParagraphs":[], | ||
"ProfMasterDates":[], | ||
"ProfTaxArticles":[], | ||
"ProfPayorLayers":[], | ||
"ProformaContacts_cccs":[], | ||
"ProfUDF_cccs":[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Text.Json; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
|
||
namespace FacadeFor3e.Tests | ||
{ | ||
[TestFixture] | ||
public class TestODataDeserialisation | ||
{ | ||
[Test] | ||
public void TestDeserialisation() | ||
{ | ||
var json = JsonDocument.Parse(Resources.ExampleProfPresParagraphs); | ||
|
||
var element = json.RootElement.GetProperty("value")[0].GetProperty("ProfPresParagraphs")[0]; | ||
var firstItem = element.JsonDeserialise<DbPresentationParagraph>(); | ||
ClassicAssert.AreEqual("ProfPresentationParagraph test", firstItem.Narrative); | ||
ClassicAssert.AreEqual(2.5m, firstItem.PresHours); | ||
ClassicAssert.AreEqual("sorted", firstItem.SortString); | ||
|
||
var result = json.RootElement.GetProperty("value")[0].GetProperty("ProfPresParagraphs").JsonDeserialiseList<DbPresentationParagraph>(); | ||
ClassicAssert.AreEqual(9, result.Count); | ||
#if NET6_0_OR_GREATER | ||
ClassicAssert.AreEqual(new DateOnly(2023, 09, 19), result[0].PresDate); | ||
#else | ||
ClassicAssert.AreEqual(new DateTime(2023, 09, 19), result[0].PresDate); | ||
#endif | ||
ClassicAssert.AreEqual("EUR", result[1].Currency); | ||
ClassicAssert.AreEqual(543.12, result[5].PresAmount); | ||
ClassicAssert.AreEqual(new Guid("d07726c1-2a71-4283-b82b-d6bbe2d079f7"), result[6].ProfPresentationParagraphId); | ||
ClassicAssert.IsNull(result[2].PresAmount); | ||
} | ||
} | ||
|
||
// ReSharper disable once ClassNeverInstantiated.Global | ||
public class DbPresentationParagraph | ||
{ | ||
// ReSharper disable UnassignedField.Global | ||
public Guid ProfPresentationParagraphId; | ||
#if NET6_0_OR_GREATER | ||
public DateOnly PresDate; | ||
#else | ||
public DateTime PresDate; | ||
#endif | ||
public string Currency; | ||
public decimal? PresAmount; | ||
public decimal? PresHours; | ||
public string Narrative; | ||
public string SortString; | ||
// ReSharper restore UnassignedField.Global | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
|
||
namespace FacadeFor3e.Tests | ||
{ | ||
[TestFixture] | ||
public class TestODataResponse | ||
{ | ||
[Test] | ||
public void TestStandardError() | ||
{ | ||
var response = @"{""error"":{""code"":"""",""message"":""Entity 'Proforma' with key '-100' does not exist.""}}"; | ||
var httpResponse = new HttpResponseMessage(HttpStatusCode.BadRequest); | ||
httpResponse.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(response)); | ||
httpResponse.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); | ||
var serviceResult = new ODataServiceResult(new HttpRequestMessage(HttpMethod.Get, "http://localhost/"), httpResponse); | ||
ClassicAssert.IsTrue(serviceResult.IsError); | ||
ClassicAssert.AreEqual(1, serviceResult.ErrorMessages.Count()); | ||
ClassicAssert.AreEqual("Entity 'Proforma' with key '-100' does not exist.", serviceResult.ErrorMessages.First()); | ||
} | ||
|
||
[Test] | ||
public void TestAlternativeError() | ||
{ | ||
var response = @"{ ""statusCode"": 429, ""message"": ""Rate limit is exceeded. Try again in 38 seconds."" }"; | ||
var httpResponse = new HttpResponseMessage(HttpStatusCode.BadRequest); | ||
httpResponse.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(response)); | ||
httpResponse.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); | ||
var serviceResult = new ODataServiceResult(new HttpRequestMessage(HttpMethod.Get, "http://localhost/"), httpResponse); | ||
ClassicAssert.IsTrue(serviceResult.IsError); | ||
ClassicAssert.AreEqual(1, serviceResult.ErrorMessages.Count()); | ||
ClassicAssert.AreEqual("Rate limit is exceeded. Try again in 38 seconds.", serviceResult.ErrorMessages.First()); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.