using System.Collections.Generic; using System.Reflection; using NUnit.Framework; namespace Chernobyl.Attribution { /// /// Tests for /// which process attribute providers. /// /// The type of the attribute provider. /// The type of the child attribute provider. public abstract class ProcessAttributesTests where TAttributeProvider : ICustomAttributeProvider where TChildAttributeProvider : ICustomAttributeProvider { [Test, Description("Ensures the IProcessAttribute " + "processes the sub IProcessAttribute instances.")] public virtual void ProcessChildProcessors() { Test test = CreateTest(); test.ProcessAttributes.Process(test.Provider); Assert.AreEqual(test.ExpectedItemsProcessed.Count, test.ItemsProcessed.Count, "Unexpected number of types processed."); foreach (TChildAttributeProvider provider in test.ExpectedItemsProcessed) { Assert.IsTrue(test.ItemsProcessed.Remove(provider), "The ICustomAttributeProvider \"" + provider + "\" was not processed though processing of it was " + "expected."); } } protected abstract Test CreateTest(); public class Test { /// /// Initializes a new instance of the class. /// /// The instance that is to be tested. /// The instance where /// was found and that should be processed by . /// The items that are the result /// of the processing by . /// The items that are the result of /// the processing by . public Test(IProcessAttribute processAttributes, TAttributeProvider provider, ICollection expectedItemsProcessed, ICollection itemsProcessed) { ProcessAttributes = processAttributes; Provider = provider; ExpectedItemsProcessed = expectedItemsProcessed; ItemsProcessed = itemsProcessed; } /// /// The instance that is to be tested. /// public IProcessAttribute ProcessAttributes { get; private set; } /// /// The instance where was found and /// that should be processed by . /// public TAttributeProvider Provider { get; private set; } /// /// The items that are the result of the processing by /// . /// public ICollection ExpectedItemsProcessed { get; private set; } /// /// The items that are the result of the processing by /// . /// public ICollection ItemsProcessed { get; private set; } } } }