-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomizerFactory.cs
More file actions
37 lines (36 loc) · 1.2 KB
/
Copy pathRandomizerFactory.cs
File metadata and controls
37 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Generator
{
//This whole file is a hack to make the generator testable. I would like to use DI. DI has issues with
//Azure functions. I have seen the service locatior pattern recommeded as a workaround. This class is a kind of
//mini service locator for just one interface. In the normal course of events, the first time we ask for a
//random number generator, we'll make one and hand it back to the user.
//
//In a unit test, before we call Generate(), we will sneak a NON-RANDOM randomizer into the Random property
//so that we can get consistent results from a unit test. I don't really like this but it will make the code
//testable.
//
public static class RandomizerFactory
{
static IRandomize _rand = null;
public static IRandomize Random
{
get
{
if (_rand == null)
{
_rand = new Randomizer();
}
return _rand;
}
set
{
_rand = value;
}
}
}
}