Skip to content

Commit 76a322a

Browse files
committed
Refactored Pickers as DataSources
1 parent 9eea6a1 commit 76a322a

File tree

9 files changed

+68
-89
lines changed

9 files changed

+68
-89
lines changed

TestStack.Dossier.Tests/Picking/PickingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Linq;
22
using Shouldly;
3+
using TestStack.Dossier.DataSources;
34
using TestStack.Dossier.Lists;
4-
using TestStack.Dossier.Picking;
55
using TestStack.Dossier.Tests.TestHelpers.Objects.Entities;
66
using Xunit;
77

TestStack.Dossier/DataSources/DataSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public IList<T> Data
4040
}
4141
return _list;
4242
}
43+
internal set { _list = value; }
4344
}
4445

4546
/// <summary>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
22

3-
namespace TestStack.Dossier.Picking
3+
namespace TestStack.Dossier.DataSources
44
{
55
/// <summary>
66
/// Pick a sequence of items from a collection of items according to different selection strategies.
@@ -12,10 +12,10 @@ public class Pick
1212
/// </summary>
1313
/// <typeparam name="T"></typeparam>
1414
/// <param name="list">The list.</param>
15-
/// <returns>The RandomItemPicker class.</returns>
16-
public static RandomItemPicker<T> RandomItemFrom<T>(IList<T> list)
15+
/// <returns>The RandomItemSource class.</returns>
16+
public static RandomItemSource<T> RandomItemFrom<T>(IList<T> list)
1717
{
18-
return new RandomItemPicker<T>(list);
18+
return new RandomItemSource<T>(list);
1919
}
2020

2121
/// <summary>
@@ -24,9 +24,9 @@ public static RandomItemPicker<T> RandomItemFrom<T>(IList<T> list)
2424
/// <typeparam name="T"></typeparam>
2525
/// <param name="list">The list.</param>
2626
/// <returns></returns>
27-
public static RepeatingSequenceItemPicker<T> RepeatingSequenceFrom<T>(IList<T> list)
27+
public static RepeatingSequenceSource<T> RepeatingSequenceFrom<T>(IList<T> list)
2828
{
29-
return new RepeatingSequenceItemPicker<T>(list);
29+
return new RepeatingSequenceSource<T>(list);
3030
}
3131
}
3232
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace TestStack.Dossier.DataSources
5+
{
6+
/// <summary>
7+
/// Implements the random item strategy
8+
/// </summary>
9+
public class RandomItemSource<T> : DataSource<T>
10+
{
11+
/// <inheritdoc />
12+
public RandomItemSource(IList<T> list)
13+
{
14+
Data = list;
15+
Generator.StartIndex = 0;
16+
Generator.ListSize = Data.Count;
17+
}
18+
19+
/// <inheritdoc />
20+
protected override IList<T> InitializeDataSource()
21+
{
22+
// This method will never be called as the list is set in the constructor.
23+
throw new NotImplementedException();
24+
}
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using TestStack.Dossier.DataSources.Generators;
4+
5+
namespace TestStack.Dossier.DataSources
6+
{
7+
/// <summary>
8+
/// Implements the repeatable sequence strategy
9+
/// </summary>
10+
public class RepeatingSequenceSource<T> : DataSource<T>
11+
{
12+
/// <inheritdoc />
13+
public RepeatingSequenceSource(IList<T> list)
14+
: base(new SequentialGenerator())
15+
{
16+
Data = list;
17+
Generator.StartIndex = 0;
18+
Generator.ListSize = Data.Count;
19+
}
20+
21+
/// <inheritdoc />
22+
protected override IList<T> InitializeDataSource()
23+
{
24+
// This method will never be called as the list is set in the constructor.
25+
throw new NotImplementedException();
26+
}
27+
}
28+
}

TestStack.Dossier/Picking/ItemPicker.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

TestStack.Dossier/Picking/RandomItemPicker.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

TestStack.Dossier/Picking/RepeatingSequenceItemPicker.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

TestStack.Dossier/TestStack.Dossier.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<ItemGroup>
5353
<Compile Include="AnonymousValueFixture.cs" />
5454
<Compile Include="Builder.cs" />
55+
<Compile Include="DataSources\Pick.cs" />
56+
<Compile Include="DataSources\RandomItemSource.cs" />
57+
<Compile Include="DataSources\RepeatingSequenceSource.cs" />
5558
<Compile Include="ITestDataBuilder.cs" />
5659
<Compile Include="DataSources\Dictionaries\Cache.cs" />
5760
<Compile Include="DataSources\Dictionaries\IDictionaryRepository.cs" />
@@ -94,10 +97,6 @@
9497
<Compile Include="NullingExpandoObject.cs" />
9598
<Compile Include="Factories\IFactory.cs" />
9699
<Compile Include="PathExpressionVisitor.cs" />
97-
<Compile Include="Picking\ItemPicker.cs" />
98-
<Compile Include="Picking\Pick.cs" />
99-
<Compile Include="Picking\RandomItemPicker.cs" />
100-
<Compile Include="Picking\RepeatingSequenceItemPicker.cs" />
101100
<Compile Include="Reflector.cs" />
102101
<Compile Include="Suppliers\DefaultEmailValueSupplier.cs" />
103102
<Compile Include="Suppliers\DefaultLastNameValueSupplier.cs" />
@@ -183,6 +182,9 @@
183182
<EmbeddedResource Include="DataSources\Dictionaries\Resources\PersonUsername.txt" />
184183
<EmbeddedResource Include="DataSources\Dictionaries\Resources\ShirtSize.txt" />
185184
</ItemGroup>
185+
<ItemGroup>
186+
<Folder Include="Picking\" />
187+
</ItemGroup>
186188
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
187189
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
188190
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)