-
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 #30 from The-Standard-Organization/users/lboullosa…
…/foundations-dependency-injection-service FOUNDATIONS: IServiceProvider part in InjectionDependencyService
- Loading branch information
Showing
23 changed files
with
993 additions
and
68 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
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
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
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
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
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
70 changes: 70 additions & 0 deletions
70
...ions/DependenciesInjections/DependencyInjectionServiceTests.Logic.BuildServiceProvider.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,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(); | ||
} | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
...es/Foundations/DependenciesInjections/DependencyInjectionServiceTests.Logic.GetService.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,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(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.