Skip to content

Commit

Permalink
Added latest spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Nov 4, 2020
1 parent 384483c commit 5d4c424
Show file tree
Hide file tree
Showing 29 changed files with 625 additions and 488 deletions.
17 changes: 17 additions & 0 deletions specification/Optimized/Constructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public override IUnityContainer GetContainer()
return new UnityContainer().AddExtension(new ForceCompillation());
}
}

[TestClass]
public class Selection : Unity.Specification.Constructor.Selection.SpecificationTests
{
public override IUnityContainer GetContainer()
{
return new UnityContainer().AddExtension(new ForceCompillation());
}
}
}


Expand Down Expand Up @@ -79,4 +88,12 @@ public override IUnityContainer GetContainer()
}
}

[TestClass]
public class Selection : Unity.Specification.Constructor.Selection.SpecificationTests
{
public override IUnityContainer GetContainer()
{
return new UnityContainer().AddExtension(new ForceActivation());
}
}
}
23 changes: 0 additions & 23 deletions specification/Optimized/Issues.cs

This file was deleted.

15 changes: 15 additions & 0 deletions specification/Optimized/Issues/CodePlex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Unity;
using Unity.Specification.Issues.Codeplex;

namespace Issues
{
[TestClass]
public class CodePlex : SpecificationTests
{
public override IUnityContainer GetContainer()
{
return new UnityContainer();
}
}
}
15 changes: 15 additions & 0 deletions specification/Optimized/Issues/GitHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Unity;
using Unity.Specification.Issues.GitHub;

namespace Issues
{
[TestClass]
public class GitHub : SpecificationTests
{
public override IUnityContainer GetContainer()
{
return new UnityContainer();
}
}
}
1 change: 0 additions & 1 deletion specification/Optimized/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public override IUnityContainer GetContainer()
}



namespace Resolved.Method
{
[TestClass]
Expand Down
1 change: 0 additions & 1 deletion specification/Optimized/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public override IUnityContainer GetContainer()
}



namespace Resolved.Parameter
{
[TestClass]
Expand Down
9 changes: 0 additions & 9 deletions specification/Optimized/Registration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ public override IUnityContainer GetContainer()
}
}

[TestClass]
public class Instance : Unity.Specification.Registration.Instance.SpecificationTests
{
public override IUnityContainer GetContainer()
{
return new UnityContainer();
}
}

[TestClass]
public class Types : Unity.Specification.Registration.Types.SpecificationTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework Condition=" '$(TargetFramework)' == '' ">net5.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\src\package.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\SpecificationTests\optimized\Unity.Specification.csproj" />
<ProjectReference Include="..\..\..\SpecificationTests\Container\optimized\Unity.Specification.Container.csproj" />
<ProjectReference Include="..\..\src\Unity.Container.csproj" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/BuiltIn/Processors/Constructor/Constructor.Activation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void Build(ref PipelineContext context, object?[] data)

object?[] arguments = (0 == parameters.Length)
? EmptyParametersArray
: Build(ref context, parameters, data);
: BuildParameters(ref context, parameters, data);

if (context.IsFaulted) return;

Expand All @@ -124,7 +124,7 @@ private void Build(ref PipelineContext context)

object?[] arguments = (0 == parameters.Length)
? EmptyParametersArray
: base.Build(ref context, parameters);
: base.BuildParameters(ref context, parameters);

if (context.IsFaulted) return;

Expand Down
14 changes: 8 additions & 6 deletions src/BuiltIn/Processors/Constructor/Constructor.Resolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private ResolveDelegate<PipelineContext> CreatePipeline(ConstructorInfo info, ob
var imports = new ReflectionInfo<ParameterInfo>[parameters.Length];

for (var i = 0; i < parameters.Length; i++)
imports[i] = parameters[i].AsInjectionInfo(data![i]);
imports[i] = InjectionInfoFromData(parameters[i], data![i]);

return (ref PipelineContext context) =>
{
Expand All @@ -138,8 +138,8 @@ private ResolveDelegate<PipelineContext> CreatePipeline(ConstructorInfo info, ob

// Check for override
arguments[i] = (null != (@override = context.GetOverride(in parameter.Import)))
? Build(ref context, in parameter.Import, parameter.Import.Element.AsImportData(@override.Value))
: Build(ref context, in parameter.Import, in parameter.Data);
? BuildImport(ref context, in parameter.Import, parameter.Import.Element.AsImportData(@override.Value))
: BuildImport(ref context, in parameter.Import, in parameter.Data);
}

if (!context.IsFaulted)
Expand Down Expand Up @@ -167,7 +167,9 @@ private ResolveDelegate<PipelineContext> CreatePipeline(ConstructorInfo info, Re
var imports = new ReflectionInfo<ParameterInfo>[parameters.Length];

for (var i = 0; i < parameters.Length; i++)
imports[i] = parameters[i].AsInjectionInfo();
{
imports[i] = InjectionInfoFromParameter(parameters[i]);
}

return (ref PipelineContext context) =>
{
Expand All @@ -182,8 +184,8 @@ private ResolveDelegate<PipelineContext> CreatePipeline(ConstructorInfo info, Re

// Check for override
arguments[i] = (null != (@override = context.GetOverride(in parameter.Import)))
? Build(ref context, in parameter.Import, parameter.Import.Element.AsImportData(@override.Value))
: Build(ref context, in parameter.Import, in parameter.Data);
? BuildImport(ref context, in parameter.Import, parameter.Import.Element.AsImportData(@override.Value))
: BuildImport(ref context, in parameter.Import, in parameter.Data);
}

if (!context.IsFaulted)
Expand Down
9 changes: 5 additions & 4 deletions src/BuiltIn/Processors/Methods/Method.Activation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public override void PreBuild(ref PipelineContext context)

///////////////////////////////////////////////////////////////////
// Initialize injected members
for (var injected = GetInjected<InjectionMethod>(context.Registration); null != injected;
for (var injected = GetInjected<InjectionMethod>(context.Registration);
null != injected && !context.IsFaulted;
injected = (InjectionMethod?)injected.Next)
{
int position;
Expand All @@ -50,7 +51,7 @@ public override void PreBuild(ref PipelineContext context)

///////////////////////////////////////////////////////////////////
// Initialize annotated members
for (var index = 0; index < members.Length; index++)
for (var index = 0; index < members.Length && !context.IsFaulted; index++)
{
if (set[index]) continue;

Expand All @@ -73,7 +74,7 @@ private void Build(ref PipelineContext context, MethodInfo info, object?[]? data

object?[] arguments = (0 == parameters.Length)
? EmptyParametersArray
: Build(ref context, parameters, data!);
: BuildParameters(ref context, parameters, data!);

if (context.IsFaulted) return;

Expand All @@ -86,7 +87,7 @@ private void Build(ref PipelineContext context, MethodInfo info)

object?[] arguments = (0 == parameters.Length)
? EmptyParametersArray
: Build(ref context, parameters);
: BuildParameters(ref context, parameters);

if (context.IsFaulted) return;

Expand Down
8 changes: 4 additions & 4 deletions src/BuiltIn/Processors/Methods/Method.Resolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class MethodProcessor
else set[index] = true;

var info = members[index];
(invocations ??= new InvokeInfo[members.Length])[count++] = info.AsInvokeInfo(injected.Data);
(invocations ??= new InvokeInfo[members.Length])[count++] = ToInvokeInfo(info, injected.Data);
}

// Add annotated methods
Expand All @@ -52,7 +52,7 @@ public partial class MethodProcessor
else set[index] = true;

var info = members[index];
(invocations ??= new InvokeInfo[members.Length - index])[count++] = info.AsInvokeInfo();
(invocations ??= new InvokeInfo[members.Length - index])[count++] = ToInvokeInfo(info);
}

// Validate and trim array
Expand All @@ -78,8 +78,8 @@ public partial class MethodProcessor

// Check for override
arguments[i] = (null != (@override = context.GetOverride(in parameter.Import)))
? Build(ref context, in parameter.Import, parameter.Import.Element.AsImportData(@override.Value))
: Build(ref context, in parameter.Import, in parameter.Data);
? BuildImport(ref context, in parameter.Import, parameter.Import.Element.AsImportData(@override.Value))
: BuildImport(ref context, in parameter.Import, in parameter.Data);
}
}
else
Expand Down
30 changes: 16 additions & 14 deletions src/BuiltIn/Processors/Parameter/Parameter.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Unity.BuiltIn
{
public abstract partial class ParameterProcessor<TMemberInfo>
{
protected object?[] Build(ref PipelineContext context, ParameterInfo[] parameters, object?[] data)
protected object?[] BuildParameters(ref PipelineContext context, ParameterInfo[] parameters, object?[] data)
{
Debug.Assert(parameters.Length == data.Length);

Expand All @@ -19,55 +19,57 @@ public abstract partial class ParameterProcessor<TMemberInfo>
for (var index = 0; index < arguments.Length && !context.IsFaulted; index++)
{
var parameter = parameters[index];
var info = parameter.AsInjectionInfo(data[index]);
if (!IsValid(parameter, ref context)) return arguments;
var info = InjectionInfoFromData(parameter, data[index]);

// Check for override
if (null != (@override = context.GetOverride(in info.Import)))
{
if (@override.Value is IReflectionProvider<ParameterInfo> provider)
{
var providerInfo = provider.GetInfo(parameter);
arguments[index] = Build(ref context, in providerInfo.Import, in providerInfo.Data);
arguments[index] = BuildImport(ref context, in providerInfo.Import, in providerInfo.Data);
}
else
arguments[index] = Build(ref context, in info.Import, parameter.AsImportData(@override.Value));
arguments[index] = BuildImport(ref context, in info.Import, parameter.AsImportData(@override.Value));
}
else
arguments[index] = Build(ref context, in info.Import, in info.Data);
arguments[index] = BuildImport(ref context, in info.Import, in info.Data);
}

return arguments;
}

protected object?[] Build(ref PipelineContext context, ParameterInfo[] parameters)
protected object?[] BuildParameters(ref PipelineContext context, ParameterInfo[] parameters)
{
ResolverOverride? @override;
object?[] arguments = new object?[parameters.Length];

for (var index = 0; index < arguments.Length && !context.IsFaulted; index++)
{
var parameter = parameters[index];
var info = parameter.AsInjectionInfo();
if (!IsValid(parameter, ref context)) return arguments;
var info = InjectionInfoFromParameter(parameter);

// Check for override
if (null != (@override = context.GetOverride(in info.Import)))
{
if (@override.Value is IReflectionProvider<ParameterInfo> provider)
{
var providerInfo = provider.GetInfo(parameter);
arguments[index] = Build(ref context, in providerInfo.Import, in providerInfo.Data);
arguments[index] = BuildImport(ref context, in providerInfo.Import, in providerInfo.Data);
}
else
arguments[index] = Build(ref context, in info.Import, info.Import.Element.AsImportData(@override.Value));
arguments[index] = BuildImport(ref context, in info.Import, info.Import.Element.AsImportData(@override.Value));
}
else
arguments[index] = Build(ref context, in info.Import);
arguments[index] = BuildImport(ref context, in info.Import);
}

return arguments;
}

protected object? Build(ref PipelineContext context, in ImportInfo<ParameterInfo> import, in ImportData data)
protected object? BuildImport(ref PipelineContext context, in ImportInfo<ParameterInfo> import, in ImportData data)
{
if (ImportType.Value == data.DataType) return data.Value;

Expand All @@ -79,7 +81,7 @@ public abstract partial class ParameterProcessor<TMemberInfo>

local.Target = data.DataType switch
{
ImportType.None => local.Resolve(),
ImportType.None => context.Container.Resolve(ref local),

ImportType.Pipeline => local.GetValueRecursively(import.Element,
((ResolveDelegate<PipelineContext>)data.Value!).Invoke(ref local)),
Expand All @@ -98,15 +100,15 @@ public abstract partial class ParameterProcessor<TMemberInfo>
return local.Target;
}

protected object? Build(ref PipelineContext context, in ImportInfo<ParameterInfo> import)
protected object? BuildImport(ref PipelineContext context, in ImportInfo<ParameterInfo> import)
{
ErrorInfo error = default;
var contract = import.Contract;
var local = import.AllowDefault
? context.CreateContext(ref contract, ref error)
: context.CreateContext(ref contract);

local.Target = local.Resolve();
local.Target = context.Container.Resolve(ref local);

if (local.IsFaulted && import.AllowDefault)
{
Expand Down
Loading

0 comments on commit 5d4c424

Please sign in to comment.