TestInventoryDataPlugin.cs 5.3 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 OpenSim 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;
  28. using System.Collections.Generic;
  29. using OpenMetaverse;
  30. using OpenSim.Framework;
  31. using OpenSim.Data;
  32. namespace OpenSim.Tests.Common.Mock
  33. {
  34. /// <summary>
  35. /// In memory inventory data plugin for test purposes. Could be another dll when properly filled out and when the
  36. /// mono addin plugin system starts co-operating with the unit test system. Currently no locking since unit
  37. /// tests are single threaded.
  38. /// </summary>
  39. public class TestInventoryDataPlugin : IInventoryDataPlugin
  40. {
  41. /// <value>
  42. /// Known inventory folders
  43. /// </value>
  44. private Dictionary<UUID, InventoryFolderBase> m_folders = new Dictionary<UUID, InventoryFolderBase>();
  45. /// <value>
  46. /// User root folders
  47. /// </value>
  48. private Dictionary<UUID, InventoryFolderBase> m_rootFolders = new Dictionary<UUID, InventoryFolderBase>();
  49. public string Version { get { return "0"; } }
  50. public string Name { get { return "TestInventoryDataPlugin"; } }
  51. public void Initialise() {}
  52. public void Initialise(string connect) {}
  53. public void Dispose() {}
  54. public List<InventoryFolderBase> getFolderHierarchy(UUID parentID)
  55. {
  56. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  57. foreach (InventoryFolderBase folder in m_folders.Values)
  58. {
  59. if (folder.ParentID == parentID)
  60. {
  61. folders.AddRange(getFolderHierarchy(folder.ID));
  62. folders.Add(folder);
  63. }
  64. }
  65. return folders;
  66. }
  67. public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
  68. {
  69. return new List<InventoryItemBase>();
  70. }
  71. public List<InventoryFolderBase> getUserRootFolders(UUID user) { return null; }
  72. public InventoryFolderBase getUserRootFolder(UUID user)
  73. {
  74. InventoryFolderBase folder = null;
  75. m_rootFolders.TryGetValue(user, out folder);
  76. return folder;
  77. }
  78. public List<InventoryFolderBase> getInventoryFolders(UUID parentID)
  79. {
  80. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  81. foreach (InventoryFolderBase folder in m_folders.Values)
  82. {
  83. if (folder.ParentID == parentID)
  84. folders.Add(folder);
  85. }
  86. return folders;
  87. }
  88. public InventoryItemBase getInventoryItem(UUID item) { return null; }
  89. public InventoryFolderBase getInventoryFolder(UUID folderId)
  90. {
  91. InventoryFolderBase folder = null;
  92. m_folders.TryGetValue(folderId, out folder);
  93. return folder;
  94. }
  95. public void addInventoryItem(InventoryItemBase item) {}
  96. public void updateInventoryItem(InventoryItemBase item) {}
  97. public void deleteInventoryItem(UUID item) {}
  98. public void addInventoryFolder(InventoryFolderBase folder)
  99. {
  100. m_folders[folder.ID] = folder;
  101. if (folder.ParentID == UUID.Zero)
  102. m_rootFolders[folder.Owner] = folder;
  103. }
  104. public void updateInventoryFolder(InventoryFolderBase folder)
  105. {
  106. m_folders[folder.ID] = folder;
  107. }
  108. public void moveInventoryFolder(InventoryFolderBase folder)
  109. {
  110. // Simple replace
  111. updateInventoryFolder(folder);
  112. }
  113. public void deleteInventoryFolder(UUID folderId)
  114. {
  115. if (m_folders.ContainsKey(folderId))
  116. m_folders.Remove(folderId);
  117. }
  118. public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) { return null; }
  119. }
  120. }