-
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 #6 from The-Standard-Organization/users/lboullosa/…
…foundations-assembly FOUNDATIONS: Assembly Service
- Loading branch information
Showing
19 changed files
with
777 additions
and
10 deletions.
There are no files selected for viewing
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
150 changes: 150 additions & 0 deletions
150
...Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Exceptions.GetAssembly.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,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(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...rvices/Foundations/Assemblies/AssemblyServiceTests.Logic.GetApplicationPathsAssemblies.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,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(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Logic.GetAssembly.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,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(); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...ests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Validations.GetAssembly.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,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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.