Skip to content

Commit

Permalink
Fill SortedDictionary when asked from fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulpnath committed Jul 5, 2016
1 parent 1d62119 commit 32448c7
Show file tree
Hide file tree
Showing 6 changed files with 120 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 @@ -100,6 +100,7 @@
<Compile Include="DomainName.cs" />
<Compile Include="DomainNameGenerator.cs" />
<Compile Include="ElementsBuilder.cs" />
<Compile Include="Kernel\SortedDictionarySpecification.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 @@ -84,6 +84,12 @@ public Fixture(ISpecimenBuilder engine, MultipleRelay multiple)
new ModestConstructorQuery()),
new DictionaryFiller()),
new DictionarySpecification()),
new FilteringSpecimenBuilder(
new Postprocessor(
new MethodInvoker(
new ModestConstructorQuery()),
new DictionaryFiller()),
new SortedDictionarySpecification()),
new FilteringSpecimenBuilder(
new MethodInvoker(
new EnumerableFavoringConstructorQuery()),
Expand Down
34 changes: 34 additions & 0 deletions Src/AutoFixture/Kernel/SortedDictionarySpecification.cs
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();
}
}
}
1 change: 1 addition & 0 deletions Src/AutoFixtureUnitTest/AutoFixtureUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="DomainNameGeneratorTest.cs" />
<Compile Include="DomainNameTest.cs" />
<Compile Include="ElementsBuilderTest.cs" />
<Compile Include="Kernel\SortedDictionarySpecificationTests.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 @@ -5154,6 +5154,18 @@ public void CreateSortedSetReturnsCorrectResult()
// Teardown
}

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

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
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
}
}
}

0 comments on commit 32448c7

Please sign in to comment.