Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sbrockway/AutoFixture int…
Browse files Browse the repository at this point in the history
…o sbrockway-master
  • Loading branch information
ploeh committed Aug 11, 2016
2 parents 8eff189 + c53c0ae commit 3e66bc6
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions Src/AutoFixture/AutoFixture.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<Compile Include="DomainNameGenerator.cs" />
<Compile Include="ElementsBuilder.cs" />
<Compile Include="Kernel\SortedDictionarySpecification.cs" />
<Compile Include="Kernel\SortedListSpecification.cs" />
<Compile Include="Kernel\SortedSetSpecification.cs" />
<Compile Include="LambdaExpressionGenerator.cs" />
<Compile Include="FixtureRepeater.cs" />
Expand Down
6 changes: 6 additions & 0 deletions Src/AutoFixture/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public Fixture(ISpecimenBuilder engine, MultipleRelay multiple)
new ModestConstructorQuery()),
new DictionaryFiller()),
new SortedDictionarySpecification()),
new FilteringSpecimenBuilder(
new Postprocessor(
new MethodInvoker(
new ModestConstructorQuery()),
new DictionaryFiller()),
new SortedListSpecification()),
new FilteringSpecimenBuilder(
new MethodInvoker(
new EnumerableFavoringConstructorQuery()),
Expand Down
32 changes: 32 additions & 0 deletions Src/AutoFixture/Kernel/SortedListSpecification.cs
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();
}
}
}
1 change: 1 addition & 0 deletions Src/AutoFixtureUnitTest/AutoFixtureUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="DomainNameTest.cs" />
<Compile Include="ElementsBuilderTest.cs" />
<Compile Include="Kernel\SortedDictionarySpecificationTests.cs" />
<Compile Include="Kernel\SortedListSpecificationTest.cs" />
<Compile Include="Kernel\SortedSetSpecificationTest.cs" />
<Compile Include="LambdaExpressionGeneratorTest.cs" />
<Compile Include="FixtureRepeaterTest.cs" />
Expand Down
12 changes: 12 additions & 0 deletions Src/AutoFixtureUnitTest/FixtureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5166,6 +5166,18 @@ public void CreateSortedDictionaryReturnsCorrectResult()
// Teardown
}

[Fact]
public void CreateSortedListReturnsCorrectResult()
{
// Fixture setup
var fixture = new Fixture();
// Exercise system
var result = fixture.Create<SortedList<int,string>>();
// Verify outcome
Assert.NotEmpty(result);
// Teardown
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
76 changes: 76 additions & 0 deletions Src/AutoFixtureUnitTest/Kernel/SortedListSpecificationTest.cs
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
}
}
}

0 comments on commit 3e66bc6

Please sign in to comment.