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: IServiceProvider part in InjectionDependencyService #30

Merged
merged 19 commits into from
Oct 9, 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
ab180d1
DOCUMENTATION: Update reference for diagram image
LBoullosa Oct 5, 2024
b0e8a48
ShouldBuildServiceProvider -> FAIL
LBoullosa Oct 5, 2024
88ff39a
ShouldBuildServiceProvider -> PASS
LBoullosa Oct 5, 2024
736847c
ShouldThrowValidationExceptionIfInvalidParametersOnBuildServiceProvid…
LBoullosa Oct 5, 2024
efd3887
ShouldThrowValidationExceptionIfInvalidParametersOnBuildServiceProvid…
LBoullosa Oct 5, 2024
ac175ae
ShouldThrowValidationExceptionIfInvalidParameters -> FAIL
LBoullosa Oct 5, 2024
7cfad81
ShouldThrowValidationExceptionIfInvalidParametersWhenUsingSpalId -> FAIL
LBoullosa Oct 5, 2024
52063d9
ShouldThrowValidationExceptionIfInvalidParametersWhenUsingSpalId -> PASS
LBoullosa Oct 5, 2024
e58ee38
CODERUB: Rename GetService method
LBoullosa Oct 5, 2024
c8483cf
ShouldGetService -> FAIL
LBoullosa Oct 5, 2024
873ff69
ShouldGetService -> PASS
LBoullosa Oct 5, 2024
0a59f58
ShouldGetServiceWithSpalId -> FAIL
LBoullosa Oct 5, 2024
99c3462
ShouldGetServiceWithSpalId -> PASS
LBoullosa Oct 5, 2024
2594399
CODERUB: Remove extra lines
LBoullosa Oct 6, 2024
241e2f1
ShouldThrowValidationExceptionIfInvalidParametersOnGetService -> FAIL
LBoullosa Oct 6, 2024
c7a22a2
ShouldThrowValidationExceptionIfInvalidParametersOnGetService
LBoullosa Oct 6, 2024
ee3ef77
ShouldThrowValidationExceptionIfInvalidParametersOnGetServiceWithSpal…
LBoullosa Oct 6, 2024
c318168
ShouldThrowValidationExceptionIfInvalidParametersOnGetServiceWithSpal…
LBoullosa Oct 6, 2024
35c34a3
CODERUB: Fix formating, missing spaces and related
LBoullosa Oct 6, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SPAL.Core should provide the following features:

![Current Engineering Overview](https://github.com/The-Standard-Organization/STX.SPAL.Core/blob/main/STX.SPAL.Core/Resources/Diagrams/spal-diagram-ovtab-05302024.png)

![Current Engineering Status](https://github.com/The-Standard-Organization/STX.SPAL.Core/blob/main/STX.SPAL.Core/Resources/Diagrams/spal-diagram-coretab-06072024.png)
![Current Engineering Status](https://github.com/The-Standard-Organization/STX.SPAL.Core/blob/main/STX.SPAL.Core/Resources/Diagrams/spal-diagram-coretab-05102024.png)

## Standard-Compliance
This library was built according to The Standard. The library follows engineering principles, patterns and tooling as recommended by The Standard.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void ShouldThrowDependencyExceptionOnLoadAssemblyIfExternalExceptionOccu
Assert.Throws<AssemblyDependencyException>(
getAssemblyFunction);

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

Expand Down Expand Up @@ -90,7 +90,7 @@ private void ShouldThrowValidationDependencyExceptionOnLoadAssemblyIfExternalExc
Assert.Throws<AssemblyValidationDependencyException>(
getAssemblyFunction);

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

Expand Down Expand Up @@ -135,7 +135,7 @@ private void ShouldThrowServiceExceptionOnLoadAssemblyIfExceptionOccurs(
Assert.Throws<AssemblyServiceException>(
getAssemblyFunction);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

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

Expand Down Expand Up @@ -31,7 +30,7 @@ private void ShouldGetApplicationPathAssemblies()
string[] actualApplicationPathsAssemblies =
this.assemblyService.GetApplicationPathsAssemblies();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void ShouldGetAssembly()
Assembly actualAssembly =
this.assemblyService.GetAssembly(inputPathAssembly);

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

this.assemblyBroker.Verify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void ShouldThrowValidationExceptionIfInvalidAssemblyPath(
Assert.Throws<AssemblyValidationException>(
getAssemblyFunction);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void ShouldThrowValidationDependencyExceptionOnRegisterServiceDescriptor

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

this.dependencyInjectionBroker
Expand All @@ -57,7 +57,7 @@ private void ShouldThrowValidationDependencyExceptionOnRegisterServiceDescriptor
Assert.Throws<DependencyInjectionValidationDependencyException>(
registerServiceDescriptorFunction);

//then
// then
actualServiceCollectionValidationDependencyException.Should().BeEquivalentTo(
expectedServiceCollectionValidationDependencyException);

Expand Down Expand Up @@ -88,7 +88,7 @@ private void ShouldThrowServiceExceptionOnRegisterServiceDescriptorIfExceptionOc

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

this.dependencyInjectionBroker
Expand All @@ -115,7 +115,7 @@ private void ShouldThrowServiceExceptionOnRegisterServiceDescriptorIfExceptionOc
Assert.Throws<DependencyInjectionServiceException>(
registerServiceDescriptorFunction);

//then
// then
actualServiceCollectionServiceException.Should().BeEquivalentTo(
expectedServiceCollectionServiceException);

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

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

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.DependenciesInjections
{
public partial class DependencyInjectionServiceTests
{
[Fact]
private void ShouldBuildServiceProvider()
{
// given
dynamic randomProperties = CreateRandomProperties();
dynamic inputProperties = randomProperties;

ServiceDescriptor randomServiceDescriptor = randomProperties.ServiceDescriptor;
ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor;
ServiceDescriptor expectedServiceDescriptor = inputServiceDescriptor;

DependencyInjection inputDependencyInjection = inputProperties.DependencyInjection;
inputDependencyInjection.ServiceCollection.Add(inputServiceDescriptor);

DependencyInjection expectedDependencyInjection =
new DependencyInjection
{
ServiceCollection = inputDependencyInjection.ServiceCollection,
ServiceProvider = inputDependencyInjection.ServiceCollection.BuildServiceProvider()
};

DependencyInjection returnedDependencyInjection = expectedDependencyInjection;

this.dependencyInjectionBroker
.Setup(broker =>
broker.BuildServiceProvider(
It.Is<IServiceCollection>(actualServiceCollection =>
SameServiceCollectionAs(
actualServiceCollection,
expectedDependencyInjection.ServiceCollection)
.Compile()
.Invoke(inputDependencyInjection.ServiceCollection))))
.Returns(returnedDependencyInjection.ServiceProvider);

// when
DependencyInjection actualDependencyInjection =
this.dependencyInjectionService.BuildServiceProvider(
inputProperties.DependencyInjection);

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

this.dependencyInjectionBroker.Verify(
broker =>
broker.BuildServiceProvider(
It.Is<IServiceCollection>(actualServiceCollection =>
SameServiceCollectionAs(
actualServiceCollection,
expectedDependencyInjection.ServiceCollection)
.Compile()
.Invoke(actualDependencyInjection.ServiceCollection))),
Times.Once);

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

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

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.DependenciesInjections
{
public partial class DependencyInjectionServiceTests
{
[Fact]
private void ShouldGetService()
{
// given
dynamic randomProperties = CreateRandomProperties();
dynamic inputProperties = randomProperties;

ServiceDescriptor randomServiceDescriptor = randomProperties.ServiceDescriptor;
ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor;
ServiceDescriptor expectedServiceDescriptor = inputServiceDescriptor;

IServiceCollection inputServiceCollection = inputProperties.DependencyInjection.ServiceCollection;
inputServiceCollection.Add(inputServiceDescriptor);

DependencyInjection inputDependencyInjection =
new DependencyInjection
{
ServiceCollection = inputServiceCollection,
ServiceProvider = inputServiceCollection.BuildServiceProvider()
};

Type implementationType = randomProperties.ImplementationType;

ISPALBase returnedService =
Activator.CreateInstance(implementationType) as ISPALBase;

ISPALBase expectedService = returnedService;

DependencyInjection expectedDependencyInjection = inputDependencyInjection.DeepClone();
DependencyInjection returnedDependencyInjection = expectedDependencyInjection;

this.dependencyInjectionBroker
.Setup(broker =>
broker.GetService<ISPALBase>(
It.Is<IServiceProvider>(actualServiceProvider =>
SameServiceProviderAs(
actualServiceProvider,
expectedDependencyInjection.ServiceProvider)
.Compile()
.Invoke(inputDependencyInjection.ServiceProvider))))
.Returns(returnedService);

// when
ISPALBase actualService =
this.dependencyInjectionService.GetService<ISPALBase>(
inputDependencyInjection);

//then
actualService.Should().BeEquivalentTo(expectedService);

this.dependencyInjectionBroker.Verify(
broker =>
broker.GetService<ISPALBase>(
It.Is<IServiceProvider>(actualServiceProvider =>
SameServiceProviderAs(
actualServiceProvider,
expectedDependencyInjection.ServiceProvider)
.Compile()
.Invoke(inputDependencyInjection.ServiceProvider))),
Times.Once);

this.dependencyInjectionBroker.VerifyNoOtherCalls();
}

[Fact]
private void ShouldGetServiceWithSpalId()
{
// given
dynamic randomProperties = CreateRandomProperties();
dynamic inputProperties = randomProperties;

ServiceDescriptor randomServiceDescriptor = randomProperties.ServiceDescriptorWithSpalId;
ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor;
ServiceDescriptor expectedServiceDescriptor = inputServiceDescriptor;


IServiceCollection inputServiceCollection = inputProperties.DependencyInjection.ServiceCollection;
inputServiceCollection.Add(inputServiceDescriptor);

DependencyInjection inputDependencyInjection =
new DependencyInjection
{
ServiceCollection = inputServiceCollection,
ServiceProvider = inputServiceCollection.BuildServiceProvider()
};

Type implementationType = randomProperties.ImplementationType;

ISPALBase returnedService =
Activator.CreateInstance(implementationType) as ISPALBase;

ISPALBase expectedService = returnedService;

DependencyInjection expectedDependencyInjection = inputDependencyInjection.DeepClone();
DependencyInjection returnedDependencyInjection = expectedDependencyInjection;

this.dependencyInjectionBroker
.Setup(broker =>
broker.GetService<ISPALBase>(
It.Is<IServiceProvider>(actualServiceProvider =>
SameServiceProviderAs(
actualServiceProvider,
expectedDependencyInjection.ServiceProvider)
.Compile()
.Invoke(inputDependencyInjection.ServiceProvider)),
It.IsAny<string>()))
.Returns(returnedService);

// when
ISPALBase actualService =
this.dependencyInjectionService.GetService<ISPALBase>(
inputDependencyInjection,
inputProperties.SpalId);

// then
actualService.Should().BeEquivalentTo(expectedService);

this.dependencyInjectionBroker.Verify(
broker =>
broker.GetService<ISPALBase>(
It.Is<IServiceProvider>(actualServiceProvider =>
SameServiceProviderAs(
actualServiceProvider,
expectedDependencyInjection.ServiceProvider)
.Compile()
.Invoke(inputDependencyInjection.ServiceProvider)),
It.IsAny<string>()),
Times.Once);

this.dependencyInjectionBroker.VerifyNoOtherCalls();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void ShouldRegisterServiceDescriptor()
inputProperties.ImplementationType,
inputProperties.ServiceLifeTime);

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

this.dependencyInjectionBroker.Verify(
Expand Down Expand Up @@ -107,7 +107,7 @@ private void ShouldRegisterServiceDescriptorWithSpalId()
inputProperties.ImplementationType,
inputProperties.ServiceLifeTime);

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

this.dependencyInjectionBroker.Verify(
Expand Down
Loading
Loading