public static void Cleanup() { var randomizersList = new Dictionary <Type, IRandomizeble>(); randomizersList[typeof(decimal)] = new DecimalRandom(); randomizersList[typeof(string)] = new StringRandom(); randomizersList[typeof(char)] = new CharRandom(); randomizersList[typeof(int)] = new Int32Random(); randomizersList[typeof(long)] = new Int64Random(); randomizersList[typeof(bool)] = new BoolRandom(); randomizersList[typeof(byte)] = new ByteRandom(); randomizersList[typeof(sbyte)] = new SByteRandom(); randomizersList[typeof(float)] = new FloatRandom(); randomizersList[typeof(double)] = new DoubleRandom(); randomizersList[typeof(short)] = new Int16Random(); randomizersList[typeof(uint)] = new UInt32Random(); randomizersList[typeof(ushort)] = new UInt16Random(); randomizersList[typeof(ulong)] = new UInt64Random(); randomizersList[typeof(DateTime)] = new DateTimeRandom(); UniversalRandom.AddRandomizers(randomizersList); UniversalRandom.AddInterceptors(new List <IInterceptor> { new ListInterceptor(), new EnumInterceptor(), new ArrayInterceptor() }); }
public void AddRandomizersTest() { var randomizers = new Dictionary <Type, IRandomizeble> { { typeof(int), new Int32RandomCustom() } }; UniversalRandom.AddRandomizers(randomizers); var item1 = _random.Randomize <int>(); var item2 = _random.Randomize <int>(); Assert.AreEqual(item1, item2); Assert.AreEqual(item1, Int32RandomCustom.FakeRandom); }
public void RandomizersThreadSafe() { var hasExceptions = false; for (int i = 0; i < 5000; i++) { ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.AddRandomizers( new Dictionary <Type, IRandomizeble> { { typeof(int), new Int32Random() } }); } catch (Exception) { hasExceptions = true; } }); ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.RemoveRandomizers(new List <Type> { typeof(int) }); } catch (Exception) { hasExceptions = true; } }); ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.ClearRandomizers(); } catch (Exception) { hasExceptions = true; } }); } Thread.Sleep(2000); Assert.IsFalse(hasExceptions); }