Skip to content

Commit

Permalink
ShouldGetService -> PASS
Browse files Browse the repository at this point in the history
  • Loading branch information
LBoullosa committed Oct 5, 2024
1 parent c8483cf commit 873ff69
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,25 @@ 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 =
Activator.CreateInstance(implementationType) as ISPALBase;

ISPALBase expectedService = returnedService;

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

DependencyInjection expectedDependencyInjection = inputDependencyInjection;
DependencyInjection returnedDependencyInjection = expectedDependencyInjection;

this.dependencyInjectionBroker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public DependencyInjection BuildServiceProvider(DependencyInjection dependencyIn
};
});

public T GetService<T>(DependencyInjection dependencyInjection) =>
throw new NotImplementedException();
public T GetService<T>(DependencyInjection dependencyInjection)
{
return dependencyInjectionBroker.GetService<T>(
dependencyInjection.ServiceProvider);
}
}
}

0 comments on commit 873ff69

Please sign in to comment.