PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Branches/1.2/Source/DotRas/DotRas.IntegrationTests/RasEntryTest.cs

#
C# | 247 lines | 140 code | 58 blank | 49 comment | 3 complexity | b2abb8d53712b0f5c08909e0834e1194 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-2.0
  1. //--------------------------------------------------------------------------
  2. // <copyright file="RasEntryTest.cs" company="Jeff Winn">
  3. // Copyright (c) Jeff Winn. All rights reserved.
  4. //
  5. // The use and distribution terms for this software is covered by the
  6. // GNU Library General Public License (LGPL) v2.1 which can be found
  7. // in the License.rtf at the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by
  9. // the terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. // </copyright>
  13. //--------------------------------------------------------------------------
  14. namespace DotRas.IntegrationTests
  15. {
  16. using System;
  17. using System.Net;
  18. using DotRas.Internal;
  19. using Microsoft.VisualStudio.TestTools.UnitTesting;
  20. /// <summary>
  21. /// This is a test class for <see cref="DotRas.RasEntry"/> and is intended to contain all associated integration tests.
  22. /// </summary>
  23. [TestClass]
  24. public class RasEntryTest : IntegrationTest
  25. {
  26. #region Fields
  27. private string _entryName;
  28. private string _phoneBookPath;
  29. private RasPhoneBook _phoneBook;
  30. private RasEntry _entry;
  31. #endregion
  32. #region Constructors
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="RasEntryTest"/> class.
  35. /// </summary>
  36. public RasEntryTest()
  37. {
  38. }
  39. #endregion
  40. #region Methods
  41. #region ~ Test Methods Init
  42. /// <summary>
  43. /// Initializes the test instance.
  44. /// </summary>
  45. [TestInitialize]
  46. public override void Initialize()
  47. {
  48. base.Initialize();
  49. this._phoneBookPath = System.IO.Path.GetTempFileName();
  50. this._entryName = Guid.NewGuid().ToString();
  51. this._phoneBook = new RasPhoneBook();
  52. this._phoneBook.Open(this._phoneBookPath);
  53. this._entry = new RasEntry(this._entryName);
  54. this._entry.Device = RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn);
  55. this._entry.EncryptionType = RasEncryptionType.Require;
  56. this._entry.EntryType = RasEntryType.Vpn;
  57. this._entry.FramingProtocol = RasFramingProtocol.Ppp;
  58. this._entry.NetworkProtocols.IP = true;
  59. this._entry.NetworkProtocols.IPv6 = true;
  60. this._entry.PhoneNumber = IPAddress.Loopback.ToString();
  61. this._entry.VpnStrategy = RasVpnStrategy.Default;
  62. this._phoneBook.Entries.Add(this._entry);
  63. }
  64. /// <summary>
  65. /// Performs cleanup for the current test instance.
  66. /// </summary>
  67. [TestCleanup]
  68. public void CleanUp()
  69. {
  70. if (this._phoneBook.Entries.Contains(this._entry))
  71. {
  72. this._phoneBook.Entries.Remove(this._entry);
  73. }
  74. this._phoneBook.Dispose();
  75. System.IO.File.Delete(this._phoneBookPath);
  76. }
  77. #endregion
  78. #region ClearCredentials
  79. /// <summary>
  80. /// Tests the ClearCredentials method to ensure the credentials will be cleared as expected.
  81. /// </summary>
  82. [TestMethod]
  83. public void ClearCredentialsTest()
  84. {
  85. bool expected = true;
  86. bool actual = this._entry.ClearCredentials();
  87. Assert.AreEqual(expected, actual);
  88. }
  89. #endregion
  90. #region GetCredentials
  91. /// <summary>
  92. /// Tests the GetCredentials method to ensure the expected credentials are returned.
  93. /// </summary>
  94. [TestMethod]
  95. public void GetCredentialsTest()
  96. {
  97. NetworkCredential expected = null;
  98. NetworkCredential actual = this._entry.GetCredentials();
  99. Assert.AreEqual(expected, actual);
  100. }
  101. #endregion
  102. #region Options
  103. /// <summary>
  104. /// Tests the IPv6RemoteDefaultGateway options property to ensure the expected value is persisting to the phonebook correctly.
  105. /// </summary>
  106. [TestMethod]
  107. public void IPv6RemoteDefaultGatewayAfterReloadTest()
  108. {
  109. bool expected = true;
  110. this._entry.Options.IPv6RemoteDefaultGateway = expected;
  111. this._entry.Update();
  112. this._entry = null;
  113. this._phoneBook.Dispose();
  114. this._phoneBook = null;
  115. this._phoneBook = new RasPhoneBook();
  116. this._phoneBook.Open(this._phoneBookPath);
  117. this._entry = this._phoneBook.Entries[this._entryName];
  118. bool actual = this._entry.Options.IPv6RemoteDefaultGateway;
  119. Assert.AreEqual(expected, actual);
  120. }
  121. #endregion
  122. #region Remove
  123. /// <summary>
  124. /// Tests the Remove method to ensure the entry is removed from the phone book.
  125. /// </summary>
  126. [TestMethod]
  127. public void RemoveTest()
  128. {
  129. bool expected = true;
  130. bool actual = this._entry.Remove();
  131. Assert.AreEqual(expected, actual);
  132. }
  133. #endregion
  134. #region Rename
  135. /// <summary>
  136. /// Tests the Rename method to ensure the entry will be renamed as expected.
  137. /// </summary>
  138. [TestMethod]
  139. public void RenameTest()
  140. {
  141. string name = this._entry.Name;
  142. string newEntryName = Guid.NewGuid().ToString();
  143. bool expected = true;
  144. bool actual = this._entry.Rename(newEntryName);
  145. Assert.AreEqual(expected, actual);
  146. Assert.AreEqual(this._entry.Name, newEntryName);
  147. }
  148. #endregion
  149. #region Update
  150. /// <summary>
  151. /// Tests the Update method to ensure the entry will update properly.
  152. /// </summary>
  153. [TestMethod]
  154. public void UpdateTest()
  155. {
  156. bool expected = true;
  157. bool actual = this._entry.Update();
  158. Assert.AreEqual(expected, actual);
  159. }
  160. #endregion
  161. #region UpdateCredentials
  162. /// <summary>
  163. /// Tests the UpdateCredentials method to ensure the credentials will update.
  164. /// </summary>
  165. [TestMethod]
  166. public void UpdateCredentialsTest()
  167. {
  168. NetworkCredential credentials = new NetworkCredential("Test", "User", "Domain");
  169. bool expected = true;
  170. bool actual = this._entry.UpdateCredentials(credentials);
  171. Assert.AreEqual(expected, actual);
  172. }
  173. #if (WINXP || WIN2K8 || WIN7)
  174. /// <summary>
  175. /// Tests the UpdateCredentials method to ensure the credentials will update for the current user.
  176. /// </summary>
  177. [TestMethod]
  178. public void UpdateCredentialsForUserTest()
  179. {
  180. NetworkCredential credentials = new NetworkCredential("Test", "User", "Domain");
  181. bool expected = true;
  182. bool actual = this._entry.UpdateCredentials(credentials, false);
  183. Assert.AreEqual(expected, actual);
  184. }
  185. #endif
  186. #endregion
  187. #endregion
  188. }
  189. }