From 9eea6a147882512ea487910261d168b82e2f0861 Mon Sep 17 00:00:00 2001 From: Michael Whelan Date: Tue, 19 Jan 2016 21:26:39 +0000 Subject: [PATCH 1/4] Added Pick functionality to builders --- .../Picking/PickingTests.cs | 48 +++++++++++++++++++ .../TestStack.Dossier.Tests.csproj | 2 + TestStack.Dossier/Picking/ItemPicker.cs | 38 +++++++++++++++ TestStack.Dossier/Picking/Pick.cs | 32 +++++++++++++ TestStack.Dossier/Picking/RandomItemPicker.cs | 20 ++++++++ .../Picking/RepeatingSequenceItemPicker.cs | 20 ++++++++ TestStack.Dossier/TestStack.Dossier.csproj | 4 ++ 7 files changed, 164 insertions(+) create mode 100644 TestStack.Dossier.Tests/Picking/PickingTests.cs create mode 100644 TestStack.Dossier/Picking/ItemPicker.cs create mode 100644 TestStack.Dossier/Picking/Pick.cs create mode 100644 TestStack.Dossier/Picking/RandomItemPicker.cs create mode 100644 TestStack.Dossier/Picking/RepeatingSequenceItemPicker.cs diff --git a/TestStack.Dossier.Tests/Picking/PickingTests.cs b/TestStack.Dossier.Tests/Picking/PickingTests.cs new file mode 100644 index 0000000..dd1e4cb --- /dev/null +++ b/TestStack.Dossier.Tests/Picking/PickingTests.cs @@ -0,0 +1,48 @@ +using System.Linq; +using Shouldly; +using TestStack.Dossier.Lists; +using TestStack.Dossier.Picking; +using TestStack.Dossier.Tests.TestHelpers.Objects.Entities; +using Xunit; + +namespace TestStack.Dossier.Tests.Picking +{ + public class PickingTests + { + [Fact] + public void RandomItemFrom_should_add_items_from_list_randomly() + { + var addresses = Builder
.CreateListOfSize(15).BuildList(); + var customers = Builder + .CreateListOfSize(15) + .All() + .Set(x => x.PostalAddress, Pick.RandomItemFrom(addresses).Next) + .BuildList(); + + var uniqueAddresses = customers.Select(x => x.PostalAddress).Distinct().Count(); + uniqueAddresses.ShouldBeGreaterThan(3); + uniqueAddresses.ShouldBeLessThan(15); + } + + [Fact] + public void RepeatingSequenceFrom_should_add_items_from_list_sequentially_and_repeat_when_list_completes() + { + var addresses = Builder
.CreateListOfSize(3).BuildList(); + var customers = Builder + .CreateListOfSize(9) + .All() + .Set(x => x.PostalAddress, Pick.RepeatingSequenceFrom(addresses).Next) + .BuildList(); + + for (int i = 0; i < 2; i++) + { + var address = customers[i].PostalAddress; + address.ShouldBeSameAs(customers[i + 3].PostalAddress); + address.ShouldBeSameAs(customers[i + 6].PostalAddress); + + address.ShouldNotBeSameAs(customers[i + 1].PostalAddress); + address.ShouldNotBeSameAs(customers[i + 2].PostalAddress); + } + } + } +} diff --git a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj index e8fe2ff..617f270 100644 --- a/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj +++ b/TestStack.Dossier.Tests/TestStack.Dossier.Tests.csproj @@ -58,6 +58,7 @@ + @@ -119,6 +120,7 @@ TestStack.Dossier +