~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.XmlEditor/Tests/Utils/SchemaIncludeTestFixtureHelper.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using MonoDevelop.XmlEditor;
 
3
using System;
 
4
using System.IO;
 
5
using System.Text;
 
6
using System.Xml;
 
7
 
 
8
namespace MonoDevelop.XmlEditor.Tests.Utils
 
9
{
 
10
        /// <summary>
 
11
        /// Helper class when testing a schema which includes 
 
12
        /// another schema.
 
13
        /// </summary>
 
14
        public class SchemaIncludeTestFixtureHelper
 
15
        {
 
16
                static string mainSchemaFileName = "main.xsd";
 
17
                static string includedSchemaFileName = "include.xsd";
 
18
                static readonly string schemaPath;
 
19
 
 
20
                SchemaIncludeTestFixtureHelper()
 
21
                {
 
22
                }
 
23
                
 
24
                static SchemaIncludeTestFixtureHelper()
 
25
                {
 
26
                        schemaPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "XmlEditorTests");
 
27
                }
 
28
                
 
29
                /// <summary>
 
30
                /// Creates a schema with the given filename
 
31
                /// </summary>
 
32
                /// <param name="fileName">Filename of the schema that will be 
 
33
                /// generated.</param>
 
34
                /// <param name="xml">The schema xml</param>
 
35
                public static void CreateSchema(string fileName, string xml)
 
36
                {
 
37
                        XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8);
 
38
                        writer.WriteRaw(xml);
 
39
                        writer.Close();
 
40
                }
 
41
                
 
42
                /// <summary>
 
43
                /// Creates two schemas, one which references the other via an
 
44
                /// xs:include.  Both schemas will exist in the same folder.
 
45
                /// </summary>
 
46
                /// <param name="mainSchema">The main schema's xml.</param>
 
47
                /// <param name="includedSchema">The included schema's xml.</param>
 
48
                public static XmlSchemaCompletionData CreateSchemaCompletionDataObject(string mainSchema, string includedSchema)
 
49
                {       
 
50
                        if (!Directory.Exists(schemaPath)) {
 
51
                                Directory.CreateDirectory(schemaPath);
 
52
                        }
 
53
                        
 
54
                        CreateSchema(Path.Combine(schemaPath, mainSchemaFileName), mainSchema);
 
55
                        CreateSchema(Path.Combine(schemaPath, includedSchemaFileName), includedSchema);
 
56
                        
 
57
                        // Parse schema.
 
58
                        string schemaFileName = Path.Combine(schemaPath, mainSchemaFileName);
 
59
                        string baseUri = XmlSchemaCompletionData.GetUri(schemaFileName);
 
60
                        return new XmlSchemaCompletionData(baseUri, schemaFileName);
 
61
                }
 
62
                
 
63
                /// <summary>
 
64
                /// Removes any files generated for the test fixture.
 
65
                /// </summary>
 
66
                public static void FixtureTearDown()
 
67
                {
 
68
                        // Delete the created schemas.
 
69
                        string fileName = Path.Combine(schemaPath, mainSchemaFileName);
 
70
                        if (File.Exists(fileName)) {
 
71
                                File.Delete(fileName);
 
72
                        }
 
73
                        
 
74
                        fileName = Path.Combine(schemaPath, includedSchemaFileName);
 
75
                        if (File.Exists(fileName)) {
 
76
                                File.Delete(fileName);
 
77
                        }
 
78
                        
 
79
                        if (Directory.Exists(schemaPath)) {
 
80
                                Directory.Delete(schemaPath);
 
81
                        }
 
82
                }
 
83
        }
 
84
}