UserAccountHelpers.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System.Collections.Generic;
  28. using OpenMetaverse;
  29. using OpenSim.Region.Framework.Scenes;
  30. using OpenSim.Services.Interfaces;
  31. namespace OpenSim.Tests.Common
  32. {
  33. /// <summary>
  34. /// Utility functions for carrying out user profile related tests.
  35. /// </summary>
  36. public static class UserAccountHelpers
  37. {
  38. // /// <summary>
  39. // /// Create a test user with a standard inventory
  40. // /// </summary>
  41. // /// <param name="commsManager"></param>
  42. // /// <param name="callback">
  43. // /// Callback to invoke when inventory has been loaded. This is required because
  44. // /// loading may be asynchronous, even on standalone
  45. // /// </param>
  46. // /// <returns></returns>
  47. // public static CachedUserInfo CreateUserWithInventory(
  48. // CommunicationsManager commsManager, OnInventoryReceivedDelegate callback)
  49. // {
  50. // UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000099");
  51. // return CreateUserWithInventory(commsManager, userId, callback);
  52. // }
  53. //
  54. // /// <summary>
  55. // /// Create a test user with a standard inventory
  56. // /// </summary>
  57. // /// <param name="commsManager"></param>
  58. // /// <param name="userId">User ID</param>
  59. // /// <param name="callback">
  60. // /// Callback to invoke when inventory has been loaded. This is required because
  61. // /// loading may be asynchronous, even on standalone
  62. // /// </param>
  63. // /// <returns></returns>
  64. // public static CachedUserInfo CreateUserWithInventory(
  65. // CommunicationsManager commsManager, UUID userId, OnInventoryReceivedDelegate callback)
  66. // {
  67. // return CreateUserWithInventory(commsManager, "Bill", "Bailey", userId, callback);
  68. // }
  69. //
  70. // /// <summary>
  71. // /// Create a test user with a standard inventory
  72. // /// </summary>
  73. // /// <param name="commsManager"></param>
  74. // /// <param name="firstName">First name of user</param>
  75. // /// <param name="lastName">Last name of user</param>
  76. // /// <param name="userId">User ID</param>
  77. // /// <param name="callback">
  78. // /// Callback to invoke when inventory has been loaded. This is required because
  79. // /// loading may be asynchronous, even on standalone
  80. // /// </param>
  81. // /// <returns></returns>
  82. // public static CachedUserInfo CreateUserWithInventory(
  83. // CommunicationsManager commsManager, string firstName, string lastName,
  84. // UUID userId, OnInventoryReceivedDelegate callback)
  85. // {
  86. // return CreateUserWithInventory(commsManager, firstName, lastName, "troll", userId, callback);
  87. // }
  88. //
  89. // /// <summary>
  90. // /// Create a test user with a standard inventory
  91. // /// </summary>
  92. // /// <param name="commsManager"></param>
  93. // /// <param name="firstName">First name of user</param>
  94. // /// <param name="lastName">Last name of user</param>
  95. // /// <param name="password">Password</param>
  96. // /// <param name="userId">User ID</param>
  97. // /// <param name="callback">
  98. // /// Callback to invoke when inventory has been loaded. This is required because
  99. // /// loading may be asynchronous, even on standalone
  100. // /// </param>
  101. // /// <returns></returns>
  102. // public static CachedUserInfo CreateUserWithInventory(
  103. // CommunicationsManager commsManager, string firstName, string lastName, string password,
  104. // UUID userId, OnInventoryReceivedDelegate callback)
  105. // {
  106. // LocalUserServices lus = (LocalUserServices)commsManager.UserService;
  107. // lus.AddUser(firstName, lastName, password, "[email protected]", 1000, 1000, userId);
  108. //
  109. // CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
  110. // userInfo.OnInventoryReceived += callback;
  111. // userInfo.FetchInventory();
  112. //
  113. // return userInfo;
  114. // }
  115. public static UserAccount CreateUserWithInventory(Scene scene)
  116. {
  117. return CreateUserWithInventory(scene, TestHelpers.ParseTail(99));
  118. }
  119. public static UserAccount CreateUserWithInventory(Scene scene, UUID userId)
  120. {
  121. return CreateUserWithInventory(scene, "Bill", "Bailey", userId, "troll");
  122. }
  123. public static UserAccount CreateUserWithInventory(Scene scene, int userId)
  124. {
  125. return CreateUserWithInventory(scene, "Bill", "Bailey", TestHelpers.ParseTail(userId), "troll");
  126. }
  127. public static UserAccount CreateUserWithInventory(
  128. Scene scene, string firstName, string lastName, UUID userId, string pw)
  129. {
  130. UserAccount ua = new UserAccount(userId) { FirstName = firstName, LastName = lastName };
  131. CreateUserWithInventory(scene, ua, pw);
  132. return ua;
  133. }
  134. public static UserAccount CreateUserWithInventory(
  135. Scene scene, string firstName, string lastName, int userId, string pw)
  136. {
  137. UserAccount ua
  138. = new UserAccount(TestHelpers.ParseTail(userId)) { FirstName = firstName, LastName = lastName };
  139. CreateUserWithInventory(scene, ua, pw);
  140. return ua;
  141. }
  142. public static void CreateUserWithInventory(Scene scene, UserAccount ua, string pw)
  143. {
  144. // FIXME: This should really be set up by UserAccount itself
  145. ua.ServiceURLs = new Dictionary<string, object>();
  146. scene.UserAccountService.StoreUserAccount(ua);
  147. scene.InventoryService.CreateUserInventory(ua.PrincipalID);
  148. scene.AuthenticationService.SetPassword(ua.PrincipalID, pw);
  149. }
  150. }
  151. }