-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/sbrockway/AutoFixture int…
…o sbrockway-master
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Ploeh.AutoFixture.Kernel | ||
{ | ||
/// <summary> | ||
/// Encapsulates logic that determines whether a request is a request for a | ||
/// <see cref="SortedList{TKey,TValue}"/>. | ||
/// </summary> | ||
public class SortedListSpecification : IRequestSpecification | ||
{ | ||
/// <summary> | ||
/// Evaluates a request for a specimen to determine whether it's a request for a | ||
/// <see cref="SortedList{TKey,TValue}"/>. | ||
/// </summary> | ||
/// <param name="request">The specimen request.</param> | ||
/// <returns> | ||
/// <see langword="true"/> if <paramref name="request"/> is a request for a | ||
/// <see cref="SortedList{TKey,TValue}" />; otherwise, <see langword="false"/>. | ||
/// </returns> | ||
public bool IsSatisfiedBy(object request) | ||
{ | ||
var type = request as Type; | ||
if (type == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return type.IsGenericType && typeof(SortedList<,>) == type.GetGenericTypeDefinition(); | ||
} | ||
} | ||
} |
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
76 changes: 76 additions & 0 deletions
76
Src/AutoFixtureUnitTest/Kernel/SortedListSpecificationTest.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,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Ploeh.AutoFixture.Kernel; | ||
using Ploeh.TestTypeFoundation; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Ploeh.AutoFixtureUnitTest.Kernel | ||
{ | ||
public class SortedListSpecificationTest | ||
{ | ||
[Fact] | ||
public void SutIsRequestSpecification() | ||
{ | ||
// Fixture setup | ||
// Exercise system | ||
var sut = new SortedListSpecification(); | ||
// Verify outcome | ||
Assert.IsAssignableFrom<IRequestSpecification>(sut); | ||
// Teardown | ||
} | ||
|
||
[Theory] | ||
[InlineData(typeof(SortedList<int, string>))] | ||
[InlineData(typeof(SortedList<string, int>))] | ||
[InlineData(typeof(SortedList<object, Version>))] | ||
[InlineData(typeof(SortedList<Version, object>))] | ||
[InlineData(typeof(SortedList<int?, EmptyEnum?>))] | ||
[InlineData(typeof(SortedList<EmptyEnum?, int?>))] | ||
[InlineData(typeof(SortedList<string[], int[]>))] | ||
[InlineData(typeof(SortedList<int[], string[]>))] | ||
[InlineData(typeof(SortedList<object[], Version[]>))] | ||
[InlineData(typeof(SortedList<Version[], object[]>))] | ||
[InlineData(typeof(SortedList<int?[], EmptyEnum?[]>))] | ||
[InlineData(typeof(SortedList<EmptyEnum?[], int?[]>))] | ||
public void IsSatisfiedBySortedListRequestReturnsCorrectResult(object request) | ||
{ | ||
// Fixture setup | ||
var sut = new SortedListSpecification(); | ||
// Exercise system | ||
var result = sut.IsSatisfiedBy(request); | ||
// Verify outcome | ||
Assert.True(result); | ||
// Teardown | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] // non-Type | ||
[InlineData(1)] | ||
[InlineData(typeof(object))] | ||
[InlineData(typeof(string))] | ||
[InlineData(typeof(int))] | ||
[InlineData(typeof(Version))] | ||
[InlineData(typeof(int?))] | ||
[InlineData(typeof(EmptyEnum?))] | ||
[InlineData(typeof(object[]))] | ||
[InlineData(typeof(string[]))] | ||
[InlineData(typeof(int[]))] | ||
[InlineData(typeof(Version[]))] | ||
[InlineData(typeof(int?[]))] | ||
[InlineData(typeof(EmptyEnum?[]))] | ||
[InlineData(typeof(List<object>))] // Generic, but not SortedList<,> | ||
[InlineData(typeof(Dictionary<object, Version>))] // double parameter generic, that implements same interface | ||
public void IsSatisfiedByNonSortedListRequestReturnsCorrectResult(object request) | ||
{ | ||
// Fixture setup | ||
var sut = new SortedListSpecification(); | ||
// Exercise system | ||
var result = sut.IsSatisfiedBy(request); | ||
// Verify outcome | ||
Assert.False(result); | ||
// Teardown | ||
} | ||
} | ||
} |