Skip to content

Commit a81d17b

Browse files
committed
Merge pull request #62 from Tynamix/blmeyers-master
Blmeyers master
2 parents 5432cd7 + 5605481 commit a81d17b

File tree

5 files changed

+116
-71
lines changed

5 files changed

+116
-71
lines changed

ObjectFiller.Test/RandomAccessTest.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace ObjectFiller.Test
2+
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
using Xunit;
8+
using Tynamix.ObjectFiller;
9+
10+
11+
public class RandomAccessTest
12+
{
13+
[Fact]
14+
public void GetRandomIntOnDifferentThreadsGetsDifferentResults()
15+
{
16+
var numberToGenerate = 1000;
17+
var intRange = new IntRange(1, 10);
18+
var task1 = Task.Factory.StartNew(() =>
19+
{
20+
var taskResults = new List<int>();
21+
for (int i = 0; i < numberToGenerate; ++i)
22+
{
23+
taskResults.Add(Randomizer<int>.Create(intRange));
24+
}
25+
return taskResults;
26+
},
27+
TaskCreationOptions.LongRunning
28+
);
29+
var task2 = Task.Factory.StartNew(() =>
30+
{
31+
var taskResults = new List<int>();
32+
for (int i = 0; i < numberToGenerate; ++i)
33+
{
34+
taskResults.Add(Randomizer<int>.Create(intRange));
35+
}
36+
return taskResults;
37+
},
38+
TaskCreationOptions.LongRunning
39+
);
40+
var results = Task.WhenAll(task1, task2).Result;
41+
var firstResults = results[0].Sum();
42+
var secondResults = results[1].Sum();
43+
Assert.NotEqual(firstResults, secondResults);
44+
}
45+
}
46+
}

ObjectFiller.Test/project.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
"dependencies": {
160160
"System.Collections": "4.0.10",
161161
"System.Diagnostics.Debug": "4.0.10",
162-
"System.Linq": "4.0.1",
162+
"System.Linq": "4.0.0",
163163
"System.Linq.Expressions": "4.0.10",
164164
"System.Runtime.Extensions": "4.0.10",
165165
"System.Text.RegularExpressions": "4.0.10"
@@ -1323,7 +1323,7 @@
13231323
"dependencies": {
13241324
"System.Collections": "4.0.10",
13251325
"System.Diagnostics.Debug": "4.0.10",
1326-
"System.Linq": "4.0.1",
1326+
"System.Linq": "4.0.0",
13271327
"System.Linq.Expressions": "4.0.10",
13281328
"System.Runtime.Extensions": "4.0.10",
13291329
"System.Text.RegularExpressions": "4.0.10"
@@ -2580,7 +2580,7 @@
25802580
"dependencies": {
25812581
"System.Collections": "4.0.10",
25822582
"System.Diagnostics.Debug": "4.0.10",
2583-
"System.Linq": "4.0.1",
2583+
"System.Linq": "4.0.0",
25842584
"System.Linq.Expressions": "4.0.10",
25852585
"System.Runtime.Extensions": "4.0.10",
25862586
"System.Text.RegularExpressions": "4.0.10"

ObjectFiller/Random.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,47 @@ namespace Tynamix.ObjectFiller
1919
/// </summary>
2020
internal static class Random
2121
{
22+
23+
private static int RandomSeed;
2224
/// <summary>
25+
/// Initializes static members of the <see cref="Random"/> class.
2326
/// A instance of <see cref="Random"/>
2427
/// </summary>
25-
[ThreadStatic]
26-
private static readonly System.Random Rnd;
28+
static Random()
29+
{
30+
RandomSeed = Environment.TickCount;
31+
}
2732

33+
#if NET3X
2834
/// <summary>
29-
/// Initializes static members of the <see cref="Random"/> class.
35+
/// A instance of <see cref="Random"/>
3036
/// </summary>
31-
static Random()
37+
[ThreadStatic]
38+
private static System.Random RndStorage;
39+
40+
private static System.Random Rnd
3241
{
33-
#if NETSTD
34-
Rnd = new System.Random();
42+
get
43+
{
44+
if (RndStorage == null)
45+
{
46+
RndStorage = new System.Random(Interlocked.Increment(ref RandomSeed));
47+
}
48+
return RndStorage;
49+
}
50+
}
3551
#else
36-
int seed = Environment.TickCount;
37-
Rnd = new System.Random(Interlocked.Increment(ref seed));
38-
#endif
52+
private static readonly ThreadLocal<System.Random> RndStorage = new ThreadLocal<System.Random>(() =>
53+
new System.Random(Interlocked.Increment(ref RandomSeed)));
54+
55+
/// <summary>
56+
/// A instance of <see cref="Random"/>
57+
/// </summary>
58+
private static System.Random Rnd
59+
{
60+
get { return RndStorage.Value; }
3961
}
62+
#endif
4063

4164
/// <summary>
4265
/// Returns a nonnegative number

ObjectFiller/project.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"title": "Tynamix.ObjectFiller",
3-
"version": "1.4.0",
2+
"title": ".NET ObjectFiller - Fill .NET objects with customized random data - by Tynamix",
3+
"version": "1.4.1",
44
"description": "The Tynamix ObjectFiller.NET fills the properties of your objects with random data. Use it for unittest, prototyping and whereever you need some random testdata. It has a fluent API and is highly customizable. It supports also IEnumerables and Dictionaries and constructors WITH parameters. It is also possible to fill instances and to write private properties.",
55
"summary": "The Tynamix ObjectFiller.NET fills the properties of your objects with customized random data. Use it for unittests, prototyping and whereever you need some random testdata.",
66
"authors": [ "Roman Köhler", "Hendrik L.", "Christian Harlass", "GothikX" ],
77
"tags": [ "objectfiller", "tynamix", "test", "testdata", "prototyp", "prototyping", "unittest", "design", "designviewmodel", "generator", "random", "data", "randomdata", "testing", "poco", "lorem", "ipsum", "fakedata", "fake", "faker" ],
88
"projectUrl": "http://objectfiller.net/",
99
"iconUrl": "https://raw.githubusercontent.com/gokTyBalD/ObjectFiller.NET/master/logo.png",
1010
"licenseUrl": "https://github.com/Tynamix/ObjectFiller.NET/blob/master/LICENSE.txt",
11-
"releaseNotes": "-1.4.0\r\n* Updated to .NET Core. Now you can use ObjectFiller.NET in your .NET Core (DNX) and Windows 10 (UWP) environment!\r\n* FillerSetup can now be used for dedicated properties or types\r\n* Bugfixes\r\n\r\n-1.3.9\r\n* Bug fixed when creating types with a copy constructor \r\n\r\n-1.3.8\r\n* Support for Arrays and Nullable Enumerations\r\n* Bugfixes (thx to Hendrik L.)\r\n\r\n-1.3.6\r\n* Added Randomizer<T> class to easy generate data for simple types like int, double, string\r\n* Support for complex standalone CLR types like List<T>\r\n* CityName plugin (Thx to Hendrik L.)\r\n* E-Mail-Address plugin (Thx to Hendrik L.)\r\n* StreetName plugin (Thx to Hendrik L.)\r\n* CountryName plugin\r\n* Code cleanup\r\n* Bugfixes\r\n\r\n-1.3.2\r\n* Bugfixes\r\n\r\n-1.3.1\r\n* Easier usage of static values in the \"Use\" API\r\n* Added missing type mappings\r\n* Some bugfixes and improvements\r\n\r\n-1.3.0\r\n* Circular Reference Detection (thx to GothikX)\r\n* Export the ObjectFiller setup and reuse it somewhere else\r\n* Improved LoremIpsum Plugin (thx to GothikX)\r\n* Many bugfixes and improvements\r\n\r\n-1.2.8\r\n* IgnoreAllUnknownTypes added\r\n* Usage of RandomList-Plugin improved\r\n* IntRange-Plugin handles now also nullable int!\r\n\r\n-1.2.4\r\n* Create multiple instances\r\n* Some bugfixes and improvements\r\n\r\n-1.2.3\r\n* Use enumerables to fill objects (thx to charlass)\r\n* Its now possible to fill enum properties (thx to charlass)\r\n* Implemented SequenceGenerator (thx to charlass)\r\n\r\n-1.2.1\r\n* Complete refactoring of the FluentAPI. Read the documentation on objectfiller.net for more information!\r\n* Properties with private setter are able to write.\r\n* Renamed ObjectFiller to Filler to avoid NameSpace conflicts\r\n* Order properties implemented\r\n* IntRange Plugin implemented\r\n* ...some more improvements and bugfixes\r\n\r\n-1.1.8\r\n* Bugfix in RandomizerForProperty\r\n\r\n-1.1.7\r\n* Implemented a Lorem Ipsum string plugin\r\n\r\n-1.1.6\r\n* new fantastic PatternGenerator-Plugin. Thanks to charlass for this!\r\n* Adjust namespaces from ObjectFiller to Tynamix.ObjectFiller\r\n\r\n-1.1.4\r\n* IgnoreAllOfType added.\r\n* Little changes to the main API\r\n\r\n-1.1.2\r\n* moved to github\r\n\r\n-1.1.0\r\n* Changed the fluent API to make it even easier than before to use.\r\n\r\n-1.0.22\r\n* Bugfix when handling lists\r\n\r\n-1.0.21\r\n* Constructors with parameters are now possible as long as the types of parameters are configured in the ObjectFiller.NET setup!\r\n\r\n-1.0.16\r\n* RandomListItem-Plugin\r\n\r\n-1.0.15\r\n* Major Bugfix\r\n\r\n-1.0.14\r\n* Bugfixes\r\n\r\n-1.0.12\r\n* RealNameListString Plugin\r\n* DoubleMinMax plugin\r\n\r\n-1.0.10\r\n* Its now possible to ignore properties.\r\n* Fluent API documented.\r\n* Better ExceptionMessages\r\n* Bugfixes\r\n\r\n-1.0.6\r\n* Its now possible to setup a randomizer to a specific property!\r\n\r\n-1.0.0\r\n* Initial release",
11+
"releaseNotes": "-1.4.1\r\n* Fixing Bug with Multi Threaded Random Access (Thanks to blmeyers)\r\n\r\n-1.4.0\r\n* Updated to .NET Core. Now you can use ObjectFiller.NET in your .NET Core (DNX) and Windows 10 (UWP) environment!\r\n* FillerSetup can now be used for dedicated properties or types\r\n* Bugfixes\r\n\r\n-1.3.9\r\n* Bug fixed when creating types with a copy constructor \r\n\r\n-1.3.8\r\n* Support for Arrays and Nullable Enumerations\r\n* Bugfixes (thx to Hendrik L.)\r\n\r\n-1.3.6\r\n* Added Randomizer<T> class to easy generate data for simple types like int, double, string\r\n* Support for complex standalone CLR types like List<T>\r\n* CityName plugin (Thx to Hendrik L.)\r\n* E-Mail-Address plugin (Thx to Hendrik L.)\r\n* StreetName plugin (Thx to Hendrik L.)\r\n* CountryName plugin\r\n* Code cleanup\r\n* Bugfixes\r\n\r\n-1.3.2\r\n* Bugfixes\r\n\r\n-1.3.1\r\n* Easier usage of static values in the \"Use\" API\r\n* Added missing type mappings\r\n* Some bugfixes and improvements\r\n\r\n-1.3.0\r\n* Circular Reference Detection (thx to GothikX)\r\n* Export the ObjectFiller setup and reuse it somewhere else\r\n* Improved LoremIpsum Plugin (thx to GothikX)\r\n* Many bugfixes and improvements\r\n\r\n-1.2.8\r\n* IgnoreAllUnknownTypes added\r\n* Usage of RandomList-Plugin improved\r\n* IntRange-Plugin handles now also nullable int!\r\n\r\n-1.2.4\r\n* Create multiple instances\r\n* Some bugfixes and improvements\r\n\r\n-1.2.3\r\n* Use enumerables to fill objects (thx to charlass)\r\n* Its now possible to fill enum properties (thx to charlass)\r\n* Implemented SequenceGenerator (thx to charlass)\r\n\r\n-1.2.1\r\n* Complete refactoring of the FluentAPI. Read the documentation on objectfiller.net for more information!\r\n* Properties with private setter are able to write.\r\n* Renamed ObjectFiller to Filler to avoid NameSpace conflicts\r\n* Order properties implemented\r\n* IntRange Plugin implemented\r\n* ...some more improvements and bugfixes\r\n\r\n-1.1.8\r\n* Bugfix in RandomizerForProperty\r\n\r\n-1.1.7\r\n* Implemented a Lorem Ipsum string plugin\r\n\r\n-1.1.6\r\n* new fantastic PatternGenerator-Plugin. Thanks to charlass for this!\r\n* Adjust namespaces from ObjectFiller to Tynamix.ObjectFiller\r\n\r\n-1.1.4\r\n* IgnoreAllOfType added.\r\n* Little changes to the main API\r\n\r\n-1.1.2\r\n* moved to github\r\n\r\n-1.1.0\r\n* Changed the fluent API to make it even easier than before to use.\r\n\r\n-1.0.22\r\n* Bugfix when handling lists\r\n\r\n-1.0.21\r\n* Constructors with parameters are now possible as long as the types of parameters are configured in the ObjectFiller.NET setup!\r\n\r\n-1.0.16\r\n* RandomListItem-Plugin\r\n\r\n-1.0.15\r\n* Major Bugfix\r\n\r\n-1.0.14\r\n* Bugfixes\r\n\r\n-1.0.12\r\n* RealNameListString Plugin\r\n* DoubleMinMax plugin\r\n\r\n-1.0.10\r\n* Its now possible to ignore properties.\r\n* Fluent API documented.\r\n* Better ExceptionMessages\r\n* Bugfixes\r\n\r\n-1.0.6\r\n* Its now possible to setup a randomizer to a specific property!\r\n\r\n-1.0.0\r\n* Initial release",
1212

1313
"frameworks": {
1414
"net40": {
@@ -35,7 +35,7 @@
3535
"dependencies": {
3636
"System.Collections": "4.0.10-*",
3737
"System.Diagnostics.Debug": "4.0.10-*",
38-
"System.Linq": "4.0.1-*",
38+
"System.Linq": "4.0.0-*",
3939
"System.Linq.Expressions": "4.0.10-*",
4040
"System.Runtime.Extensions": "4.0.10-*",
4141
"System.Text.RegularExpressions": "4.0.10-*"

ObjectFiller/project.lock.json

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,14 +1163,20 @@
11631163
"ref/dotnet/System.IO.dll": {}
11641164
}
11651165
},
1166-
"System.Linq/4.0.1-beta-23516": {
1166+
"System.Linq/4.0.0": {
11671167
"type": "package",
11681168
"dependencies": {
1169-
"System.Collections": "4.0.0",
1170-
"System.Runtime": "4.0.0"
1169+
"System.Collections": "4.0.10",
1170+
"System.Diagnostics.Debug": "4.0.10",
1171+
"System.Resources.ResourceManager": "4.0.0",
1172+
"System.Runtime": "4.0.20",
1173+
"System.Runtime.Extensions": "4.0.10"
11711174
},
11721175
"compile": {
1173-
"ref/dotnet5.1/System.Linq.dll": {}
1176+
"ref/dotnet/System.Linq.dll": {}
1177+
},
1178+
"runtime": {
1179+
"lib/dotnet/System.Linq.dll": {}
11741180
}
11751181
},
11761182
"System.Linq.Expressions/4.0.10": {
@@ -3660,14 +3666,20 @@
36603666
"ref/dotnet/System.IO.dll": {}
36613667
}
36623668
},
3663-
"System.Linq/4.0.1-beta-23516": {
3669+
"System.Linq/4.0.0": {
36643670
"type": "package",
36653671
"dependencies": {
3666-
"System.Collections": "4.0.0",
3667-
"System.Runtime": "4.0.0"
3672+
"System.Collections": "4.0.10",
3673+
"System.Diagnostics.Debug": "4.0.10",
3674+
"System.Resources.ResourceManager": "4.0.0",
3675+
"System.Runtime": "4.0.20",
3676+
"System.Runtime.Extensions": "4.0.10"
36683677
},
36693678
"compile": {
3670-
"ref/dotnet5.1/System.Linq.dll": {}
3679+
"ref/dotnet/System.Linq.dll": {}
3680+
},
3681+
"runtime": {
3682+
"lib/dotnet/System.Linq.dll": {}
36713683
}
36723684
},
36733685
"System.Linq.Expressions/4.0.10": {
@@ -3834,14 +3846,20 @@
38343846
"ref/dotnet/System.IO.dll": {}
38353847
}
38363848
},
3837-
"System.Linq/4.0.1-beta-23516": {
3849+
"System.Linq/4.0.0": {
38383850
"type": "package",
38393851
"dependencies": {
3840-
"System.Collections": "4.0.0",
3841-
"System.Runtime": "4.0.0"
3852+
"System.Collections": "4.0.10",
3853+
"System.Diagnostics.Debug": "4.0.10",
3854+
"System.Resources.ResourceManager": "4.0.0",
3855+
"System.Runtime": "4.0.20",
3856+
"System.Runtime.Extensions": "4.0.10"
38423857
},
38433858
"compile": {
3844-
"ref/dotnet5.1/System.Linq.dll": {}
3859+
"ref/dotnet/System.Linq.dll": {}
3860+
},
3861+
"runtime": {
3862+
"lib/dotnet/System.Linq.dll": {}
38453863
}
38463864
},
38473865
"System.Linq.Expressions/4.0.10": {
@@ -4899,48 +4917,6 @@
48994917
"System.Linq.nuspec"
49004918
]
49014919
},
4902-
"System.Linq/4.0.1-beta-23516": {
4903-
"type": "package",
4904-
"serviceable": true,
4905-
"sha512": "uNxm2RB+kMeiKnY26iPvOtJLzTzNaAF4A2qqyzev6j8x8w2Dr+gg7LF7BHCwC55N7OirhHrAWUb3C0n4oi9qYw==",
4906-
"files": [
4907-
"lib/dotnet5.4/System.Linq.dll",
4908-
"lib/net45/_._",
4909-
"lib/netcore50/System.Linq.dll",
4910-
"lib/win8/_._",
4911-
"lib/wp80/_._",
4912-
"lib/wpa81/_._",
4913-
"ref/dotnet5.1/de/System.Linq.xml",
4914-
"ref/dotnet5.1/es/System.Linq.xml",
4915-
"ref/dotnet5.1/fr/System.Linq.xml",
4916-
"ref/dotnet5.1/it/System.Linq.xml",
4917-
"ref/dotnet5.1/ja/System.Linq.xml",
4918-
"ref/dotnet5.1/ko/System.Linq.xml",
4919-
"ref/dotnet5.1/ru/System.Linq.xml",
4920-
"ref/dotnet5.1/System.Linq.dll",
4921-
"ref/dotnet5.1/System.Linq.xml",
4922-
"ref/dotnet5.1/zh-hans/System.Linq.xml",
4923-
"ref/dotnet5.1/zh-hant/System.Linq.xml",
4924-
"ref/net45/_._",
4925-
"ref/netcore50/de/System.Linq.xml",
4926-
"ref/netcore50/es/System.Linq.xml",
4927-
"ref/netcore50/fr/System.Linq.xml",
4928-
"ref/netcore50/it/System.Linq.xml",
4929-
"ref/netcore50/ja/System.Linq.xml",
4930-
"ref/netcore50/ko/System.Linq.xml",
4931-
"ref/netcore50/ru/System.Linq.xml",
4932-
"ref/netcore50/System.Linq.dll",
4933-
"ref/netcore50/System.Linq.xml",
4934-
"ref/netcore50/zh-hans/System.Linq.xml",
4935-
"ref/netcore50/zh-hant/System.Linq.xml",
4936-
"ref/win8/_._",
4937-
"ref/wp80/_._",
4938-
"ref/wpa81/_._",
4939-
"System.Linq.4.0.1-beta-23516.nupkg",
4940-
"System.Linq.4.0.1-beta-23516.nupkg.sha512",
4941-
"System.Linq.nuspec"
4942-
]
4943-
},
49444920
"System.Linq.Expressions/4.0.10": {
49454921
"type": "package",
49464922
"serviceable": true,
@@ -6307,7 +6283,7 @@
63076283
".NETPlatform,Version=v5.1": [
63086284
"System.Collections >= 4.0.10-*",
63096285
"System.Diagnostics.Debug >= 4.0.10-*",
6310-
"System.Linq >= 4.0.1-*",
6286+
"System.Linq >= 4.0.0-*",
63116287
"System.Linq.Expressions >= 4.0.10-*",
63126288
"System.Runtime.Extensions >= 4.0.10-*",
63136289
"System.Text.RegularExpressions >= 4.0.10-*"

0 commit comments

Comments
 (0)