From 5953b8a44b774b0036c09322268247e9f70fb10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20LB?= Date: Sat, 25 May 2024 19:50:28 +0200 Subject: [PATCH] ShouldThrowServiceExceptionOnLoadAssemblyIfExceptionOccurs -> FAIL --- ...mblyServiceTests.Exceptions.GetAssembly.cs | 45 +++++++++++++++++++ .../Assemblies/AssemblyServiceTests.cs | 8 ++++ .../Exceptions/AssemblyServiceException.cs | 15 +++++++ .../FailedAssemblyServiceException.cs | 16 +++++++ 4 files changed, 84 insertions(+) create mode 100644 STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/AssemblyServiceException.cs create mode 100644 STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/FailedAssemblyServiceException.cs diff --git a/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Exceptions.GetAssembly.cs b/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Exceptions.GetAssembly.cs index 3f27c1c..c787565 100644 --- a/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Exceptions.GetAssembly.cs +++ b/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Exceptions.GetAssembly.cs @@ -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(actualAssemblyPath => + actualAssemblyPath == someAssemblyPath))) + .Throws(externalException); + + // when + Func getAssemblyFunction = () => + this.assemblyService.GetAssembly(someAssemblyPath); + + AssemblyServiceException actualAssemblyServiceException = + Assert.Throws( + getAssemblyFunction); + + //then + actualAssemblyServiceException.Should().BeEquivalentTo( + expectedAssemblyServiceException); + + this.assemblyBroker + .Verify(broker => + broker.GetAssembly(It.IsAny()), + Times.Once); + + this.assemblyBroker.VerifyNoOtherCalls(); + } } } diff --git a/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs b/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs index 1c135c1..858aa30 100644 --- a/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs +++ b/STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.cs @@ -85,5 +85,13 @@ public static TheoryData AssemblyLoadValidationDependencyExceptions() new ArgumentException() }; } + + public static TheoryData AssemblyLoadServiceExceptions() + { + return new TheoryData + { + new Exception() + }; + } } } diff --git a/STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/AssemblyServiceException.cs b/STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/AssemblyServiceException.cs new file mode 100644 index 0000000..df0d174 --- /dev/null +++ b/STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/AssemblyServiceException.cs @@ -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) + { } + } +} diff --git a/STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/FailedAssemblyServiceException.cs b/STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/FailedAssemblyServiceException.cs new file mode 100644 index 0000000..557b9dc --- /dev/null +++ b/STX.SPAL.Core/Models/Services/Foundations/Assemblies/Exceptions/FailedAssemblyServiceException.cs @@ -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) + { } + } +}