Exemple #1
0
 public void Clear() => _clear.Invoke();
 public void Start() => _start.Invoke();
 public void Stop() => _close.Invoke();
 public void VoidVoid() => _voidVoid.Invoke();
Exemple #5
0
 public void ToTop() => _toTop.Invoke();
Exemple #6
0
 public void Disable() => _disable.Invoke();
Exemple #7
0
 public void Enable() => _enable.Invoke();
        /// <summary>
        /// Mocks the specified collection, optionally prepopulating it with the specified number of entries.
        /// </summary>
        /// <typeparam name="T">A T that is the collection to mock.</typeparam>
        /// <param name="prepopulateSize">An int that indicates the number of entries to prepopulate.</param>
        /// <returns>A T that was the created type instance.</returns>
        public static T MockCollection <T>(int prepopulateSize = 0)
        {
            Type MyType;
            T    ReturnValue;

            MyType = typeof(T);
            if (MyType.GetInterface("ICollection") == null &&
                MyType.GetInterface("ICollection`1") == null)
            {
                throw new ArgumentException("The specified type does not implement ICollection", "T");
            }

            ReturnValue = Activator.CreateInstance <T>();

            // Prepopulate values?
            if (prepopulateSize > 0)
            {
                Type GenericType = null;

                if (MyType.IsGenericType)
                {
                    GenericType = MyType;
                }
                else if (MyType.BaseType != null && MyType.BaseType.IsGenericType)
                {
                    GenericType = MyType.BaseType;
                }

                // Check for generic-based collections
                if (GenericType != null)
                {
                    if (GenericType.GenericTypeArguments != null && GenericType.GenericTypeArguments.Length == 1)
                    {
                        MethodInfo MockMethod;

                        MockMethod = typeof(TestDataTestHelper).GetMethod("MockType", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                        if (MockMethod != null)
                        {
                            MockMethod = MockMethod.MakeGenericMethod(GenericType.GenericTypeArguments[0]);
                            if (MockMethod != null)
                            {
                                MethodInfo AddMethod;

                                AddMethod = MyType.GetMethod("Add");
                                for (int i = 0; i < prepopulateSize; i++)
                                {
                                    object NewItem;

                                    NewItem = MockMethod.Invoke(null, new object[] { null });
                                    AddMethod.Invoke(ReturnValue, new object[] { NewItem });
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Unable to mock generic collections with more than one generic type", "T");
                    }
                }
                else
                {
                    // Non generic-collection
                    throw new ArgumentException("Currently unable to mock non-generic collections", "T");
                }
            }

            return(ReturnValue);
        }
 public void Release() => _release.Invoke();
 public void WaitSync() => _waitSync.Invoke();