UserProfileTestUtils.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 OpenMetaverse;
  28. using OpenSim.Framework.Communications;
  29. using OpenSim.Framework.Communications.Cache;
  30. using OpenSim.Region.Communications.Local;
  31. namespace OpenSim.Tests.Common.Setup
  32. {
  33. /// <summary>
  34. /// Utility functions for carrying out user profile related tests.
  35. /// </summary>
  36. public static class UserProfileTestUtils
  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. /// <summary>
  54. /// Create a test user with a standard inventory
  55. /// </summary>
  56. /// <param name="commsManager"></param>
  57. /// <param name="userId">User ID</param>
  58. /// <param name="callback">
  59. /// Callback to invoke when inventory has been loaded. This is required because
  60. /// loading may be asynchronous, even on standalone
  61. /// </param>
  62. /// <returns></returns>
  63. public static CachedUserInfo CreateUserWithInventory(
  64. CommunicationsManager commsManager, UUID userId, OnInventoryReceivedDelegate callback)
  65. {
  66. return CreateUserWithInventory(commsManager, "Bill", "Bailey", userId, callback);
  67. }
  68. /// <summary>
  69. /// Create a test user with a standard inventory
  70. /// </summary>
  71. /// <param name="commsManager"></param>
  72. /// <param name="firstName">First name of user</param>
  73. /// <param name="lastName">Last name of user</param>
  74. /// <param name="userId">User ID</param>
  75. /// <param name="callback">
  76. /// Callback to invoke when inventory has been loaded. This is required because
  77. /// loading may be asynchronous, even on standalone
  78. /// </param>
  79. /// <returns></returns>
  80. public static CachedUserInfo CreateUserWithInventory(
  81. CommunicationsManager commsManager, string firstName, string lastName,
  82. UUID userId, OnInventoryReceivedDelegate callback)
  83. {
  84. return CreateUserWithInventory(commsManager, firstName, lastName, "troll", userId, callback);
  85. }
  86. /// <summary>
  87. /// Create a test user with a standard inventory
  88. /// </summary>
  89. /// <param name="commsManager"></param>
  90. /// <param name="firstName">First name of user</param>
  91. /// <param name="lastName">Last name of user</param>
  92. /// <param name="password">Password</param>
  93. /// <param name="userId">User ID</param>
  94. /// <param name="callback">
  95. /// Callback to invoke when inventory has been loaded. This is required because
  96. /// loading may be asynchronous, even on standalone
  97. /// </param>
  98. /// <returns></returns>
  99. public static CachedUserInfo CreateUserWithInventory(
  100. CommunicationsManager commsManager, string firstName, string lastName, string password,
  101. UUID userId, OnInventoryReceivedDelegate callback)
  102. {
  103. LocalUserServices lus = (LocalUserServices)commsManager.UserService;
  104. lus.AddUser(firstName, lastName, password, "[email protected]", 1000, 1000, userId);
  105. CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
  106. userInfo.OnInventoryReceived += callback;
  107. userInfo.FetchInventory();
  108. return userInfo;
  109. }
  110. }
  111. }