Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXPOSERS: Serialization Abstraction Provider - Serialize #9

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
920da75
ShouldSerializeAsync -> FAIL
cjdutoit Jan 30, 2024
1cd3f80
ShouldSerializeAsync -> PASS
cjdutoit Jan 30, 2024
7d76083
ShouldCaptureAndLocaliseValidationExceptionsAsync -> FAIL
cjdutoit Jan 30, 2024
6b055f1
ShouldCaptureAndLocaliseValidationExceptionsAsync -> PASS
cjdutoit Jan 31, 2024
66b7a55
ShouldCaptureAndLocaliseDependencyValidationExceptionsAsync -> FAIL
cjdutoit Jan 31, 2024
51f5916
ShouldCaptureAndLocaliseDependencyValidationExceptionsAsync -> PASS
cjdutoit Jan 31, 2024
437c4b9
ShouldCaptureAndLocaliseDependencyExceptionsAsync -> FAIL
cjdutoit Jan 31, 2024
d673798
ShouldCaptureAndLocaliseDependencyExceptionsAsync -> PASS
cjdutoit Jan 31, 2024
f05df81
ShouldCaptureAndLocaliseServiceExceptionsAsync -> FAIL
cjdutoit Jan 31, 2024
9c8c607
ShouldCaptureAndLocaliseServiceExceptionsAsync -> PASS
cjdutoit Jan 31, 2024
347e109
ShouldCaptureAndLocaliseAnyNonServiceExceptionsAsync -> FAIL
cjdutoit Jan 31, 2024
328e7c1
ShouldCaptureAndLocaliseAnyNonServiceExceptionsAsync -> PASS
cjdutoit Jan 31, 2024
41f9d16
Merge branch 'main' into users/cjdutoit/exposers-serializationabstrac…
cjdutoit Jan 31, 2024
45ca33e
CODE RUB: Code cleanup
cjdutoit Feb 1, 2024
bb55d59
CODE RUB: Code cleanup
cjdutoit Feb 1, 2024
671f7e8
CODE RUB: Replaced the abstract classes with interfaces
cjdutoit Feb 2, 2024
a80846a
CODE RUB: Code clean-up
cjdutoit Feb 2, 2024
6d68e5a
Merge branch 'main' into users/cjdutoit/exposers-serializationabstrac…
cjdutoit Feb 2, 2024
0406402
CODE RUB: Code cleanup
cjdutoit Feb 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
{ }
}
}
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)
{ }
}
}
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)
{ }
}
}
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)
{ }
}
}
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>
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.",
cjdutoit marked this conversation as resolved.
Show resolved Hide resolved

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);
}
}
}
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);
}
}
}
Loading
Loading