Example #1
0
        public void DoInsert_Should_throw_ArgumentNullException_When_source_is_null()
        {
            IUnDoManager   manager = Substitute.For <IUnDoManager>();
            IList <object> source  = null;

            Check
            .ThatCode(() => manager.DoInsert(source, 0, null))
            .Throws <ArgumentNullException>()
            .WithProperty("ParamName", "source");
        }
Example #2
0
        /// <summary>
        /// Adds a value to a <see cref="ICollection{T}"/> as a <see cref="IUnDo"/> operation.
        /// </summary>
        /// <typeparam name="T">The type of element in the <see cref="ICollection{T}"/>.</typeparam>
        /// <param name="manager">The <see cref="IUnDoManager"/>.</param>
        /// <param name="source">The <see cref="ICollection{T}"/>.</param>
        /// <param name="item">The item to add.</param>
        /// <param name="description">The description of the operation.</param>
        /// <exception cref="ArgumentNullException"><paramref name="manager"/> or <paramref name="source"/> is null.</exception>
        public static void DoAdd <T>(this IUnDoManager manager, ICollection <T> source, T item, object description = null)
        {
            if (manager is null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (source is IList <T> list)
            {
                manager.DoInsert(list, list.Count, item, description);
            }
            else
            {
                manager.Do(new CollectionUnDo <T>(description, source, item, true));
            }
        }