Exemplo n.º 1
0
        public void When_Cache_Is_Accessed_From_Multiple_Threads_It_Only_Initialized_Once()
        {
            var tasks = new List <Task>();

            for (int i = 0; i < 1000; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => {
                    var repository = new CachedPersonRepository(personCache);
                    //System.Diagnostics.Trace.WriteLine(repository.CountPersons);
                }));
            }

            Task.WaitAll(tasks.ToArray());
            Assert.AreEqual(CachedPersonRepository.CountOfWarmUps, 1);
        }
 public void Setup()
 {
     repo = new CachedPersonRepository(new PersonRepository());
 }