From 873ff69d6c1b9258031efe221c2858015bcec035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20LB?= Date: Sun, 6 Oct 2024 00:17:38 +0200 Subject: [PATCH] ShouldGetService -> PASS --- ...yInjectionServiceTests.Logic.GetService.cs | 21 +++++++++------- .../DependencyInjectionServiceTests.cs | 24 ++++++++++++------- .../DependencyInjectionService.cs | 7 ++++-- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.Logic.GetService.cs b/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.Logic.GetService.cs index d274802..12d2307 100644 --- a/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.Logic.GetService.cs +++ b/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.Logic.GetService.cs @@ -24,8 +24,17 @@ private void ShouldGetService() ServiceDescriptor inputServiceDescriptor = randomServiceDescriptor; ServiceDescriptor expectedServiceDescriptor = inputServiceDescriptor; - DependencyInjection inputDependencyInjection = inputProperties.DependencyInjection; - inputDependencyInjection.ServiceCollection.Add(inputServiceDescriptor); + + IServiceCollection inputServiceCollection = inputProperties.DependencyInjection.ServiceCollection; + inputServiceCollection.Add(inputServiceDescriptor); + + DependencyInjection inputDependencyInjection = + new DependencyInjection + { + ServiceCollection = inputServiceCollection, + ServiceProvider = inputServiceCollection.BuildServiceProvider() + }; + Type implementationType = randomProperties.ImplementationType; ISPALBase returnedService = @@ -33,13 +42,7 @@ private void ShouldGetService() ISPALBase expectedService = returnedService; - DependencyInjection expectedDependencyInjection = - new DependencyInjection - { - ServiceCollection = inputDependencyInjection.ServiceCollection, - ServiceProvider = inputDependencyInjection.ServiceCollection.BuildServiceProvider() - }; - + DependencyInjection expectedDependencyInjection = inputDependencyInjection; DependencyInjection returnedDependencyInjection = expectedDependencyInjection; this.dependencyInjectionBroker diff --git a/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.cs b/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.cs index 201689b..f8aaa84 100644 --- a/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.cs +++ b/STX.SPAL.Core.Tests.Unit/Services/Foundations/DependenciesInjections/DependencyInjectionServiceTests.cs @@ -86,12 +86,11 @@ private static Type CreateRandomImplementationType() TypeBuilder typeBuilder = moduleBuilder.DefineType( name: GetRandomString(), - attr: TypeAttributes.Public | TypeAttributes.Class, - parent: null, - interfaces: new Type[] - { - iSpalBaseType - }); + attr: + TypeAttributes.Public + | TypeAttributes.Class); + + typeBuilder.AddInterfaceImplementation(iSpalBaseType); MethodInfo methodInfoGetSPALId = iSpalBaseType @@ -101,15 +100,22 @@ private static Type CreateRandomImplementationType() typeBuilder .DefineMethod( name: nameof(ISPALBase.GetSPALId), - attributes: MethodAttributes.Public | MethodAttributes.Virtual, - callingConvention: CallingConventions.HasThis, + attributes: + MethodAttributes.Public + | MethodAttributes.Final + | MethodAttributes.HideBySig + | MethodAttributes.NewSlot + | MethodAttributes.Virtual, + returnType: typeof(string), parameterTypes: Type.EmptyTypes); ILGenerator ilGenerator = getSPALIDMethodBuilder.GetILGenerator(); - ilGenerator.Emit(OpCodes.Ret, "Hello SPAL ID"); + ilGenerator.Emit(OpCodes.Ldstr, "Hello SPAL ID"); + ilGenerator.Emit(OpCodes.Ret); + typeBuilder.DefineMethodOverride( getSPALIDMethodBuilder, iSpalBaseType.GetMethod(nameof(ISPALBase.GetSPALId))); diff --git a/STX.SPAL.Core/Services/Foundations/DepedenciesInjections/DependencyInjectionService.cs b/STX.SPAL.Core/Services/Foundations/DepedenciesInjections/DependencyInjectionService.cs index 2b0096c..6d79969 100644 --- a/STX.SPAL.Core/Services/Foundations/DepedenciesInjections/DependencyInjectionService.cs +++ b/STX.SPAL.Core/Services/Foundations/DepedenciesInjections/DependencyInjectionService.cs @@ -73,7 +73,10 @@ public DependencyInjection BuildServiceProvider(DependencyInjection dependencyIn }; }); - public T GetService(DependencyInjection dependencyInjection) => - throw new NotImplementedException(); + public T GetService(DependencyInjection dependencyInjection) + { + return dependencyInjectionBroker.GetService( + dependencyInjection.ServiceProvider); + } } }