Skip to content

Commit

Permalink
Merge pull request #29 from The-Standard-Organization/users/lboullosa…
Browse files Browse the repository at this point in the history
…/coderub-renaming-to-dependency-injection-service

CODERUB: Renaming ServicesCollections to DependenciesInjections
  • Loading branch information
glhays authored Oct 5, 2024
2 parents 349625e + e7b569c commit df9a318
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using STX.SPAL.Core.Models.Services.Foundations.ServicesCollections.Exceptions;
using STX.SPAL.Core.Models.Services.Foundations.DependenciesInjections;
using STX.SPAL.Core.Models.Services.Foundations.DependenciesInjections.Exceptions;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.ServicesCollections
namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.DependenciesInjections
{
public partial class ServiceCollectionServiceTests
public partial class DependencyInjectionServiceTests
{
[Theory]
[MemberData(nameof(RegisterServiceDescriptorValidationDependencyExceptions))]
Expand All @@ -19,6 +20,7 @@ private void ShouldThrowValidationDependencyExceptionOnRegisterServiceDescriptor
{
// given
dynamic randomProperties = CreateRandomProperties();
DependencyInjection someDependencyInjection = randomProperties.DependencyInjection;
ServiceDescriptor someServiceDescriptor = randomProperties.ServiceDescriptor;

var addServiceDescriptorException =
Expand All @@ -27,13 +29,14 @@ private void ShouldThrowValidationDependencyExceptionOnRegisterServiceDescriptor
innerException: externalException);

var expectedServiceCollectionValidationDependencyException =
new ServiceCollectionValidationDependencyException(
new DependencyInjectionValidationDependencyException(
message: "Service collection validation dependency error occurred, contact support.",
innerException: addServiceDescriptorException);

this.dependencyInjectionBroker
.Setup(broker =>
broker.AddServiceDescriptor(
someDependencyInjection.ServiceCollection,
It.Is<ServiceDescriptor>(actualServiceDescriptor =>
SameServiceDescriptorAs(
actualServiceDescriptor,
Expand All @@ -43,14 +46,15 @@ private void ShouldThrowValidationDependencyExceptionOnRegisterServiceDescriptor
.Throws(externalException);

// when
Func<IServiceCollection> registerServiceDescriptorFunction = () =>
this.serviceCollectionService.RegisterServiceDescriptor(
Func<DependencyInjection> registerServiceDescriptorFunction = () =>
this.dependencyInjectionService.RegisterServiceDescriptor(
randomProperties.DependencyInjection,
randomProperties.SpalInterfaceType,
randomProperties.ImplementationType,
randomProperties.ServiceLifeTime);

ServiceCollectionValidationDependencyException actualServiceCollectionValidationDependencyException =
Assert.Throws<ServiceCollectionValidationDependencyException>(
DependencyInjectionValidationDependencyException actualServiceCollectionValidationDependencyException =
Assert.Throws<DependencyInjectionValidationDependencyException>(
registerServiceDescriptorFunction);

//then
Expand All @@ -59,7 +63,9 @@ private void ShouldThrowValidationDependencyExceptionOnRegisterServiceDescriptor

this.dependencyInjectionBroker
.Verify(broker =>
broker.AddServiceDescriptor(It.IsAny<ServiceDescriptor>()),
broker.AddServiceDescriptor(
someDependencyInjection.ServiceCollection,
It.IsAny<ServiceDescriptor>()),
Times.Once);

this.dependencyInjectionBroker.VerifyNoOtherCalls();
Expand All @@ -72,21 +78,23 @@ private void ShouldThrowServiceExceptionOnRegisterServiceDescriptorIfExceptionOc
{
// given
dynamic randomProperties = CreateRandomProperties();
DependencyInjection someDependencyInjection = randomProperties.DependencyInjection;
ServiceDescriptor someServiceDescriptor = randomProperties.ServiceDescriptor;

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

var expectedServiceCollectionServiceException =
new ServiceCollectionServiceException(
new DependencyInjectionServiceException(
message: "ServiceCollection service error occurred, contact support.",
innerException: assemblyLoadException);

this.dependencyInjectionBroker
.Setup(broker =>
broker.AddServiceDescriptor(
someDependencyInjection.ServiceCollection,
It.Is<ServiceDescriptor>(actualServiceDescriptor =>
SameServiceDescriptorAs(
actualServiceDescriptor,
Expand All @@ -97,13 +105,14 @@ private void ShouldThrowServiceExceptionOnRegisterServiceDescriptorIfExceptionOc

// when
Func<IServiceCollection> registerServiceDescriptorFunction = () =>
this.serviceCollectionService.RegisterServiceDescriptor(
this.dependencyInjectionService.RegisterServiceDescriptor(
someDependencyInjection,
randomProperties.SpalInterfaceType,
randomProperties.ImplementationType,
randomProperties.ServiceLifeTime);

ServiceCollectionServiceException actualServiceCollectionServiceException =
Assert.Throws<ServiceCollectionServiceException>(
DependencyInjectionServiceException actualServiceCollectionServiceException =
Assert.Throws<DependencyInjectionServiceException>(
registerServiceDescriptorFunction);

//then
Expand All @@ -112,7 +121,9 @@ private void ShouldThrowServiceExceptionOnRegisterServiceDescriptorIfExceptionOc

this.dependencyInjectionBroker
.Verify(broker =>
broker.AddServiceDescriptor(It.IsAny<ServiceDescriptor>()),
broker.AddServiceDescriptor(
someDependencyInjection.ServiceCollection,
It.IsAny<ServiceDescriptor>()),
Times.Once);

this.dependencyInjectionBroker.VerifyNoOtherCalls();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// ----------------------------------------------------------------------------------

using FluentAssertions;
using Force.DeepCloner;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using STX.SPAL.Core.Models.Services.Foundations.DependenciesInjections;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.ServicesCollections
namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.DependenciesInjections
{
public partial class ServiceCollectionServiceTests
public partial class DependencyInjectionServiceTests
{
[Fact]
private void ShouldRegisterServiceDescriptor()
Expand All @@ -21,36 +23,40 @@ private void ShouldRegisterServiceDescriptor()
ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor;
ServiceDescriptor expectedServiceDescriptor = inputServiceDescriptor;

IServiceCollection randomServiceCollection = randomProperties.ServiceCollection;
IServiceCollection expectedServiceCollection = randomServiceCollection;
IServiceCollection returnedServiceCollection = randomServiceCollection;
DependencyInjection inputDependencyInjection = inputProperties.DependencyInjection;
DependencyInjection expectedDependencyInjection = inputDependencyInjection.DeepClone();
DependencyInjection returnedDependencyInjection = inputDependencyInjection.DeepClone();
IServiceCollection inputServiceCollection = inputDependencyInjection.ServiceCollection;

expectedServiceCollection.Add(inputServiceDescriptor);
expectedDependencyInjection.ServiceCollection.Add(inputServiceDescriptor);

this.dependencyInjectionBroker
.Setup(broker =>
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.Is<ServiceDescriptor>(actualServiceDescriptor =>
SameServiceDescriptorAs(
actualServiceDescriptor,
expectedServiceDescriptor)
.Compile()
.Invoke(actualServiceDescriptor))))
.Returns(returnedServiceCollection);
.Returns(returnedDependencyInjection.ServiceCollection);

// when
IServiceCollection actualServiceCollection =
this.serviceCollectionService.RegisterServiceDescriptor(
DependencyInjection actualDependencyInjection =
this.dependencyInjectionService.RegisterServiceDescriptor(
inputProperties.DependencyInjection,
inputProperties.SpalInterfaceType,
inputProperties.ImplementationType,
inputProperties.ServiceLifeTime);

//then
actualServiceCollection.Should().BeEquivalentTo(expectedServiceCollection);
actualDependencyInjection.Should().BeEquivalentTo(expectedDependencyInjection);

this.dependencyInjectionBroker.Verify(
broker =>
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.Is<ServiceDescriptor>(actualServiceDescriptor =>
SameServiceDescriptorAs(
actualServiceDescriptor,
Expand All @@ -73,37 +79,41 @@ private void ShouldRegisterServiceDescriptorWithSpalId()
ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor;
ServiceDescriptor expectedServiceDescriptor = inputServiceDescriptor;

IServiceCollection randomServiceCollection = randomProperties.ServiceCollection;
IServiceCollection expectedServiceCollection = randomServiceCollection;
IServiceCollection returnedServiceCollection = randomServiceCollection;
DependencyInjection inputDependencyInjection = inputProperties.DependencyInjection;
DependencyInjection expectedDependencyInjection = inputDependencyInjection.DeepClone();
DependencyInjection returnedDependencyInjection = inputDependencyInjection.DeepClone();
IServiceCollection inputServiceCollection = inputDependencyInjection.ServiceCollection;

expectedServiceCollection.Add(inputServiceDescriptor);
expectedDependencyInjection.ServiceCollection.Add(inputServiceDescriptor);

this.dependencyInjectionBroker
.Setup(broker =>
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.Is<ServiceDescriptor>(actualServiceDescriptor =>
SameServiceDescriptorAs(
actualServiceDescriptor,
expectedServiceDescriptor)
.Compile()
.Invoke(actualServiceDescriptor))))
.Returns(returnedServiceCollection);
.Returns(returnedDependencyInjection.ServiceCollection);

// when
IServiceCollection actualServiceCollection =
this.serviceCollectionService.RegisterServiceDescriptor(
DependencyInjection actualDependencyInjection =
this.dependencyInjectionService.RegisterServiceDescriptor(
inputProperties.DependencyInjection,
inputProperties.SpalInterfaceType,
inputProperties.SpalId,
inputProperties.ImplementationType,
inputProperties.ServiceLifeTime);

//then
actualServiceCollection.Should().BeEquivalentTo(expectedServiceCollection);
actualDependencyInjection.Should().BeEquivalentTo(expectedDependencyInjection);

this.dependencyInjectionBroker.Verify(
broker =>
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.Is<ServiceDescriptor>(actualServiceDescriptor =>
SameServiceDescriptorAs(
actualServiceDescriptor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using STX.SPAL.Core.Models.Services.Foundations.ServicesCollections.Exceptions;
using STX.SPAL.Core.Models.Services.Foundations.DependenciesInjections;
using STX.SPAL.Core.Models.Services.Foundations.DependenciesInjections.Exceptions;
using Xeptions;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.ServicesCollections
namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.DependenciesInjections
{
public partial class ServiceCollectionServiceTests
public partial class DependencyInjectionServiceTests
{
[Theory]
[MemberData(nameof(RegisterServiceDescriptorValidationExceptions))]
Expand All @@ -20,26 +21,31 @@ private void ShouldThrowValidationExceptionIfInvalidParameters(
Type implementationType,
Xeption exception)
{
dynamic randomProperties = CreateRandomProperties();
DependencyInjection someDependencyInjection = randomProperties.DependencyInjection;

// given
var expectedServiceCollectionValidationException =
new ServiceCollectionValidationException(
new DependencyInjectionValidationException(
message: "Service Collection validation error occurred, fix errors and try again.",
innerException: exception);

this.dependencyInjectionBroker
.Setup(broker =>
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.IsAny<ServiceDescriptor>()));

// when
Func<IServiceCollection> registerServiceDescriptorFunction = () =>
this.serviceCollectionService.RegisterServiceDescriptor(
Func<DependencyInjection> registerServiceDescriptorFunction = () =>
this.dependencyInjectionService.RegisterServiceDescriptor(
someDependencyInjection,
spalInterfaceType,
implementationType,
ServiceLifetime.Singleton);

ServiceCollectionValidationException actualServiceCollectionValidationException =
Assert.Throws<ServiceCollectionValidationException>(
DependencyInjectionValidationException actualServiceCollectionValidationException =
Assert.Throws<DependencyInjectionValidationException>(
registerServiceDescriptorFunction);

//then
Expand All @@ -48,7 +54,9 @@ private void ShouldThrowValidationExceptionIfInvalidParameters(

this.dependencyInjectionBroker
.Verify(broker =>
broker.AddServiceDescriptor(It.IsAny<ServiceDescriptor>()),
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.IsAny<ServiceDescriptor>()),
Times.Never);

this.dependencyInjectionBroker.VerifyNoOtherCalls();
Expand All @@ -62,27 +70,32 @@ private void ShouldThrowValidationExceptionIfInvalidParametersWhenUsingSpalId(
Type implementationType,
Xeption exception)
{
dynamic randomProperties = CreateRandomProperties();
DependencyInjection someDependencyInjection = randomProperties.DependencyInjection;

// given
var expectedServiceCollectionValidationException =
new ServiceCollectionValidationException(
new DependencyInjectionValidationException(
message: "Service Collection validation error occurred, fix errors and try again.",
innerException: exception);

this.dependencyInjectionBroker
.Setup(broker =>
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.IsAny<ServiceDescriptor>()));

// when
Func<IServiceCollection> registerServiceDescriptorFunction = () =>
this.serviceCollectionService.RegisterServiceDescriptor(
Func<DependencyInjection> registerServiceDescriptorFunction = () =>
this.dependencyInjectionService.RegisterServiceDescriptor(
someDependencyInjection,
spalInterfaceType,
spalId,
implementationType,
ServiceLifetime.Singleton);

ServiceCollectionValidationException actualServiceCollectionValidationException =
Assert.Throws<ServiceCollectionValidationException>(
DependencyInjectionValidationException actualServiceCollectionValidationException =
Assert.Throws<DependencyInjectionValidationException>(
registerServiceDescriptorFunction);

//then
Expand All @@ -91,7 +104,9 @@ private void ShouldThrowValidationExceptionIfInvalidParametersWhenUsingSpalId(

this.dependencyInjectionBroker
.Verify(broker =>
broker.AddServiceDescriptor(It.IsAny<ServiceDescriptor>()),
broker.AddServiceDescriptor(
It.IsAny<IServiceCollection>(),
It.IsAny<ServiceDescriptor>()),
Times.Never);

this.dependencyInjectionBroker.VerifyNoOtherCalls();
Expand Down
Loading

0 comments on commit df9a318

Please sign in to comment.