Added RedirectUsingNamedRoute
[castle.git] / InversionOfControl / Castle.Windsor.Tests / XmlProcessor / XmlProcessorTestCase.cs
blobf49451a3e2249fd0fcfb19880383973544d93441
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Windsor.Tests.XmlProcessor
17 using System;
18 using System.Diagnostics;
19 using System.IO;
20 using System.Text.RegularExpressions;
21 using System.Xml;
22 using Castle.Windsor.Configuration.Interpreters.XmlProcessor;
23 using NUnit.Framework;
25 /// <summary>
26 /// Summary description for Class1.
27 /// </summary>
28 [TestFixture]
29 public class XmlProcessorTestCase
31 private String dir = ConfigHelper.ResolveConfigPath("XmlProcessor/TestFiles/");
33 [Test]
34 public void InvalidFiles()
36 String dirFullPath = GetFullPath();
38 foreach(String fileName in Directory.GetFiles(dirFullPath, "Invalid*.xml"))
40 try
42 XmlDocument doc = GetXmlDocument(fileName);
43 XmlProcessor processor = new XmlProcessor();
45 XmlNode result = processor.Process(doc.DocumentElement);
47 Assert.Fail(fileName + " should throw an exception");
49 catch(ConfigurationProcessingException e)
51 Debug.WriteLine("Expected exception:" + e.Message);
56 /// <summary>
57 /// Runs the tests.
58 /// </summary>
59 [Test]
60 public void RunTests()
62 String dirFullPath = GetFullPath();
64 foreach(String fileName in Directory.GetFiles(dirFullPath, "*Test.xml"))
66 // Debug.WriteLine("Running " + fileName.Substring( fileName.LastIndexOf("/") + 1 ));
68 if (fileName.EndsWith("PropertiesWithAttributesTest.xml"))
70 continue;
73 XmlDocument doc = GetXmlDocument(fileName);
75 String resultFileName = fileName.Substring(0, fileName.Length - 4) + "Result.xml";
77 XmlDocument resultDoc = GetXmlDocument(resultFileName);
79 XmlProcessor processor = new XmlProcessor();
81 try
83 XmlNode result = processor.Process(doc.DocumentElement);
85 String resultDocStr = StripSpaces(resultDoc.OuterXml);
86 String resultStr = StripSpaces(result.OuterXml);
88 // Debug.WriteLine(resultDocStr);
89 // Debug.WriteLine(resultStr);
91 Assert.AreEqual(resultDocStr, resultStr);
93 catch(Exception e)
95 throw new Exception("Error processing " + fileName, e);
100 #region Helpers
102 public XmlDocument GetXmlDocument(string fileName)
104 XmlDocument doc = new XmlDocument();
106 doc.Load(fileName);
108 return doc;
111 private string StripSpaces(String xml)
113 return Regex.Replace(xml, "\\s+", "", RegexOptions.Compiled);
116 private string GetFullPath()
118 return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir);
121 #endregion