How to use XmlConfigurationDeserializer class of Telerik.JustMock.Core.Castle.Core.Configuration.Xml package

Best JustMockLite code snippet using Telerik.JustMock.Core.Castle.Core.Configuration.Xml.XmlConfigurationDeserializer

Run JustMockLite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

XmlConfigurationDeserializer.cs

Source: XmlConfigurationDeserializer.cs Github

copy
1// Copyright 2004-2011 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.
14
15namespace Telerik.JustMock.Core.Castle.Core.Configuration.Xml
16{
17	using System.Text;
18	using System.Xml;
19
20	internal class XmlConfigurationDeserializer
21	{
22		/// <summary>
23		///   Deserializes the specified node into an abstract representation of configuration.
24		/// </summary>
25		/// <param name = "node">The node.</param>
26		/// <returns></returns>
27		public IConfiguration Deserialize(XmlNode node)
28		{
29			return GetDeserializedNode(node);
30		}
31
32		/// <summary>
33		///   If a config value is an empty string we return null, this is to keep
34		///   backward compatibility with old code
35		/// </summary>
36		public static string GetConfigValue(string value)
37		{
38			if (value == string.Empty)
39			{
40				return null;
41			}
42			return value;
43		}
44
45		public static IConfiguration GetDeserializedNode(XmlNode node)
46		{
47			var configChilds = new ConfigurationCollection();
48
49			var configValue = new StringBuilder();
50			if (node.HasChildNodes)
51			{
52				foreach (XmlNode child in node.ChildNodes)
53				{
54					if (IsTextNode(child))
55					{
56						configValue.Append(child.Value);
57					}
58					else if (child.NodeType == XmlNodeType.Element)
59					{
60						configChilds.Add(GetDeserializedNode(child));
61					}
62				}
63			}
64
65			var config = new MutableConfiguration(node.Name, GetConfigValue(configValue.ToString()));
66			foreach (XmlAttribute attribute in node.Attributes)
67			{
68				config.Attributes.Add(attribute.Name, attribute.Value);
69			}
70
71			config.Children.AddRange(configChilds);
72
73			return config;
74		}
75
76		public static bool IsTextNode(XmlNode node)
77		{
78			return node.NodeType == XmlNodeType.Text || node.NodeType == XmlNodeType.CDATA;
79		}
80	}
81}
82
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in XmlConfigurationDeserializer

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)