File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,4 +9,6 @@ _ReSharper.*
99* ~
1010* .log
1111packages
12- * .DotSettings
12+ * .DotSettings
13+ * .ncrunchproject
14+ * .ncrunchsolution
Original file line number Diff line number Diff line change 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 RandomGeneratorTests
10+ {
11+ [ Fact ]
12+ public void WhenGeneratingRandomIntegers_ThenShouldAlwaysGenerateIntegerBetweenMinAndMaxValue ( )
13+ {
14+ var random = new Random ( ) ;
15+ for ( int i = 0 ; i < 10 ; i ++ )
16+ {
17+ int minimumValue = random . Next ( 0 , 10 ) ;
18+ int maximumValue = random . Next ( 20 , 30 ) ;
19+ var sut = new RandomGenerator ( minimumValue , maximumValue ) ;
20+
21+ var result = sut . Generate ( ) ;
22+
23+ result . ShouldBeGreaterThanOrEqualTo ( minimumValue ) ;
24+ result . ShouldBeLessThanOrEqualTo ( maximumValue ) ;
25+ }
26+ }
27+
28+ [ Theory ,
29+ InlineData ( 0 , 0 ) ,
30+ InlineData ( 0 , - 1 ) ,
31+ InlineData ( - 1 , - 2 ) ,
32+ InlineData ( 5 , 4 ) ,
33+ InlineData ( 5 , 5 ) ]
34+ public void WhenCreatingRandomGenerator_minimumValueMustBeLessThanMaximumValue ( int minValue , int maxValue )
35+ {
36+ Action factory = ( ) => new RandomGenerator ( minValue , maxValue ) ;
37+ Should . Throw < ArgumentException > ( factory )
38+ . Message . ShouldBe ( string . Format ( "minValue must be less than maxValue" ) ) ;
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 4747 <Reference Include =" xunit" >
4848 <HintPath >..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath >
4949 </Reference >
50+ <Reference Include =" xunit.extensions" >
51+ <HintPath >..\packages\xunit.extensions.1.9.2\lib\net20\xunit.extensions.dll</HintPath >
52+ </Reference >
5053 </ItemGroup >
5154 <ItemGroup >
55+ <Compile Include =" DataSources\Generators\RandomGeneratorTests.cs" />
5256 <Compile Include =" EquivalenceClasses\StringEquivalenceClassesTests.cs" />
5357 <Compile Include =" AsProxyTests.cs" />
5458 <Compile Include =" BuildListTests.cs" />
Original file line number Diff line number Diff line change 44 <package id =" NSubstitute" version =" 1.7.2.0" targetFramework =" net40" />
55 <package id =" Shouldly" version =" 2.2.0" targetFramework =" net40" />
66 <package id =" xunit" version =" 1.9.2" targetFramework =" net40" />
7+ <package id =" xunit.extensions" version =" 1.9.2" targetFramework =" net40" />
78</packages >
Original file line number Diff line number Diff line change 1+ namespace NTestDataBuilder . DataSources . Generators
2+ {
3+ public interface IGenerator
4+ {
5+ int Generate ( ) ;
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace NTestDataBuilder . DataSources . Generators
4+ {
5+ public class RandomGenerator : IGenerator
6+ {
7+ private readonly Random _random ;
8+ private readonly int _minValue ;
9+ private readonly int _maxValue ;
10+
11+ public RandomGenerator ( int minValue , int maxValue )
12+ {
13+ if ( minValue >= maxValue )
14+ {
15+ throw new ArgumentException ( "minValue must be less than maxValue" ) ;
16+ }
17+ _minValue = minValue ;
18+ _maxValue = maxValue ;
19+ _random = new Random ( ) ;
20+ }
21+
22+ public int Generate ( )
23+ {
24+ return _random . Next ( _minValue , _maxValue ) ;
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change 5252 </ItemGroup >
5353 <ItemGroup >
5454 <Compile Include =" AnonymousValueFixture.cs" />
55+ <Compile Include =" DataSources\Generators\IGenerator.cs" />
56+ <Compile Include =" DataSources\Generators\RandomGenerator.cs" />
57+ <Compile Include =" DataSources\Generators\SequentialGenerator.cs" />
5558 <Compile Include =" EquivalenceClasses\StringEquivalenceClasses.cs" />
5659 <Compile Include =" IAnonymousValueSupplier.cs" />
5760 <Compile Include =" Lists\ListBuilder.cs" />
6871 <None Include =" NTestDataBuilder.nuspec" />
6972 <None Include =" packages.config" />
7073 </ItemGroup >
74+ <ItemGroup />
7175 <Import Project =" $(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7276 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7377 Other similar extension points exist, see Microsoft.Common.targets.
You can’t perform that action at this time.
0 commit comments