コード例 #1
0
 public void GetCharCounts_ShouldReturnDoubledValues_WhenSameFileAddedSecondTime()
 {
     var counter = new MultiFileCharacterCounter();
     counter.Add(EmbeddedFiles.Large);
     var firstResults = counter.GetCharCounts();
     counter.Add(EmbeddedFiles.Large);
     Assert.That(counter.GetCharCounts().All(secondResult => IsDoubled(secondResult, firstResults)));
 }
コード例 #2
0
 public void GetCharCounts_ShouldReturnValue_WhenCalledWhileAddsAreOccurringOnOtherThreads()
 {
     const int NumAdds = 1000, NumGets = 10000;
     var counter = new MultiFileCharacterCounter();
     Task[] addTasks = Enumerable.Range(0, NumAdds).Select(i => Task.Factory.StartNew(() => counter.Add(EmbeddedFiles.Medium))).ToArray();
     var results = Enumerable.Range(0, NumGets).Select(i => counter.GetCharCounts()).ToList();
     Assert.That(results.All(d => d != null));
     Task.WaitAll(addTasks);
 }