-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add lazy WalkDependencies for Assembly types
- Loading branch information
1 parent
4d44caa
commit 9022498
Showing
2 changed files
with
123 additions
and
27 deletions.
There are no files selected for viewing
92 changes: 65 additions & 27 deletions
92
source/Utils/PeanutButter.Utils.NetCore.Tests/TestAssemblyExtensions.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 |
---|---|---|
@@ -1,41 +1,79 @@ | ||
using PeanutButter.RandomGenerators; | ||
using System.Reflection; | ||
using PeanutButter.RandomGenerators; | ||
|
||
namespace PeanutButter.Utils.Tests | ||
{ | ||
[TestFixture] | ||
public class TestAssemblyExtensions | ||
{ | ||
[Test] | ||
public void FindTypeByName_WhenGivenUnknownTypeName_ShouldReturnNull() | ||
[TestFixture] | ||
public class FindTypeByName | ||
{ | ||
//---------------Set up test pack------------------- | ||
var asm = GetType().Assembly; | ||
var search = RandomValueGen.GetRandomString(20, 30); | ||
//---------------Assert Precondition---------------- | ||
[TestFixture] | ||
public class GivenUnknownTypeName | ||
{ | ||
[Test] | ||
public void ShouldReturnNull() | ||
{ | ||
//---------------Set up test pack------------------- | ||
var asm = GetType().Assembly; | ||
var search = RandomValueGen.GetRandomString(20, 30); | ||
//---------------Assert Precondition---------------- | ||
|
||
//---------------Execute Test ---------------------- | ||
var result = asm.FindTypeByName(search); | ||
//---------------Execute Test ---------------------- | ||
var result = asm.FindTypeByName(search); | ||
|
||
//---------------Test Result ----------------------- | ||
Expect(result) | ||
.To.Be.Null(); | ||
//---------------Test Result ----------------------- | ||
Expect(result) | ||
.To.Be.Null(); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class GivenKnownTypeName | ||
{ | ||
[Test] | ||
public void ShouldReturnTheType() | ||
{ | ||
//---------------Set up test pack------------------- | ||
var myType = GetType(); | ||
var asm = myType.Assembly; | ||
var search = myType.Name; | ||
//---------------Assert Precondition---------------- | ||
|
||
//---------------Execute Test ---------------------- | ||
var result = asm.FindTypeByName(search); | ||
|
||
//---------------Test Result ----------------------- | ||
Expect(result) | ||
.To.Equal(myType); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void FindTypeByName_WhenGivenKnownTypeName_ShouldReturnTheType() | ||
[TestFixture] | ||
public class WalkDependencies | ||
{ | ||
//---------------Set up test pack------------------- | ||
var myType = GetType(); | ||
var asm = myType.Assembly; | ||
var search = myType.Name; | ||
//---------------Assert Precondition---------------- | ||
|
||
//---------------Execute Test ---------------------- | ||
var result = asm.FindTypeByName(search); | ||
|
||
//---------------Test Result ----------------------- | ||
Expect(result) | ||
.To.Equal(myType); | ||
[Test] | ||
public void ShouldReturnAssemblyDependenciesPerLevel() | ||
{ | ||
// Arrange | ||
// Act | ||
var collected = new List<Assembly>(); | ||
foreach (var assemblies in typeof(TestAssemblyExtensions).Assembly.WalkDependencies()) | ||
{ | ||
collected.AddRange(assemblies); | ||
} | ||
|
||
// Assert | ||
var asmNames = collected.Select(o => o.FullName).ToArray(); | ||
Expect(asmNames) | ||
.To.Contain.At.Least(80).Items( | ||
"At time of writing, this should be around 87..." | ||
); | ||
Expect(asmNames) | ||
.To.Be.Distinct(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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