-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fill SortedDictionary when asked from fixture
- Loading branch information
1 parent
1d62119
commit 32448c7
Showing
6 changed files
with
120 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,34 @@ | ||
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="SortedDictionary{TKey, TValue}"/>. | ||
/// </summary> | ||
public class SortedDictionarySpecification : IRequestSpecification | ||
{ | ||
/// <summary> | ||
/// Evaluates a request for a specimen to determine whether it's a request for a | ||
/// <see cref="SortedDictionary{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="SortedDictionary{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(SortedDictionary<,>) == 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
66 changes: 66 additions & 0 deletions
66
Src/AutoFixtureUnitTest/Kernel/SortedDictionarySpecificationTests.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,66 @@ | ||
using Ploeh.AutoFixture.Kernel; | ||
using Ploeh.TestTypeFoundation; | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
using Xunit.Extensions; | ||
|
||
namespace Ploeh.AutoFixtureUnitTest.Kernel | ||
{ | ||
public class SortedDictionarySpecificationTests | ||
{ | ||
[Fact] | ||
public void SutIsRequestSpecification() | ||
{ | ||
// Fixture setup | ||
// Exercise system | ||
var sut = new SortedDictionarySpecification(); | ||
// Verify outcome | ||
Assert.IsAssignableFrom<IRequestSpecification>(sut); | ||
// Teardown | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[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?[]))] | ||
public void IsSatisfiedByNonSortedSetRequestReturnsCorrectResult(object request) | ||
{ | ||
// Fixture setup. | ||
var sut = new SortedDictionarySpecification(); | ||
// Exercise system | ||
var result = sut.IsSatisfiedBy(request); | ||
// Verify outcome | ||
Assert.False(result); | ||
// Teardown | ||
} | ||
|
||
[Theory] | ||
[InlineData(typeof(SortedDictionary<string,int>))] | ||
[InlineData(typeof(SortedDictionary<int,string>))] | ||
[InlineData(typeof(SortedDictionary<object,object>))] | ||
[InlineData(typeof(SortedDictionary<Version, OperatingSystem>))] | ||
public void IsSatisfiedBySortedSetRequestReturnsCorrectResult(object request) | ||
{ | ||
// Fixture setup | ||
var sut = new SortedDictionarySpecification(); | ||
// Exercise system | ||
var result = sut.IsSatisfiedBy(request); | ||
// Verify outcome | ||
Assert.True(result); | ||
// Teardown | ||
} | ||
} | ||
} |