1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Diagnostics
;
20 using System
.Text
.RegularExpressions
;
22 using Castle
.Windsor
.Configuration
.Interpreters
.XmlProcessor
;
23 using NUnit
.Framework
;
26 /// Summary description for Class1.
29 public class XmlProcessorTestCase
31 private String dir
= ConfigHelper
.ResolveConfigPath("XmlProcessor/TestFiles/");
34 public void InvalidFiles()
36 String dirFullPath
= GetFullPath();
38 foreach(String fileName
in Directory
.GetFiles(dirFullPath
, "Invalid*.xml"))
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
);
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"))
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();
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
);
95 throw new Exception("Error processing " + fileName
, e
);
102 public XmlDocument
GetXmlDocument(string fileName
)
104 XmlDocument doc
= new XmlDocument();
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
);