1 // ================================================================================================
3 // XmlParserのテストクラスソース。</summary>
5 // <copyright file="XmlParserTest.cs" company="honeplusのメモ帳">
6 // Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
9 // ================================================================================================
11 namespace Honememo.Parsers
14 using System.Collections.Generic;
16 using Microsoft.VisualStudio.TestTools.UnitTesting;
19 /// <see cref="XmlParser"/>のテストクラスです。
22 internal class XmlParserTest
27 /// <see cref="XmlParser.Parsers"/>プロパティテストケース。
30 public void TestParsers()
32 using (XmlParser parser = new XmlParser())
35 Assert.IsNotNull(parser.Parsers);
36 Assert.AreEqual(2, parser.Parsers.Length);
39 IParser[] parsers = new IParser[0];
40 parser.Parsers = parsers;
41 Assert.AreSame(parsers, parser.Parsers);
46 /// <see cref="XmlParser.Parsers"/>プロパティテストケース(null)。
49 [ExpectedException(typeof(ArgumentNullException))]
50 public void TestParsersNull()
52 using (XmlParser parser = new XmlParser())
54 parser.Parsers = null;
59 /// <see cref="XmlParser.IgnoreCase"/>プロパティテストケース。
62 public void TestIgnoreCase()
64 using (XmlParser parser = new XmlParser())
66 // 初期値はtrue、値を設定すればその値に変わる
67 Assert.IsTrue(parser.IgnoreCase);
68 parser.IgnoreCase = false;
69 Assert.IsFalse(parser.IgnoreCase);
70 parser.IgnoreCase = true;
71 Assert.IsTrue(parser.IgnoreCase);
76 /// <see cref="XmlParser.IsHtml"/>プロパティテストケース。
79 public void TestIsHtml()
81 using (XmlParser parser = new XmlParser())
83 // 初期値はfalse、値を設定すればその値に変わる
84 Assert.IsFalse(parser.IsHtml);
86 Assert.IsTrue(parser.IsHtml);
87 parser.IsHtml = false;
88 Assert.IsFalse(parser.IsHtml);
94 #region IParserインタフェースメソッドテストケース
96 // ※ 2012年2月現在、IParser, ITextParserの各メソッド実装は抽象クラス側で共通になっており、
97 // 改造部分はどこかでやればテストされるのでそれで割愛
100 /// <see cref="IParser.Parse"/>メソッドテストケース。
103 public void TestParse()
105 using (XmlParser parser = new XmlParser())
107 Assert.AreEqual("test", parser.Parse("test").ToString());
109 IElement element = parser.Parse("testbefore<p>testinner</p><!--comment-->testafter");
110 Assert.IsInstanceOfType(element, typeof(ICollection<IElement>));
111 ICollection<IElement> collection = (ICollection<IElement>)element;
112 Assert.AreEqual(4, collection.Count);
113 Assert.AreEqual("testbefore", collection.ElementAt(0).ToString());
114 Assert.IsInstanceOfType(collection.ElementAt(1), typeof(XmlElement));
115 Assert.AreEqual("<p>testinner</p>", collection.ElementAt(1).ToString());
116 Assert.IsInstanceOfType(collection.ElementAt(2), typeof(XmlCommentElement));
117 Assert.AreEqual("<!--comment-->", collection.ElementAt(2).ToString());
118 Assert.AreEqual("testafter", collection.ElementAt(3).ToString());
123 /// <see cref="IParser.Parse"/>メソッドテストケース(null)。
126 [ExpectedException(typeof(ArgumentNullException))]
127 public void TestParseNull()
129 using (XmlParser parser = new XmlParser())
136 /// <see cref="IParser.Parse"/>メソッドテストケース(Dispose)。
139 [ExpectedException(typeof(ObjectDisposedException))]
140 public void TestParseDispose()
142 XmlParser parser = new XmlParser();
145 parser.TryParse("test", out result);
150 #region IDisposableインタフェース実装メソッドテストケース
153 /// <see cref="XmlParser.Dispose"/>メソッドテストケース。
156 public void TestDispose()
158 // 循環参照のあるParsersを解放する
159 XmlParser parser = new XmlParser();
160 Assert.IsNotNull(parser.Parsers);
162 Assert.IsNull(parser.Parsers);