Skip to content

Commit

Permalink
ShouldThrowServiceExceptionOnLoadAssemblyIfExceptionOccurs -> FAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
LBoullosa committed May 25, 2024
1 parent b75ecc4 commit 5953b8a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,50 @@ public void ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExce

this.assemblyBroker.VerifyNoOtherCalls();
}

[Theory]
[MemberData(nameof(AssemblyLoadServiceExceptions))]
public 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
Expand Up @@ -85,5 +85,13 @@ public static TheoryData AssemblyLoadValidationDependencyExceptions()
new ArgumentException()
};
}

public static TheoryData AssemblyLoadServiceExceptions()
{
return new TheoryData<Exception>
{
new Exception()
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ----------------------------------------------------------------------------------
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using Xeptions;

namespace STX.SPAL.Core.Models.Services.Foundations.Assemblies.Exceptions
{
internal class AssemblyServiceException : Xeption
{
public AssemblyServiceException(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 System;
using Xeptions;

namespace STX.SPAL.Core.Models.Services.Foundations.Assemblies.Exceptions
{
internal class FailedAssemblyServiceException : Xeption
{
public FailedAssemblyServiceException(string message, Exception innerException)
: base(message, innerException)
{ }
}
}

0 comments on commit 5953b8a

Please sign in to comment.