using ICSharpCode.NRefactory.Completion; using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.Xml.Completion; using NUnit.Framework; using System; using System.IO; namespace MonoDevelop.Xml.Tests.Schema { [TestFixture] public abstract class SchemaTestFixtureBase { XmlSchemaCompletionData schemaCompletionData; /// /// Gets the object generated /// by this class. /// /// This object will be null until the /// has been run. public XmlSchemaCompletionData SchemaCompletionData { get { return schemaCompletionData; } } /// /// Creates the object from /// the derived class's schema. /// /// Calls at the end of the method. /// [TestFixtureSetUp] public void FixtureInitBase() { schemaCompletionData = CreateSchemaCompletionDataObject(); FixtureInit(); } /// /// Method overridden by derived class so it can execute its own /// fixture initialisation. /// public virtual void FixtureInit() { } /// /// Checks whether the specified name exists in the completion data. /// public static bool Contains(CompletionDataList items, string name) { bool Contains = false; foreach (ICompletionData data in items) { if (data.DisplayText == name) { Contains = true; break; } } return Contains; } /// /// Checks whether the completion data specified by name has /// the correct description. /// public static bool ContainsDescription(CompletionDataList items, string name, string description) { bool Contains = false; foreach (ICompletionData data in items) { if (data.DisplayText == name) { if (data.Description == description) { Contains = true; break; } } } return Contains; } /// /// Gets a count of the number of occurrences of a particular name /// in the completion data. /// public static int GetItemCount(CompletionDataList items, string name) { int count = 0; foreach (ICompletionData data in items) { if (data.DisplayText == name) { ++count; } } return count; } /// /// Returns the schema that will be used in this test fixture. /// /// protected virtual string GetSchema() { return String.Empty; } /// /// Creates an object that /// will be used in the test fixture. /// protected virtual XmlSchemaCompletionData CreateSchemaCompletionDataObject() { StringReader reader = new StringReader(GetSchema()); return new XmlSchemaCompletionData(reader); } } }