-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6408738
commit da4dec5
Showing
5 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
Assets/Reflex.EditModeTests/ReflexConstructorAttributeTests.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,69 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using Reflex.Attributes; | ||
using Reflex.Core; | ||
|
||
namespace Reflex.EditModeTests | ||
{ | ||
public class ReflexConstructorAttributeTests | ||
{ | ||
private class ClassWithReflexConstructorIdentifiedByMaxAmountOfArguments | ||
{ | ||
public bool ConstructedWithEmptyConstructor { get; } | ||
public bool ConstructedWithNonEmptyConstructor { get; } | ||
|
||
public ClassWithReflexConstructorIdentifiedByMaxAmountOfArguments() | ||
{ | ||
ConstructedWithEmptyConstructor = true; | ||
} | ||
|
||
public ClassWithReflexConstructorIdentifiedByMaxAmountOfArguments(object a, int b) | ||
{ | ||
ConstructedWithNonEmptyConstructor = true; | ||
} | ||
} | ||
|
||
private class ClassWithReflexConstructorIdentifiedByReflexConstructorAttribute | ||
{ | ||
public bool ConstructedWithEmptyConstructor { get; } | ||
public bool ConstructedWithNonEmptyConstructor { get; } | ||
|
||
[ReflexConstructor] | ||
public ClassWithReflexConstructorIdentifiedByReflexConstructorAttribute() | ||
{ | ||
ConstructedWithEmptyConstructor = true; | ||
} | ||
|
||
public ClassWithReflexConstructorIdentifiedByReflexConstructorAttribute(object a, int b) | ||
{ | ||
ConstructedWithNonEmptyConstructor = true; | ||
} | ||
} | ||
|
||
[Test] | ||
public void ClassWithMultipleConstructors_WithoutAnyReflexConstructorAttribute_ShouldBeConstructedUsing_ConstructorWithMostArguments() | ||
{ | ||
var container = new ContainerBuilder() | ||
.AddSingleton(new object()) | ||
.AddSingleton(42) | ||
.Build(); | ||
|
||
var result = container.Construct<ClassWithReflexConstructorIdentifiedByMaxAmountOfArguments>(); | ||
result.ConstructedWithEmptyConstructor.Should().BeFalse(); | ||
result.ConstructedWithNonEmptyConstructor.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public void ClassWithMultipleConstructors_WithOneDefiningReflexConstructorAttribute_ShouldBeConstructedUsing_ConstructorWithReflexConstructorAttribute() | ||
{ | ||
var container = new ContainerBuilder() | ||
.AddSingleton(new object()) | ||
.AddSingleton(42) | ||
.Build(); | ||
|
||
var result = container.Construct<ClassWithReflexConstructorIdentifiedByReflexConstructorAttribute>(); | ||
result.ConstructedWithEmptyConstructor.Should().BeTrue(); | ||
result.ConstructedWithNonEmptyConstructor.Should().BeFalse(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/Reflex.EditModeTests/ReflexConstructorAttributeTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace Reflex.Attributes | ||
{ | ||
[MeansImplicitUse(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] | ||
[AttributeUsage(AttributeTargets.Constructor)] | ||
public class ReflexConstructorAttribute : Attribute | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Reflex/Attributes/ReflexConstructorAttribute.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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