public void CreateId_Initially_ShouldReturnExpectedResult() { var generator = new IncrementalIdGenerator(); var id = generator.CreateId(); Assert.Equal(1L, id); }
public void CreateId_InParallel_ShouldReturnDistinctResults() { var generator = new IncrementalIdGenerator(); var results = new ConcurrentQueue <long>(); Parallel.For(0, 100, _ => results.Enqueue(generator.CreateId())); Assert.Equal(results.Count, results.Distinct().Count()); }
public void CreateId_Repeatedly_ShouldReturnExpectedResults() { var generator = new IncrementalIdGenerator(); var results = new List <long>(); for (var i = 0; i < 100; i++) { results.Add(generator.CreateId()); } for (var i = 0; i < results.Count; i++) { Assert.Equal(1L + i, results[i]); } }