UserProfileTestUtils.cs 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 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. LocalUserServices lus = (LocalUserServices)commsManager.UserService;
  85. lus.AddUser(firstName, lastName, "troll", "[email protected]", 1000, 1000, userId);
  86. CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
  87. userInfo.OnInventoryReceived += callback;
  88. userInfo.FetchInventory();
  89. return userInfo;
  90. }
  91. }
  92. }