OSDN Git Service

#30244 Visual Studioの自動テストはテストクラスがinternalだと実行されていなかったので修正,
[wptscs/wpts.git] / WptscsTest / Websites / WebsiteTest.cs
1 // ================================================================================================
2 // <summary>
3 //      Websiteのテストクラスソース。</summary>
4 //
5 // <copyright file="WebsiteTest.cs" company="honeplusのメモ帳">
6 //      Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
7 // <author>
8 //      Honeplus</author>
9 // ================================================================================================
10
11 namespace Honememo.Wptscs.Websites
12 {
13     using System;
14     using Honememo.Wptscs.Models;
15     using Honememo.Wptscs.Utilities;
16     using Microsoft.VisualStudio.TestTools.UnitTesting;
17
18     /// <summary>
19     /// <see cref="Website"/>のテストクラスです。
20     /// </summary>
21     [TestClass]
22     public class WebsiteTest
23     {
24         #region プロパティテストケース
25
26         /// <summary>
27         /// <see cref="Website.Location"/>プロパティテストケース。
28         /// </summary>
29         [TestMethod]
30         public void TestLocation()
31         {
32             DummySite site = new DummySite();
33             site.Location = "test";
34             Assert.AreEqual("test", site.Location);
35         }
36
37         /// <summary>
38         /// <see cref="Website.Location"/>プロパティテストケース(null)。
39         /// </summary>
40         [TestMethod]
41         [ExpectedException(typeof(ArgumentNullException))]
42         public void TestLocationNull()
43         {
44             new DummySite().Location = null;
45         }
46
47         /// <summary>
48         /// <see cref="Website.Location"/>プロパティテストケース(空)。
49         /// </summary>
50         [TestMethod]
51         [ExpectedException(typeof(ArgumentException))]
52         public void TestLocationBlank()
53         {
54             new DummySite().Location = " ";
55         }
56
57         /// <summary>
58         /// <see cref="Website.Language"/>プロパティテストケース。
59         /// </summary>
60         [TestMethod]
61         public void TestLanguage()
62         {
63             DummySite site = new DummySite();
64             site.Language = new Language("ja");
65             Assert.AreEqual("ja", site.Language.Code);
66         }
67
68         /// <summary>
69         /// <see cref="Website.Language"/>プロパティテストケース(null)。
70         /// </summary>
71         [TestMethod]
72         [ExpectedException(typeof(ArgumentNullException))]
73         public void TestLanguageNull()
74         {
75             new DummySite().Language = null;
76         }
77
78         /// <summary>
79         /// <see cref="Website.WebProxy"/>プロパティテストケース。
80         /// </summary>
81         [TestMethod]
82         public void TestWebProxy()
83         {
84             DummySite site = new DummySite();
85
86             // デフォルトでオブジェクトが格納されている
87             Assert.IsNotNull(site.WebProxy);
88
89             // 値を設定するとそのオブジェクトが返る
90             IWebProxy proxy = new AppConfigWebProxy();
91             site.WebProxy = proxy;
92             Assert.AreSame(proxy, site.WebProxy);
93         }
94
95         /// <summary>
96         /// <see cref="Website.WebProxy"/>プロパティテストケース(null)。
97         /// </summary>
98         [TestMethod]
99         [ExpectedException(typeof(ArgumentNullException))]
100         public void TestWebProxyNull()
101         {
102             new DummySite().WebProxy = null;
103         }
104
105         #endregion
106
107         #region モッククラス
108
109         /// <summary>
110         /// <see cref="Website"/>テスト用のモッククラスです。
111         /// </summary>
112         private class DummySite : Website
113         {
114             #region 非公開プロパティテスト用のオーラーライドプロパティ
115             
116             /// <summary>
117             /// ウェブサイトの言語。
118             /// </summary>
119             public new Language Language
120             {
121                 get
122                 {
123                     return base.Language;
124                 }
125
126                 set
127                 {
128                     base.Language = value;
129                 }
130             }
131
132             #endregion
133
134             #region ダミーメソッド
135
136             /// <summary>
137             /// ページを取得。空実装。
138             /// </summary>
139             /// <param name="title">ページタイトル。</param>
140             /// <returns><c>null</c>。</returns>
141             public override Page GetPage(string title)
142             {
143                 return null;
144             }
145
146             #endregion
147         }
148
149         #endregion
150     }
151 }