Skip to content

Commit 4e5c529

Browse files
committed
Merge remote-tracking branch 'upstream/master' into any-api
2 parents 0e90bd4 + a6ffe80 commit 4e5c529

File tree

8 files changed

+144
-1
lines changed

8 files changed

+144
-1
lines changed

GitVersionConfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
mode: ContinuousDelivery
2-
next-version: 3.2.0
2+
next-version: 3.3.0
33
branches: {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Linq;
2+
using Shouldly;
3+
using TestStack.Dossier.DataSources.Picking;
4+
using TestStack.Dossier.Lists;
5+
using TestStack.Dossier.Tests.TestHelpers.Objects.Entities;
6+
using Xunit;
7+
8+
namespace TestStack.Dossier.Tests.DataSources.Picking
9+
{
10+
public class PickingTests
11+
{
12+
[Fact]
13+
public void RandomItemFrom_should_add_items_from_list_randomly()
14+
{
15+
var addresses = Builder<Address>.CreateListOfSize(15).BuildList();
16+
var customers = Builder<Customer>
17+
.CreateListOfSize(15)
18+
.All()
19+
.Set(x => x.PostalAddress, Pick.RandomItemFrom(addresses).Next)
20+
.BuildList();
21+
22+
var uniqueAddresses = customers.Select(x => x.PostalAddress).Distinct().Count();
23+
uniqueAddresses.ShouldBeGreaterThan(3);
24+
uniqueAddresses.ShouldBeLessThan(15);
25+
}
26+
27+
[Fact]
28+
public void RepeatingSequenceFrom_should_add_items_from_list_sequentially_and_repeat_when_list_completes()
29+
{
30+
var addresses = Builder<Address>.CreateListOfSize(3).BuildList();
31+
var customers = Builder<Customer>
32+
.CreateListOfSize(9)
33+
.All()
34+
.Set(x => x.PostalAddress, Pick.RepeatingSequenceFrom(addresses).Next)
35+
.BuildList();
36+
37+
for (int i = 0; i < 2; i++)
38+
{
39+
var address = customers[i].PostalAddress;
40+
address.ShouldBeSameAs(customers[i + 3].PostalAddress);
41+
address.ShouldBeSameAs(customers[i + 6].PostalAddress);
42+
43+
address.ShouldNotBeSameAs(customers[i + 1].PostalAddress);
44+
address.ShouldNotBeSameAs(customers[i + 2].PostalAddress);
45+
}
46+
}
47+
}
48+
}

TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="EquivalenceClasses\PersonEquivalenceClassesTests.cs" />
7979
<Compile Include="EquivalenceClasses\ShirtSizeEquivalenceTests.cs" />
8080
<Compile Include="PublicApiApproval\PublicApiApproverTests.cs" />
81+
<Compile Include="DataSources\Picking\PickingTests.cs" />
8182
<Compile Include="TestHelpers\Builders\AddressViewModelBuilder.cs" />
8283
<Compile Include="TestHelpers\Builders\AutoConstructorCustomerBuilder.cs" />
8384
<Compile Include="ChildBuilderTests.cs" />
@@ -139,6 +140,7 @@
139140
<Name>TestStack.Dossier</Name>
140141
</ProjectReference>
141142
</ItemGroup>
143+
<ItemGroup />
142144
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
143145
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
144146
Other similar extension points exist, see Microsoft.Common.targets.

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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
3+
namespace TestStack.Dossier.DataSources.Picking
4+
{
5+
/// <summary>
6+
/// Pick a sequence of items from a collection of items according to different selection strategies.
7+
/// </summary>
8+
public class Pick
9+
{
10+
/// <summary>
11+
/// Selects a random item from the list each time it is called.
12+
/// </summary>
13+
/// <typeparam name="T"></typeparam>
14+
/// <param name="list">The list.</param>
15+
/// <returns>The RandomItemSource class.</returns>
16+
public static RandomItemSource<T> RandomItemFrom<T>(IList<T> list)
17+
{
18+
return new RandomItemSource<T>(list);
19+
}
20+
21+
/// <summary>
22+
/// Selects each item sequentially from the list and starts again from the beginning when the list is exhausted.
23+
/// </summary>
24+
/// <typeparam name="T"></typeparam>
25+
/// <param name="list">The list.</param>
26+
/// <returns></returns>
27+
public static RepeatingSequenceSource<T> RepeatingSequenceFrom<T>(IList<T> list)
28+
{
29+
return new RepeatingSequenceSource<T>(list);
30+
}
31+
}
32+
}
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.Picking
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.Picking
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/TestStack.Dossier.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
<Compile Include="EquivalenceClasses\InternetEquivalence.cs" />
7171
<Compile Include="EquivalenceClasses\LoremIpsumEquivalence.cs" />
7272
<Compile Include="EquivalenceClasses\PersonEquivalence.cs" />
73+
<Compile Include="DataSources\Picking\Pick.cs" />
74+
<Compile Include="DataSources\Picking\RandomItemSource.cs" />
75+
<Compile Include="DataSources\Picking\RepeatingSequenceSource.cs" />
7376
<Compile Include="ITestDataBuilder.cs" />
7477
<Compile Include="DataSources\Dictionaries\WordsCache.cs" />
7578
<Compile Include="DataSources\Dictionaries\IDictionaryRepository.cs" />
@@ -181,6 +184,9 @@
181184
<EmbeddedResource Include="DataSources\Dictionaries\Resources\ShirtSize.txt" />
182185
</ItemGroup>
183186
<ItemGroup />
187+
<ItemGroup>
188+
<Folder Include="Picking\" />
189+
</ItemGroup>
184190
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
185191
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
186192
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)