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

FOUNDATIONS: Assembly Service #6

Merged
merged 19 commits into from
May 30, 2024
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
625ed7d
ShouldGetApplicationPathAssemblies -> FAIL
LBoullosa May 22, 2024
420e32b
ShouldGetApplicationPathAssemblies -> PASS
LBoullosa May 22, 2024
2726cad
MINOR FIX: Add fluent assertion package
LBoullosa May 23, 2024
438aee8
ShouldGetAssembly -> FAIL
LBoullosa May 23, 2024
21dd7b8
CODE RUB: Remove unused usings
LBoullosa May 23, 2024
abb34d2
ShouldGetAssembly -> PASS
LBoullosa May 23, 2024
313ab5c
ShouldThrowExceptionIfInvalidAssemblyPath -> FAIL
LBoullosa May 23, 2024
2a9c54b
ShouldThrowValidationExceptionIfInvalidAssemblyPath -> PASS
LBoullosa May 23, 2024
6009806
CODE RUB: Fix naming variables
LBoullosa May 23, 2024
7c5db2d
CODE RUB: Code cleanup
cjdutoit May 23, 2024
ec0d6af
ShouldThrowDependencyExceptionOnLoadAssemblyIfExternalExceptionOccurs…
LBoullosa May 25, 2024
0d909c1
ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExcep…
LBoullosa May 25, 2024
3d64b97
ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExcep…
LBoullosa May 25, 2024
6721c49
ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExcep…
LBoullosa May 25, 2024
b75ecc4
ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExcep…
LBoullosa May 25, 2024
5953b8a
ShouldThrowServiceExceptionOnLoadAssemblyIfExceptionOccurs -> FAIL
LBoullosa May 25, 2024
b452d36
ShouldThrowServiceExceptionOnLoadAssemblyIfExceptionOccurs -> PASS
LBoullosa May 25, 2024
0ec015d
CODE RUB: Fix returning void instead Task
LBoullosa May 26, 2024
7e2da07
CODE RUB: Change all tests methods to private
LBoullosa May 27, 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
11 changes: 9 additions & 2 deletions STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -9,7 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="CleanMoq" Version="1.0.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Tynamix.ObjectFiller" Version="1.5.8" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -25,4 +28,8 @@
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\STX.SPAL.Core\STX.SPAL.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// ----------------------------------------------------------------------------------
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System;
using System.Reflection;
using FluentAssertions;
using Moq;
using STX.SPAL.Core.Models.Services.Foundations.Assemblies.Exceptions;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.Assemblies
{
public partial class AssemblyServiceTests
{
[Theory]
[MemberData(nameof(AssemblyLoadDependencyExceptions))]
private void ShouldThrowDependencyExceptionOnLoadAssemblyIfExternalExceptionOccurs(
Exception externalException)
{
// given
string someAssemblyPath = CreateRandomPathAssembly();

var assemblyLoadException =
new AssemblyLoadException(
message: "Assembly load error occurred, contact support.",
innerException: externalException);

var expectedAssemblyDependencyException =
new AssemblyDependencyException(
message: "Assembly dependency error occurred, contact support.",
innerException: assemblyLoadException);

this.assemblyBroker
.Setup(broker =>
broker.GetAssembly(
It.Is<string>(actualAssemblyPath =>
actualAssemblyPath == someAssemblyPath)))
.Throws(externalException);

// when
Func<Assembly> getAssemblyFunction = () =>
this.assemblyService.GetAssembly(someAssemblyPath);

AssemblyDependencyException actualAssemblyDependencyException =
Assert.Throws<AssemblyDependencyException>(
getAssemblyFunction);

//then
actualAssemblyDependencyException.Should().BeEquivalentTo(
expectedAssemblyDependencyException);

this.assemblyBroker
.Verify(broker =>
broker.GetAssembly(It.IsAny<string>()),
Times.Once);

this.assemblyBroker.VerifyNoOtherCalls();
}

[Theory]
[MemberData(nameof(AssemblyLoadValidationDependencyExceptions))]
private void ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExceptionOccurs(
Exception externalException)
{
// given
string someAssemblyPath = CreateRandomPathAssembly();

var assemblyLoadException =
new AssemblyLoadException(
message: "Assembly load error occurred, contact support.",
innerException: externalException);

var expectedAssemblyValidationDependencyException =
new AssemblyValidationDependencyException(
message: "Assembly validation dependency error occurred, contact support.",
innerException: assemblyLoadException);

this.assemblyBroker
.Setup(broker =>
broker.GetAssembly(
It.Is<string>(actualAssemblyPath =>
actualAssemblyPath == someAssemblyPath)))
.Throws(externalException);

// when
Func<Assembly> getAssemblyFunction = () =>
this.assemblyService.GetAssembly(someAssemblyPath);

AssemblyValidationDependencyException actualAssemblyValidationDependencyException =
Assert.Throws<AssemblyValidationDependencyException>(
getAssemblyFunction);

//then
actualAssemblyValidationDependencyException.Should().BeEquivalentTo(
expectedAssemblyValidationDependencyException);

this.assemblyBroker
.Verify(broker =>
broker.GetAssembly(It.IsAny<string>()),
Times.Once);

this.assemblyBroker.VerifyNoOtherCalls();
}

[Theory]
[MemberData(nameof(AssemblyLoadServiceExceptions))]
private void ShouldThrowServiceExceptionOnLoadAssemblyIfExceptionOccurs(
Exception externalException)
{
// given
string someAssemblyPath = CreateRandomPathAssembly();

var assemblyLoadException =
new FailedAssemblyServiceException(
message: "Failed service error occurred, contact support.",
innerException: externalException);

var expectedAssemblyServiceException =
new AssemblyServiceException(
message: "Assembly service error occurred, contact support.",
innerException: assemblyLoadException);

this.assemblyBroker
.Setup(broker =>
broker.GetAssembly(
It.Is<string>(actualAssemblyPath =>
actualAssemblyPath == someAssemblyPath)))
.Throws(externalException);

// when
Func<Assembly> getAssemblyFunction = () =>
this.assemblyService.GetAssembly(someAssemblyPath);

AssemblyServiceException actualAssemblyServiceException =
Assert.Throws<AssemblyServiceException>(
getAssemblyFunction);

//then
actualAssemblyServiceException.Should().BeEquivalentTo(
expectedAssemblyServiceException);

this.assemblyBroker
.Verify(broker =>
broker.GetAssembly(It.IsAny<string>()),
Times.Once);

this.assemblyBroker.VerifyNoOtherCalls();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ----------------------------------------------------------------------------------
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.Threading.Tasks;
using FluentAssertions;
using Moq;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.Assemblies
{
public partial class AssemblyServiceTests
{
[Fact]
private void ShouldGetApplicationPathAssemblies()
{
// given
string[] randomApplicationPathsAssemblies =
CreateRandomPathArray();

string[] expectedApplicationPathsAssemblies =
randomApplicationPathsAssemblies;

string[] returnedApplicationPathsAssemblies =
randomApplicationPathsAssemblies;

this.assemblyBroker
.Setup(broker => broker.GetApplicationPathsAssemblies())
.Returns(returnedApplicationPathsAssemblies);

// when
string[] actualApplicationPathsAssemblies =
this.assemblyService.GetApplicationPathsAssemblies();

//then
actualApplicationPathsAssemblies.Should()
.BeEquivalentTo(expectedApplicationPathsAssemblies);

this.assemblyBroker.Verify(
broker =>
broker.GetApplicationPathsAssemblies(),
Times.Once);

this.assemblyBroker.VerifyNoOtherCalls();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ----------------------------------------------------------------------------------
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.Reflection;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.Assemblies
{
public partial class AssemblyServiceTests
{
[Fact]
private void ShouldGetAssembly()
{
// given
Assembly randomAssembly = CreateRandomAssembly();
Assembly expectedAssembly = randomAssembly;
Assembly returnedAssembly = randomAssembly;
string randomPathAssembly = CreateRandomPathAssembly();
string inputPathAssembly = randomPathAssembly;

this.assemblyBroker
.Setup(broker =>
broker.GetAssembly(
It.Is<string>(actualPathAssembly =>
actualPathAssembly == inputPathAssembly)))
.Returns(returnedAssembly);

// when
Assembly actualAssembly =
this.assemblyService.GetAssembly(inputPathAssembly);

//then
actualAssembly.Should().BeSameAs(expectedAssembly);

this.assemblyBroker.Verify(
broker =>
broker.GetAssembly(
It.Is<string>(actualPathAssembly =>
actualPathAssembly == inputPathAssembly)),
Times.Once);

this.assemblyBroker.VerifyNoOtherCalls();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// ----------------------------------------------------------------------------------
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System;
using System.Reflection;
using FluentAssertions;
using Moq;
using STX.SPAL.Core.Models.Services.Foundations.Assemblies.Exceptions;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.Assemblies
{
public partial class AssemblyServiceTests
{
[Theory]
[InlineData(null, "Value is required")]
[InlineData("", "Value is required")]
[InlineData(" ", "Value is required")]
[InlineData("file", "Value is not a valid assembly path")]
private void ShouldThrowValidationExceptionIfInvalidAssemblyPath(
string assemblyPath,
string exceptionMessage)
{
// given
Assembly randomAssembly = CreateRandomAssembly();
Assembly expectedAssembly = randomAssembly;
Assembly returnedAssembly = randomAssembly;
string randomPathAssembly = CreateRandomPathAssembly();
string inputAssemblyPath = assemblyPath;

var invalidAssemblyPathException =
new InvalidAssemblyPathException(
message: "Invalid assembly path error occurred, fix errors and try again.");

invalidAssemblyPathException.AddData(
key: nameof(assemblyPath),
values: exceptionMessage
);

var expectedAssemblyValidationException =
new AssemblyValidationException(
message: "Assembly validation error occurred, fix errors and try again.",
innerException: invalidAssemblyPathException);

this.assemblyBroker
.Setup(broker =>
broker.GetAssembly(
It.Is<string>(actualAssemblyPath =>
actualAssemblyPath == inputAssemblyPath)));

// when
Func<Assembly> getAssemblyFunction = () =>
this.assemblyService.GetAssembly(inputAssemblyPath);

AssemblyValidationException actualAssemblyValidationException =
Assert.Throws<AssemblyValidationException>(
getAssemblyFunction);

//then
actualAssemblyValidationException.Should().BeEquivalentTo(
expectedAssemblyValidationException);

this.assemblyBroker
.Verify(broker =>
broker.GetAssembly(It.IsAny<string>()),
Times.Never);

this.assemblyBroker.VerifyNoOtherCalls();
}
}
}
Loading
Loading