-
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.
Merge pull request #9 from The-Standard-Organization/users/cjdutoit/e…
…xposers-serializationabstractionprovider-serialize-withinterfaces EXPOSERS: Serialization Abstraction Provider - Serialize
- Loading branch information
Showing
22 changed files
with
678 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...ialization.Providers.Abstractions.Tests.Unit/Models/Exceptions/TestDependencyException.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,16 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using STX.Serialization.Providers.Abstractions.Models.Exceptions; | ||
using Xeptions; | ||
|
||
namespace STX.Serialization.Providers.Abstractions.Tests.Unit.Models.Exceptions | ||
{ | ||
internal class TestDependencyException : Xeption, ISerializationDependencyException | ||
{ | ||
public TestDependencyException(string message, Xeption innerException) | ||
: base(message, innerException) | ||
{ } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
....Providers.Abstractions.Tests.Unit/Models/Exceptions/TestDependencyValidationException.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,16 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using STX.Serialization.Providers.Abstractions.Models.Exceptions; | ||
using Xeptions; | ||
|
||
namespace STX.Serialization.Providers.Abstractions.Tests.Unit.Models.Exceptions | ||
{ | ||
internal class TestDependencyValidationException : Xeption, ISerializationDependencyValidationException | ||
{ | ||
public TestDependencyValidationException(string message, Xeption innerException) | ||
: base(message, innerException) | ||
{ } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...Serialization.Providers.Abstractions.Tests.Unit/Models/Exceptions/TestServiceException.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,16 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using STX.Serialization.Providers.Abstractions.Models.Exceptions; | ||
using Xeptions; | ||
|
||
namespace STX.Serialization.Providers.Abstractions.Tests.Unit.Models.Exceptions | ||
{ | ||
internal class TestServiceException : Xeption, ISerializationServiceException | ||
{ | ||
public TestServiceException(string message, Xeption innerException) | ||
: base(message, innerException) | ||
{ } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ialization.Providers.Abstractions.Tests.Unit/Models/Exceptions/TestValidationException.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,16 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using STX.Serialization.Providers.Abstractions.Models.Exceptions; | ||
using Xeptions; | ||
|
||
namespace STX.Serialization.Providers.Abstractions.Tests.Unit.Models.Exceptions | ||
{ | ||
internal class TestValidationException : Xeption, ISerializationValidationException | ||
{ | ||
public TestValidationException(string message, Xeption innerException) | ||
: base(message, innerException) | ||
{ } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...viders.Abstractions.Tests.Unit/STX.Serialization.Providers.Abstractions.Tests.Unit.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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CleanMoq" Version="42.42.42" /> | ||
<PackageReference Include="Tynamix.ObjectFiller" Version="1.5.8" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\STX.Serialization.Providers.Abstractions\STX.Serialization.Providers.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
231 changes: 231 additions & 0 deletions
231
...ers.Abstractions.Tests.Unit/SerializationAbstractionProviderTests.Exceptions.Serialize.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,231 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Moq; | ||
using STX.Serialization.Providers.Abstractions.Models.Exceptions; | ||
using STX.Serialization.Providers.Abstractions.Tests.Unit.Models.Exceptions; | ||
using Xeptions; | ||
using Xunit; | ||
|
||
namespace STX.Serialization.Providers.Abstractions.Tests.Unit | ||
{ | ||
public partial class SerializationAbstractionProviderTests | ||
{ | ||
[Fact] | ||
public async Task ShouldCaptureAndLocaliseValidationExceptionsAsync() | ||
{ | ||
// given | ||
dynamic dynamicPerson = new | ||
{ | ||
Name = GetRandomString(), | ||
Surname = GetRandomString(), | ||
Age = GetRandomNumber() | ||
}; | ||
|
||
dynamic inputPerson = dynamicPerson; | ||
Xeption someException = new Xeption(message: "Some exception occurred."); | ||
|
||
TestValidationException testValidationException = | ||
new TestValidationException( | ||
message: "Serialization validation errors occurred, please try again.", | ||
innerException: someException); | ||
|
||
SerializationValidationProviderException expectedSerializationValidationProviderException = | ||
new SerializationValidationProviderException( | ||
message: "Serialization validation errors occurred, please try again.", | ||
innerException: testValidationException, | ||
data: testValidationException.Data); | ||
|
||
this.serializationProviderMock.Setup(provider => | ||
provider.Serialize(It.IsAny<object>())) | ||
.ThrowsAsync(testValidationException); | ||
|
||
// when | ||
ValueTask<string> serializationTask = | ||
this.serializationAbstractionProvider.Serialize(inputPerson); | ||
|
||
SerializationValidationProviderException actualSerializationValidationProviderException = | ||
await Assert.ThrowsAsync<SerializationValidationProviderException>( | ||
serializationTask.AsTask); | ||
|
||
// then | ||
actualSerializationValidationProviderException.Should() | ||
.BeEquivalentTo(expectedSerializationValidationProviderException); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCaptureAndLocaliseDependencyValidationExceptionsAsync() | ||
{ | ||
// given | ||
dynamic dynamicPerson = new | ||
{ | ||
Name = GetRandomString(), | ||
Surname = GetRandomString(), | ||
Age = GetRandomNumber() | ||
}; | ||
|
||
dynamic inputPerson = dynamicPerson; | ||
Xeption someException = new Xeption(message: "Some exception occurred."); | ||
|
||
TestDependencyValidationException testDependencyValidationException = | ||
new TestDependencyValidationException( | ||
message: "Serialization dependency validation errors occurred, please try again.", | ||
innerException: someException); | ||
|
||
SerializationValidationProviderException expectedSerializationValidationProviderException = | ||
new SerializationValidationProviderException( | ||
message: "Serialization validation errors occurred, please try again.", | ||
innerException: testDependencyValidationException, | ||
data: testDependencyValidationException.Data); | ||
|
||
this.serializationProviderMock.Setup(provider => | ||
provider.Serialize(It.IsAny<object>())) | ||
.ThrowsAsync(testDependencyValidationException); | ||
|
||
// when | ||
ValueTask<string> serializationTask = | ||
this.serializationAbstractionProvider.Serialize(inputPerson); | ||
|
||
SerializationValidationProviderException actualSerializationValidationProviderException = | ||
await Assert.ThrowsAsync<SerializationValidationProviderException>( | ||
serializationTask.AsTask); | ||
|
||
// then | ||
actualSerializationValidationProviderException.Should() | ||
.BeEquivalentTo(expectedSerializationValidationProviderException); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCaptureAndLocaliseDependencyExceptionsAsync() | ||
{ | ||
// given | ||
dynamic dynamicPerson = new | ||
{ | ||
Name = GetRandomString(), | ||
Surname = GetRandomString(), | ||
Age = GetRandomNumber() | ||
}; | ||
|
||
dynamic inputPerson = dynamicPerson; | ||
Xeption someException = new Xeption(message: "Some exception occurred."); | ||
|
||
TestDependencyException testDependencyException = | ||
new TestDependencyException( | ||
message: "Serialization dependency error occurred, contact support.", | ||
innerException: someException); | ||
|
||
SerializationDependencyProviderException expectedSerializationDependencyProviderException = | ||
new SerializationDependencyProviderException( | ||
message: "Serialization dependency error occurred, contact support.", | ||
innerException: testDependencyException, | ||
data: testDependencyException.Data); | ||
|
||
this.serializationProviderMock.Setup(provider => | ||
provider.Serialize(It.IsAny<object>())) | ||
.ThrowsAsync(testDependencyException); | ||
|
||
// when | ||
ValueTask<string> serializationTask = | ||
this.serializationAbstractionProvider.Serialize(inputPerson); | ||
|
||
SerializationDependencyProviderException actualSerializationDependencyProviderException = | ||
await Assert.ThrowsAsync<SerializationDependencyProviderException>( | ||
serializationTask.AsTask); | ||
|
||
// then | ||
actualSerializationDependencyProviderException.Should() | ||
.BeEquivalentTo(expectedSerializationDependencyProviderException); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCaptureAndLocaliseServiceExceptionsAsync() | ||
{ | ||
// given | ||
dynamic dynamicPerson = new | ||
{ | ||
Name = GetRandomString(), | ||
Surname = GetRandomString(), | ||
Age = GetRandomNumber() | ||
}; | ||
|
||
dynamic inputPerson = dynamicPerson; | ||
Xeption someException = new Xeption(message: "Some exception occurred."); | ||
|
||
TestServiceException testServiceException = | ||
new TestServiceException( | ||
message: "Serialization service error occurred, contact support.", | ||
innerException: someException); | ||
|
||
SerializationServiceProviderException expectedSerializationServiceProviderException = | ||
new SerializationServiceProviderException( | ||
message: "Serialization service error occurred, contact support.", | ||
innerException: testServiceException, | ||
data: testServiceException.Data); | ||
|
||
this.serializationProviderMock.Setup(provider => | ||
provider.Serialize(It.IsAny<object>())) | ||
.ThrowsAsync(testServiceException); | ||
|
||
// when | ||
ValueTask<string> serializationTask = | ||
this.serializationAbstractionProvider.Serialize(inputPerson); | ||
|
||
SerializationServiceProviderException actualSerializationServiceProviderException = | ||
await Assert.ThrowsAsync<SerializationServiceProviderException>( | ||
serializationTask.AsTask); | ||
|
||
// then | ||
actualSerializationServiceProviderException.Should() | ||
.BeEquivalentTo(expectedSerializationServiceProviderException); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCaptureAndLocaliseAnyNonServiceExceptionsAsync() | ||
{ | ||
// given | ||
dynamic dynamicPerson = new | ||
{ | ||
Name = GetRandomString(), | ||
Surname = GetRandomString(), | ||
Age = GetRandomNumber() | ||
}; | ||
|
||
dynamic inputPerson = dynamicPerson; | ||
Exception someException = new Exception(message: "Some exception occurred."); | ||
|
||
UncatagorizedSerializationProviderException notImplementedSerializationProviderException = | ||
new UncatagorizedSerializationProviderException( | ||
message: "Serialization provider not properly implemented. Uncatagorized errors found, " + | ||
"contact the serialization provider owner for support.", | ||
|
||
innerException: someException, | ||
data: someException.Data); | ||
|
||
SerializationServiceProviderException expectedSerializationServiceProviderException = | ||
new SerializationServiceProviderException( | ||
message: "Uncatagorized serialization service error occurred, contact support.", | ||
innerException: notImplementedSerializationProviderException, | ||
data: notImplementedSerializationProviderException.Data); | ||
|
||
this.serializationProviderMock.Setup(provider => | ||
provider.Serialize(It.IsAny<object>())) | ||
.ThrowsAsync(someException); | ||
|
||
// when | ||
ValueTask<string> serializationTask = | ||
this.serializationAbstractionProvider.Serialize(inputPerson); | ||
|
||
SerializationServiceProviderException actualSerializationServiceProviderException = | ||
await Assert.ThrowsAsync<SerializationServiceProviderException>( | ||
serializationTask.AsTask); | ||
|
||
// then | ||
actualSerializationServiceProviderException.Should() | ||
.BeEquivalentTo(expectedSerializationServiceProviderException); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...roviders.Abstractions.Tests.Unit/SerializationAbstractionProviderTests.Logic.Serialize.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,41 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace STX.Serialization.Providers.Abstractions.Tests.Unit | ||
{ | ||
public partial class SerializationAbstractionProviderTests | ||
{ | ||
[Fact] | ||
public async Task ShouldSerializeAsync() | ||
{ | ||
// given | ||
dynamic somePerson = new | ||
{ | ||
Name = GetRandomString(), | ||
Surname = GetRandomString(), | ||
Age = GetRandomNumber() | ||
}; | ||
|
||
dynamic inputPerson = somePerson; | ||
string randomString = GetRandomString(); | ||
string outputString = GetRandomString(); | ||
string expectedString = outputString; | ||
|
||
this.serializationProviderMock.Setup(provider => | ||
provider.Serialize(It.IsAny<object>())) | ||
.ReturnsAsync(outputString); | ||
|
||
// when | ||
string actualString = await this.serializationAbstractionProvider.Serialize(inputPerson); | ||
|
||
// then | ||
actualString.Should().BeEquivalentTo(expectedString); | ||
} | ||
} | ||
} |
Oops, something went wrong.