-
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.
ShouldRegisterServiceDescriptor -> FAIL
- Loading branch information
Showing
10 changed files
with
231 additions
and
10 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
54 changes: 54 additions & 0 deletions
54
...ions/ServicesCollections/ServiceCollectionServiceTests.Logic.RegisterServiceDescriptor.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,54 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
|
||
namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.ServicesCollections | ||
{ | ||
public partial class ServiceCollectionServiceTests | ||
{ | ||
[Fact] | ||
private void ShouldRegisterServiceDescriptor() | ||
{ | ||
// given | ||
dynamic randomProperties = CreateRandomProperties(); | ||
dynamic inputProperties = randomProperties; | ||
|
||
ServiceDescriptor randomServiceDescriptor = randomProperties.ServiceDescriptor; | ||
ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor; | ||
|
||
IServiceCollection randomServiceCollection = randomProperties.ServiceCollection; | ||
IServiceCollection expectedServiceCollection = randomServiceCollection; | ||
IServiceCollection returnedServiceCollection = randomServiceCollection; | ||
|
||
this.dependencyInjectionBroker | ||
.Setup(broker => | ||
broker.RegisterServiceDescriptor( | ||
It.Is<ServiceDescriptor>(actualServiceDescriptor => | ||
actualServiceDescriptor == inputServiceDescriptor))) | ||
.Returns(returnedServiceCollection); | ||
|
||
// when | ||
IServiceCollection actualServiceCollection = | ||
this.serviceCollectionService.RegisterServiceDescriptor( | ||
inputProperties.SpalInterfaceType, | ||
inputProperties.ImplementationType, | ||
inputProperties.ServiceLifeTime); | ||
|
||
//then | ||
actualServiceCollection.Should().BeSameAs(expectedServiceCollection); | ||
|
||
this.dependencyInjectionBroker.Verify( | ||
broker => | ||
broker.RegisterServiceDescriptor( | ||
It.Is<ServiceDescriptor>(actualServiceDescriptor => | ||
actualServiceDescriptor == inputServiceDescriptor)), | ||
Times.Once); | ||
|
||
this.dependencyInjectionBroker.VerifyNoOtherCalls(); | ||
} | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
...Core.Tests.Unit/Services/Foundations/ServicesCollections/ServiceCollectionServiceTests.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,121 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using STX.SPAL.Abstractions; | ||
using STX.SPAL.Core.Brokers.DependenciesInjection; | ||
using STX.SPAL.Core.Models.Services.Foundations.ServicesCollections; | ||
using Tynamix.ObjectFiller; | ||
|
||
namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.ServicesCollections | ||
{ | ||
public partial class ServiceCollectionServiceTests | ||
{ | ||
private readonly Mock<IDependencyInjectionBroker> dependencyInjectionBroker; | ||
private readonly IServiceCollectionService serviceCollectionService; | ||
|
||
public ServiceCollectionServiceTests() | ||
{ | ||
this.dependencyInjectionBroker = new Mock<IDependencyInjectionBroker>(); | ||
|
||
this.serviceCollectionService = | ||
new ServiceCollectionService(dependencyInjectionBroker.Object); | ||
} | ||
|
||
private static string GetRandomString() => | ||
new MnemonicString().GetValue(); | ||
|
||
private static AssemblyBuilder CreateRandomAssembly() | ||
{ | ||
string randomAssemblyName = GetRandomString(); | ||
|
||
var assemblyName = | ||
new AssemblyName(randomAssemblyName); | ||
|
||
AssemblyBuilder assemblyBuilder = | ||
AssemblyBuilder.DefineDynamicAssembly( | ||
assemblyName, | ||
AssemblyBuilderAccess.Run); | ||
|
||
return assemblyBuilder; | ||
} | ||
|
||
private static Type CreateRandomSpalInterfaceType() | ||
{ | ||
AssemblyBuilder spalAssembly = CreateRandomAssembly(); | ||
string assemblyName = spalAssembly.GetName().Name; | ||
ModuleBuilder moduleBuilder = spalAssembly.DefineDynamicModule(assemblyName); | ||
|
||
TypeBuilder typeBuilder = moduleBuilder.DefineType( | ||
name: GetRandomString(), | ||
attr: TypeAttributes.Public, | ||
parent: null, | ||
interfaces: new Type[] | ||
{ | ||
typeof(ISPALBase) | ||
}); | ||
|
||
return typeBuilder; | ||
} | ||
|
||
private static Type CreateRandomImplementationType() | ||
{ | ||
AssemblyBuilder spalAssembly = CreateRandomAssembly(); | ||
string assemblyName = spalAssembly.GetName().Name; | ||
ModuleBuilder moduleBuilder = spalAssembly.DefineDynamicModule(assemblyName); | ||
|
||
TypeBuilder typeBuilder = moduleBuilder.DefineType( | ||
name: GetRandomString(), | ||
attr: TypeAttributes.Public, | ||
parent: null, | ||
interfaces: new Type[] | ||
{ | ||
typeof(ISPALBase) | ||
}); | ||
|
||
return typeBuilder; | ||
} | ||
|
||
private static ServiceLifetime CreateRandomServiceLifeTime() | ||
{ | ||
int randomNumber = new IntRange(min: 0, max: 2).GetValue(); | ||
|
||
return randomNumber switch | ||
{ | ||
0 => ServiceLifetime.Singleton, | ||
1 => ServiceLifetime.Scoped, | ||
_ => ServiceLifetime.Transient | ||
}; | ||
} | ||
|
||
private static dynamic CreateRandomProperties() | ||
{ | ||
Type randomSpalInterfaceType = CreateRandomSpalInterfaceType(); | ||
string randomSpalId = GetRandomString(); | ||
Type randomImplementationType = CreateRandomImplementationType(); | ||
ServiceLifetime randomServiceLifeTime = CreateRandomServiceLifeTime(); | ||
|
||
return new | ||
{ | ||
SpalInterfaceType = randomSpalInterfaceType, | ||
SpalId = randomSpalId, | ||
ImplementationType = randomImplementationType, | ||
ServiceLifeTime = randomServiceLifeTime, | ||
|
||
ServiceDescriptor = | ||
new ServiceDescriptor( | ||
randomSpalInterfaceType, | ||
randomSpalId, | ||
randomImplementationType, | ||
randomServiceLifeTime), | ||
|
||
ServiceCollection = new ServiceCollection() | ||
}; | ||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
STX.SPAL.Core/Models/Services/Foundations/ServicesCollections/IServiceCollectionService.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,17 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace STX.SPAL.Core.Models.Services.Foundations.ServicesCollections | ||
{ | ||
internal partial interface IServiceCollectionService | ||
{ | ||
IServiceCollection RegisterServiceDescriptor( | ||
Type spalInterfaceType, | ||
Type implementationType, | ||
ServiceLifetime serviceLifetime); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
STX.SPAL.Core/Models/Services/Foundations/ServicesCollections/ServiceCollectionService.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,28 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using STX.SPAL.Core.Brokers.DependenciesInjection; | ||
|
||
namespace STX.SPAL.Core.Models.Services.Foundations.ServicesCollections | ||
{ | ||
internal partial class ServiceCollectionService : IServiceCollectionService | ||
{ | ||
private readonly IDependencyInjectionBroker dependencyInjectionBroker; | ||
|
||
public ServiceCollectionService(IDependencyInjectionBroker dependencyInjectionBroker) | ||
{ | ||
this.dependencyInjectionBroker = dependencyInjectionBroker; | ||
} | ||
|
||
public IServiceCollection RegisterServiceDescriptor( | ||
Type spalInterfaceType, | ||
Type implementationType, | ||
ServiceLifetime serviceLifetime) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |