-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from BenjaminAbt/feature/add-more-tests-3
add missing assembly prefix and instance tests
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 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
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
46 changes: 46 additions & 0 deletions
46
tests/StrongOf.UnitTests/Factories/StrongOfInstanceFactoryTests.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,46 @@ | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using StrongOf.Factories; | ||
using Xunit; | ||
|
||
namespace StrongOf.UnitTests.Factories; | ||
|
||
public class StrongOfInstanceFactoryTests | ||
{ | ||
private sealed class TestInt32Of(int Value) : StrongInt32<TestInt32Of>(Value) { } | ||
|
||
[Fact] | ||
public void CreateWithOneParameterExpression_SuccessfullyCreatesLambdaExpression() | ||
{ | ||
// Arrange | ||
Type expectedStrong = typeof(TestInt32Of); | ||
Type expectedType = typeof(int); | ||
ConstructorInfo? expectedCtor = expectedStrong.GetConstructor([expectedType]); | ||
|
||
ArgumentNullException.ThrowIfNull(expectedCtor); | ||
|
||
// Act | ||
LambdaExpression lambdaExpression = StrongOfInstanceFactory.CreateWithOneParameterExpression<TestInt32Of, int>(); | ||
|
||
// Assert | ||
Assert.NotNull(lambdaExpression); | ||
|
||
// Assert type | ||
Assert.IsAssignableFrom<LambdaExpression>(lambdaExpression); | ||
Assert.IsAssignableFrom<Expression<Func<int, TestInt32Of>>>(lambdaExpression); | ||
|
||
// Assert instance | ||
Func<int, TestInt32Of> func = (Func<int, TestInt32Of>)lambdaExpression.Compile(); | ||
TestInt32Of newInstance = func.Invoke(10); | ||
|
||
Assert.NotNull(newInstance); | ||
Assert.IsType<TestInt32Of>(newInstance); | ||
|
||
// Assert params | ||
Expression? ctorParameter = ((NewExpression)lambdaExpression.Body).Arguments.First(); | ||
Assert.Equal(expectedType, ctorParameter.Type); | ||
|
||
ConstructorInfo? ctor = ((NewExpression)lambdaExpression.Body).Constructor; | ||
Assert.Equal(expectedCtor, ctor); | ||
} | ||
} |