using System; using System.Collections.Generic; using Chernobyl.Collections.Generic.Event; using NUnit.Framework; // ReSharper disable ObjectCreationAsStatement namespace Chernobyl.Collections.Generic.Hierarchy { [TestFixture, Description("Tests for the Children type and its subtypes.")] public class ChildrenTests : CollectionTests { public ChildrenTests() : base(false) {} //------------------------------------------------------------------ // Children(TParent, Func>) Tests //------------------------------------------------------------------ [Test, Description("Ensures the Children(TParent, Func>) " + "constructor throws an ArgumentNullException when the first argument is null.")] public void ConstructorTParentFuncFirstArgumentNullException() { Assert.Throws( () => new Children(null, hierarchy => hierarchy.Parent)); } [Test, Description("Ensures the Children(TParent, Func>) " + "constructor throws an ArgumentNullException when the second argument is null.")] public void ConstructorTParentFuncSecondArgumentNullException() { var parent = new ParentTests.Hierarchy(); Assert.Throws(() => new Children(parent, null)); } //------------------------------------------------------------------ // Children(TParent, Func>, IEventCollection) Tests //------------------------------------------------------------------ [Test, Description("Ensures the Children(TParent, Func>, IEventCollection) " + "constructor throws an ArgumentNullException when the first argument is null.")] public void ConstructorTParentFuncEventCollectionFirstArgumentNullException() { Assert.Throws(() => new Children(null, hierarchy => hierarchy.Parent)); } [Test, Description("Ensures the Children(TParent, Func>, IEventCollection) " + "constructor throws an ArgumentNullException when the second argument is null.")] public void ConstructorTParentFuncEventCollectionSecondArgumentNullException() { var parent = new ParentTests.Hierarchy(); Assert.Throws(() => new Children(parent, null)); } [Test, Description("Ensures the Children(TParent, Func>, IEventCollection) " + "constructor throws an ArgumentNullException when the third argument is null.")] public void ConstructorTParentFuncEventCollectionThirdArgumentNullException() { var parent = new ParentTests.Hierarchy(); Assert.Throws(() => new Children(parent, hierarchy => hierarchy.Parent, null)); } [Test, Description("Ensures the Children(TParent, Func>, IEventCollection) " + "constructor throws an ArgumentException when the third argument contains items.")] public void ConstructorTParentFuncEventCollectionThirdArgumentHasItemsException() { DecoratingEventList implementation = new DecoratingEventList(); implementation.Add(new ParentTests.Hierarchy()); var parent = new ParentTests.Hierarchy(); Assert.Throws(() => new Children(parent, hierarchy => hierarchy.Parent, implementation)); } //------------------------------------------------------------------ // Utility //------------------------------------------------------------------ protected override ICollection CreateCollection() { ParentTests.Hierarchy first = new ParentTests.Hierarchy(); first.Children.AddRange(new[] { new ParentTests.Hierarchy(), new ParentTests.Hierarchy(), new ParentTests.Hierarchy(), new ParentTests.Hierarchy(), new ParentTests.Hierarchy(), new ParentTests.Hierarchy(), new ParentTests.Hierarchy() }); return first.Children; } protected override ICollection CreateReadOnlyCollection() { // Read only Children not supported. return null; } protected override ParentTests.Hierarchy CreateItem() { return new ParentTests.Hierarchy(); } } }