public void TestModuleCollectionBehavior()
        {
            ProcessModule[] mArray = Process.GetCurrentProcess().Modules.Cast <ProcessModule>().ToArray();

            // Constructor
            ProcessModuleCollection moduleCollection = new ProcessModuleCollection(mArray);

            // Count
            Assert.Equal(mArray.Count(), moduleCollection.Count);

            // get_item, Contains, IndexOf
            for (int i = 0; i < mArray.Count(); i++)
            {
                Assert.Equal(mArray[i], moduleCollection[i]);
                Assert.True(moduleCollection.Contains(mArray[i]));
                Assert.Equal(i, moduleCollection.IndexOf(mArray[i]));
            }

            // CopyTo
            ProcessModule[] moduleArray = new ProcessModule[moduleCollection.Count + 1];
            moduleCollection.CopyTo(moduleArray, 1);
            for (int i = 0; i < mArray.Count(); i++)
            {
                Assert.Equal(mArray[i], moduleArray[i + 1]);
            }

            Assert.Throws <ArgumentOutOfRangeException>(() => moduleCollection.CopyTo(moduleArray, -1));

            // Explicit interface implementations
            Assert.False(((ICollection)moduleCollection).IsSynchronized);
            Assert.NotNull(((ICollection)moduleCollection).SyncRoot);

            moduleArray = new ProcessModule[moduleCollection.Count];
            ((ICollection)moduleCollection).CopyTo(moduleArray, 0);
            Assert.Equal(moduleCollection.Cast <ProcessModule>().ToArray(), moduleArray);

            // GetEnumerator
            IEnumerator enumerator = moduleCollection.GetEnumerator();

            Assert.Throws <InvalidOperationException>(() => enumerator.Current);

            for (int i = 0; i < moduleCollection.Count; i++)
            {
                enumerator.MoveNext();
                Assert.Equal(moduleCollection[i], enumerator.Current);
            }
        }
        public void TestModuleCollectionBehavior()
        {
            ProcessModule[] mArray = Process.GetCurrentProcess().Modules.Cast<ProcessModule>().ToArray();

            // Constructor
            ProcessModuleCollection moduleCollection = new ProcessModuleCollection(mArray);

            // Count
            Assert.Equal(mArray.Count(), moduleCollection.Count);

            // get_item, Contains, IndexOf
            for (int i = 0; i < mArray.Count(); i++)
            {
                Assert.Equal(mArray[i], moduleCollection[i]);
                Assert.True(moduleCollection.Contains(mArray[i]));
                Assert.Equal(i, moduleCollection.IndexOf(mArray[i]));
            }

            // CopyTo
            ProcessModule[] moduleArray = new ProcessModule[moduleCollection.Count + 1];
            moduleCollection.CopyTo(moduleArray, 1);
            for (int i = 0; i < mArray.Count(); i++)
            {
                Assert.Equal(mArray[i], moduleArray[i + 1]);
            }

            Assert.Throws<ArgumentOutOfRangeException>(() => moduleCollection.CopyTo(moduleArray, -1));

            // Explicit interface implementations
            Assert.False(((ICollection)moduleCollection).IsSynchronized);
            Assert.NotNull(((ICollection)moduleCollection).SyncRoot);

            moduleArray = new ProcessModule[moduleCollection.Count];
            ((ICollection)moduleCollection).CopyTo(moduleArray, 0);
            Assert.Equal(moduleCollection.Cast<ProcessModule>().ToArray(), moduleArray);

            // GetEnumerator
            IEnumerator enumerator = moduleCollection.GetEnumerator();
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);

            for (int i = 0; i < moduleCollection.Count; i++)
            {
                enumerator.MoveNext();
                Assert.Equal(moduleCollection[i], enumerator.Current);
            }
        }
Beispiel #3
0
        public static ProcessModule[] ToArray(this ProcessModuleCollection mList)
        {
            var collection = new ProcessModule[mList.Count];

            mList.CopyTo(collection, 0);

            return(collection);
        }