Skip to content

Commit

Permalink
Release candidate 3
Browse files Browse the repository at this point in the history
  • Loading branch information
JonSaffron committed May 14, 2024
1 parent c6f8666 commit 0202a2e
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 423 deletions.
10 changes: 3 additions & 7 deletions FacadeFor3e.Tests/FacadeFor3e.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="TestODataUpdate.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NLog" Version="5.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NLog" Version="5.3.2" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions FacadeFor3e.Tests/Resources/ExampleProfPresParagraphs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@odata.context": "https://rdfin91tewa01.dentons.global/TE_3E_DEV_EU_REPORT/odata/$metadata#Proforma_ndt(ProfPresParagraphs)",
"@odata.context": "https://rdfin91tewa01.elite.global/TE_3E_DEV_EU_REPORT/odata/$metadata#Proforma_ndt(ProfPresParagraphs)",
"value": [
{
"ProfPresParagraphs": [
Expand All @@ -14,7 +14,7 @@
"Currency": "EUR",
"PresAmount": 1464.77,
"PresHours": 2.5,
"Narrative": "505533b2-2df1-4ffa-bf16-31c3351c408e",
"Narrative": "ProfPresentationParagraph test",
"SortString": "sorted",
"ProfMaster": 225370
},
Expand Down
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 FacadeFor3e.Tests/Resources/ExampleResponseFromODataExecute2.json
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":[]
}
53 changes: 53 additions & 0 deletions FacadeFor3e.Tests/TestODataDeserialisation.cs
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
}
}
41 changes: 41 additions & 0 deletions FacadeFor3e.Tests/TestODataResponse.cs
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());
}
}
}

Loading

0 comments on commit 0202a2e

Please sign in to comment.