📄 schemaincludetestfixturehelper.cs
字号:
//
// SharpDevelop Xml Editor
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Matthew Ward (mrward@users.sourceforge.net)
using ICSharpCode.XmlEditor;
using System;
using System.IO;
using System.Text;
using System.Xml;
namespace XmlEditor.Tests.Utils
{
/// <summary>
/// Helper class when testing a schema which includes
/// another schema.
/// </summary>
public class SchemaIncludeTestFixtureHelper
{
static string mainSchemaFileName = "main.xsd";
static string includedSchemaFileName = "include.xsd";
static readonly string schemaPath;
SchemaIncludeTestFixtureHelper()
{
}
static SchemaIncludeTestFixtureHelper()
{
schemaPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "XmlEditorTests");
}
/// <summary>
/// Creates a schema with the given filename
/// </summary>
/// <param name="fileName">Filename of the schema that will be
/// generated.</param>
/// <param name="xml">The schema xml</param>
public static void CreateSchema(string fileName, string xml)
{
XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8);
writer.WriteRaw(xml);
writer.Close();
}
/// <summary>
/// Creates two schemas, one which references the other via an
/// xs:include. Both schemas will exist in the same folder.
/// </summary>
/// <param name="mainSchema">The main schema's xml.</param>
/// <param name="includedSchema">The included schema's xml.</param>
public static XmlSchemaCompletionData CreateSchemaCompletionDataObject(string mainSchema, string includedSchema)
{
if (!Directory.Exists(schemaPath)) {
Directory.CreateDirectory(schemaPath);
}
CreateSchema(Path.Combine(schemaPath, mainSchemaFileName), mainSchema);
CreateSchema(Path.Combine(schemaPath, includedSchemaFileName), includedSchema);
// Parse schema.
string schemaFileName = Path.Combine(schemaPath, mainSchemaFileName);
string baseUri = XmlSchemaCompletionData.GetUri(schemaFileName);
return new XmlSchemaCompletionData(baseUri, schemaFileName);
}
/// <summary>
/// Removes any files generated for the test fixture.
/// </summary>
public static void FixtureTearDown()
{
// Delete the created schemas.
string fileName = Path.Combine(schemaPath, mainSchemaFileName);
if (File.Exists(fileName)) {
File.Delete(fileName);
}
fileName = Path.Combine(schemaPath, includedSchemaFileName);
if (File.Exists(fileName)) {
File.Delete(fileName);
}
if (Directory.Exists(schemaPath)) {
Directory.Delete(schemaPath);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -