private List <AppMetric> MergeAppMetrics(AppMetricsCollection[] collections)
        {
            List <AppMetric> metrics =
                new List <AppMetric>();

            foreach (AppMetricsCollection col in collections)
            {
                foreach (AppMetric metric in col.CollectMetrics())
                {
                    AppMetric existingMetric = metrics.FirstOrDefault(m
                                                                      => m.Id.Equals(metric.Id));

                    if (existingMetric != null)
                    {
                        existingMetric.Add(metric.Value);
                    }
                    else
                    {
                        metrics.Add(metric.Copy());
                    }
                }
            }

            return(metrics);
        }
        public void Test_CanAdd_Parallel(int nThreads)
        {
            Faker faker = new Faker();

            Thread[] threads    = new Thread[nThreads];
            long     valueToAdd = faker.Random.Long(1, 10);

            AppMetric metric = new AppMetric(faker.PickRandom(AppMetricId.BuiltInAppMetricIds),
                                             0);

            for (int i = 0; i < nThreads; i++)
            {
                Thread addThread = new Thread(() => metric.Add(valueToAdd));
                threads[i] = addThread;
                addThread.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            Assert.AreEqual(nThreads * valueToAdd, metric.Value);
        }