|
| 1 | +using System; |
| 2 | +using NTestDataBuilder.DataSources.Generators; |
| 3 | +using Shouldly; |
| 4 | +using Xunit; |
| 5 | +using Xunit.Extensions; |
| 6 | + |
| 7 | +namespace NTestDataBuilder.Tests.DataSources.Generators |
| 8 | +{ |
| 9 | + public class SequentiaGeneratorTests |
| 10 | + { |
| 11 | + [Theory, |
| 12 | + InlineData(0, 0), |
| 13 | + InlineData(5, 4), |
| 14 | + InlineData(5, 5)] |
| 15 | + public void WhenCreatingRandomGenerator_ThenStartIndexMustBeLessThanListSize(int startIndex, int listSize) |
| 16 | + { |
| 17 | + Action factory = () => new SequentialGenerator(startIndex, listSize); |
| 18 | + Should.Throw<ArgumentException>(factory) |
| 19 | + .Message.ShouldBe(string.Format("startIndex must be less than listSize")); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void WhenCreatingRandomGenerator_ThenStartIndexMustBeZeroOrMore() |
| 24 | + { |
| 25 | + Action factory = () => new SequentialGenerator(-1, 1); |
| 26 | + Should.Throw<ArgumentException>(factory) |
| 27 | + .Message.ShouldBe(string.Format("startIndex must be zero or more")); |
| 28 | + } |
| 29 | + |
| 30 | + [Theory, |
| 31 | + InlineData(0, 0), |
| 32 | + InlineData(0, -1)] |
| 33 | + public void WhenCreatingRandomGenerator_ThenListSizeMustBeGreaterThanZero(int startIndex, int listSize) |
| 34 | + { |
| 35 | + Action factory = () => new SequentialGenerator(startIndex, listSize); |
| 36 | + Should.Throw<ArgumentException>(factory) |
| 37 | + .Message.ShouldBe(string.Format("listSize must be greater than zero")); |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void WhenGeneratingIntegers_ThenShouldBeSequential() |
| 43 | + { |
| 44 | + var sut = new SequentialGenerator(0, 11); |
| 45 | + for (int index = sut.StartIndex; index <= sut.ListSize; index++) |
| 46 | + { |
| 47 | + sut.Generate().ShouldBe(index); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + [Fact] |
| 52 | + public void GivenGeneratorIsNotUnique_WhenGeneratingIntegers_ThenShouldResetAtEndOfList() |
| 53 | + { |
| 54 | + var sut = new SequentialGenerator(0, 2); |
| 55 | + for (int index = sut.StartIndex; index <= sut.ListSize; index++) |
| 56 | + { |
| 57 | + sut.Generate().ShouldBe(index); |
| 58 | + } |
| 59 | + |
| 60 | + sut.Generate().ShouldBe(sut.StartIndex); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void GivenGeneratorIsUnique_WhenGeneratingIntegers_ThenShouldResetAtEndOfList() |
| 65 | + { |
| 66 | + var sut = new SequentialGenerator(0, 2, true); |
| 67 | + for (int index = sut.StartIndex; index <= sut.ListSize; index++) |
| 68 | + { |
| 69 | + sut.Generate().ShouldBe(index); |
| 70 | + } |
| 71 | + |
| 72 | + Should.Throw<InvalidOperationException>(()=>sut.Generate()) |
| 73 | + .Message.ShouldBe("There are not enough elements in the data source to continue adding items"); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + } |
| 78 | +} |
0 commit comments