-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TECH-30764 Refactor the solution. Added Unit Test and fixed issues
- Loading branch information
1 parent
9ac4f81
commit 593cf4f
Showing
22 changed files
with
3,616 additions
and
1,664 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
samples/MyCRM.Lodgement.Common.Tests/MyCRM.Lodgement.Common.Tests.csproj
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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
<PackageReference Include="xunit" Version="2.5.3"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MyCRM.Lodgement.Core\MyCRM.Lodgement.Common.csproj" /> | ||
<ProjectReference Include="..\MyCRM.Lodgement.Sample\MyCRM.Lodgement.Sample.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
148 changes: 148 additions & 0 deletions
148
samples/MyCRM.Lodgement.Common.Tests/Utilities/LixiPackageSerializerTests.cs
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,148 @@ | ||
|
||
using LMGTech.DotNetLixi; | ||
using LMGTech.DotNetLixi.Models; | ||
using MyCRM.Lodgement.Common.Utilities; | ||
|
||
namespace MyCRM.Lodgement.Common.Tests; | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.IO; | ||
using Xunit; | ||
|
||
public class LixiPackageSerializerTests | ||
{ | ||
|
||
|
||
[Fact] | ||
public void Serialize_ShouldSerializeToJson_WhenMediaTypeIsJson_AndCountryIsAustralia() | ||
{ | ||
// Arrange | ||
var package = CreateTestPackage(); | ||
|
||
// Act | ||
var result = LixiPackageSerializer.Serialize(package, LixiCountry.Australia, "application/json"); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.Contains("\"@CompanyName\":\"Test Company\"", result); | ||
} | ||
|
||
[Fact] | ||
public void Serialize_ShouldSerializeToXml_WhenMediaTypeIsXml_AndCountryIsAustralia() | ||
{ | ||
// Arrange | ||
var package = CreateTestPackage(); | ||
|
||
// Act | ||
var result = LixiPackageSerializer.Serialize(package, LixiCountry.Australia, "application/xml"); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.Contains("CompanyName=\"Test Company\"", result); | ||
} | ||
|
||
|
||
|
||
[Fact] | ||
public void Serialize_ShouldSerializeToXml_WhenMediaTypeIsXml_AndCountryIsNewZealand() | ||
{ | ||
// Arrange | ||
var package = CreateTestPackage(); | ||
|
||
// Act | ||
var result = LixiPackageSerializer.Serialize(package, LixiCountry.NewZealand, "application/xml"); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.Contains("CompanyName=\"Test Company\"", result); | ||
} | ||
|
||
[Fact] | ||
public void Serialize_ShouldThrowNotImplementedException_WhenMediaTypeIsUnsupported() | ||
{ | ||
// Arrange | ||
var package = CreateTestPackage(); | ||
|
||
// Act & Assert | ||
var ex = Assert.Throws<NotImplementedException>(() => | ||
LixiPackageSerializer.Serialize(package, LixiCountry.Australia, "application/unsupported")); | ||
Assert.Equal("Media Type application/unsupported not supported.", ex.Message); | ||
} | ||
|
||
[Fact] | ||
public void Serialize_ShouldThrowArgumentNullException_WhenPackageIsNull() | ||
{ | ||
// Act & Assert | ||
Assert.Throws<ArgumentNullException>(() => | ||
LixiPackageSerializer.Serialize(null, LixiCountry.Australia, "application/json")); | ||
} | ||
|
||
[Fact] | ||
public void ObfuscateJson_ShouldObfuscateAllProperties_WhenNoPropertiesToObfuscateSpecified() | ||
{ | ||
// Arrange | ||
var package = JObject.FromObject(CreateTestPackage()); | ||
|
||
// Act | ||
var result = LixiPackageSerializer.ObfuscateJson(package); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.DoesNotContain("123456789", result); // BrokerApplicationReferenceNumber should be obfuscated | ||
Assert.DoesNotContain("Test Company", result); // CompanyName should be obfuscated | ||
Assert.DoesNotContain("test@gmail.com", result); // ABN should be obfuscated | ||
Assert.DoesNotContain("0450000111", result); // Phone number should be obfuscated | ||
} | ||
|
||
[Fact] | ||
public void ObfuscateJson_ShouldObfuscateOnlySpecifiedProperties() | ||
{ | ||
// Arrange | ||
var package = JObject.FromObject(CreateTestPackage()); | ||
string[] propertiesToObfuscate = { "CompanyName", "UniqueID" }; | ||
|
||
// Act | ||
var result = LixiPackageSerializer.ObfuscateJson(package, propertiesToObfuscate); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
Assert.DoesNotContain("LoanScenario-12345", result); // UniqueID should be obfuscated | ||
Assert.DoesNotContain("Test Company", result); // CompanyName should be obfuscated | ||
} | ||
|
||
|
||
private Package CreateTestPackage() | ||
{ | ||
return new Package | ||
{ | ||
// Populate with test data | ||
Content = new PackageContent | ||
{ | ||
Application = new Application | ||
{ | ||
SalesChannel = new SalesChannel() | ||
{ | ||
Company = new SalesChannelCompany() | ||
{ | ||
CompanyName = "Test Company", | ||
BusinessNumber = "123456789" | ||
}, | ||
LoanWriter = new SalesChannelLoanWriter() | ||
{ | ||
Contact = new SalesChannelLoanWriterContact() | ||
{ | ||
Email = "test@gmail.com", | ||
Mobile = new PhoneType() | ||
{ | ||
Number = "0450000111" | ||
} | ||
} | ||
} | ||
}, | ||
UniqueID = "LoanScenario-12345" | ||
} | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.