UserProfileTestUtils.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.Framework.Communications;
  30. using OpenSim.Region.Framework.Scenes;
  31. using OpenSim.Services.Interfaces;
  32. namespace OpenSim.Tests.Common.Setup
  33. {
  34. /// <summary>
  35. /// Utility functions for carrying out user profile related tests.
  36. /// </summary>
  37. public static class UserProfileTestUtils
  38. {
  39. // /// <summary>
  40. // /// Create a test user with a standard inventory
  41. // /// </summary>
  42. // /// <param name="commsManager"></param>
  43. // /// <param name="callback">
  44. // /// Callback to invoke when inventory has been loaded. This is required because
  45. // /// loading may be asynchronous, even on standalone
  46. // /// </param>
  47. // /// <returns></returns>
  48. // public static CachedUserInfo CreateUserWithInventory(
  49. // CommunicationsManager commsManager, OnInventoryReceivedDelegate callback)
  50. // {
  51. // UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000099");
  52. // return CreateUserWithInventory(commsManager, userId, callback);
  53. // }
  54. //
  55. // /// <summary>
  56. // /// Create a test user with a standard inventory
  57. // /// </summary>
  58. // /// <param name="commsManager"></param>
  59. // /// <param name="userId">User ID</param>
  60. // /// <param name="callback">
  61. // /// Callback to invoke when inventory has been loaded. This is required because
  62. // /// loading may be asynchronous, even on standalone
  63. // /// </param>
  64. // /// <returns></returns>
  65. // public static CachedUserInfo CreateUserWithInventory(
  66. // CommunicationsManager commsManager, UUID userId, OnInventoryReceivedDelegate callback)
  67. // {
  68. // return CreateUserWithInventory(commsManager, "Bill", "Bailey", userId, callback);
  69. // }
  70. //
  71. // /// <summary>
  72. // /// Create a test user with a standard inventory
  73. // /// </summary>
  74. // /// <param name="commsManager"></param>
  75. // /// <param name="firstName">First name of user</param>
  76. // /// <param name="lastName">Last name of user</param>
  77. // /// <param name="userId">User ID</param>
  78. // /// <param name="callback">
  79. // /// Callback to invoke when inventory has been loaded. This is required because
  80. // /// loading may be asynchronous, even on standalone
  81. // /// </param>
  82. // /// <returns></returns>
  83. // public static CachedUserInfo CreateUserWithInventory(
  84. // CommunicationsManager commsManager, string firstName, string lastName,
  85. // UUID userId, OnInventoryReceivedDelegate callback)
  86. // {
  87. // return CreateUserWithInventory(commsManager, firstName, lastName, "troll", userId, callback);
  88. // }
  89. //
  90. // /// <summary>
  91. // /// Create a test user with a standard inventory
  92. // /// </summary>
  93. // /// <param name="commsManager"></param>
  94. // /// <param name="firstName">First name of user</param>
  95. // /// <param name="lastName">Last name of user</param>
  96. // /// <param name="password">Password</param>
  97. // /// <param name="userId">User ID</param>
  98. // /// <param name="callback">
  99. // /// Callback to invoke when inventory has been loaded. This is required because
  100. // /// loading may be asynchronous, even on standalone
  101. // /// </param>
  102. // /// <returns></returns>
  103. // public static CachedUserInfo CreateUserWithInventory(
  104. // CommunicationsManager commsManager, string firstName, string lastName, string password,
  105. // UUID userId, OnInventoryReceivedDelegate callback)
  106. // {
  107. // LocalUserServices lus = (LocalUserServices)commsManager.UserService;
  108. // lus.AddUser(firstName, lastName, password, "[email protected]", 1000, 1000, userId);
  109. //
  110. // CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
  111. // userInfo.OnInventoryReceived += callback;
  112. // userInfo.FetchInventory();
  113. //
  114. // return userInfo;
  115. // }
  116. public static UserAccount CreateUserWithInventory(Scene scene)
  117. {
  118. return CreateUserWithInventory(
  119. scene, "Bill", "Bailey", UUID.Parse("00000000-0000-0000-0000-000000000099"), "troll");
  120. }
  121. public static UserAccount CreateUserWithInventory(
  122. Scene scene, string firstName, string lastName, UUID userId, string pw)
  123. {
  124. UserAccount ua
  125. = new UserAccount(userId)
  126. { FirstName = firstName, LastName = lastName };
  127. CreateUserWithInventory(scene, ua, pw);
  128. return ua;
  129. }
  130. public static void CreateUserWithInventory(Scene scene, UserAccount ua, string pw)
  131. {
  132. // FIXME: This should really be set up by UserAccount itself
  133. ua.ServiceURLs = new Dictionary<string, object>();
  134. scene.UserAccountService.StoreUserAccount(ua);
  135. scene.InventoryService.CreateUserInventory(ua.PrincipalID);
  136. scene.AuthenticationService.SetPassword(ua.PrincipalID, pw);
  137. }
  138. }
  139. }