mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 00:46:02 +08:00
Simplify TestLoadIarV0_1AbsentUsers() to use common IAR test setup. Make static dictionaries on NullUserAccountData instance instead to stop user accounts being carried over between tests
This commit is contained in:
@@ -28,6 +28,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Data;
|
||||
@@ -36,12 +39,17 @@ namespace OpenSim.Data.Null
|
||||
{
|
||||
public class NullUserAccountData : IUserAccountData
|
||||
{
|
||||
private static Dictionary<UUID, UserAccountData> m_DataByUUID = new Dictionary<UUID, UserAccountData>();
|
||||
private static Dictionary<string, UserAccountData> m_DataByName = new Dictionary<string, UserAccountData>();
|
||||
private static Dictionary<string, UserAccountData> m_DataByEmail = new Dictionary<string, UserAccountData>();
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Dictionary<UUID, UserAccountData> m_DataByUUID = new Dictionary<UUID, UserAccountData>();
|
||||
private Dictionary<string, UserAccountData> m_DataByName = new Dictionary<string, UserAccountData>();
|
||||
private Dictionary<string, UserAccountData> m_DataByEmail = new Dictionary<string, UserAccountData>();
|
||||
|
||||
public NullUserAccountData(string connectionString, string realm)
|
||||
{
|
||||
// m_log.DebugFormat(
|
||||
// "[NULL USER ACCOUNT DATA]: Initializing new NullUserAccountData with connectionString [{0}], realm [{1}]",
|
||||
// connectionString, realm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,6 +62,15 @@ namespace OpenSim.Data.Null
|
||||
/// <returns></returns>
|
||||
public UserAccountData[] Get(string[] fields, string[] values)
|
||||
{
|
||||
// if (m_log.IsDebugEnabled)
|
||||
// {
|
||||
// m_log.DebugFormat(
|
||||
// "[NULL USER ACCOUNT DATA]: Called Get with fields [{0}], values [{1}]",
|
||||
// string.Join(", ", fields), string.Join(", ", values));
|
||||
// }
|
||||
|
||||
UserAccountData[] userAccounts = new UserAccountData[0];
|
||||
|
||||
List<string> fieldsLst = new List<string>(fields);
|
||||
if (fieldsLst.Contains("PrincipalID"))
|
||||
{
|
||||
@@ -61,41 +78,61 @@ namespace OpenSim.Data.Null
|
||||
UUID id = UUID.Zero;
|
||||
if (UUID.TryParse(values[i], out id))
|
||||
if (m_DataByUUID.ContainsKey(id))
|
||||
return new UserAccountData[] { m_DataByUUID[id] };
|
||||
}
|
||||
if (fieldsLst.Contains("FirstName") && fieldsLst.Contains("LastName"))
|
||||
userAccounts = new UserAccountData[] { m_DataByUUID[id] };
|
||||
}
|
||||
else if (fieldsLst.Contains("FirstName") && fieldsLst.Contains("LastName"))
|
||||
{
|
||||
int findex = fieldsLst.IndexOf("FirstName");
|
||||
int lindex = fieldsLst.IndexOf("LastName");
|
||||
if (m_DataByName.ContainsKey(values[findex] + " " + values[lindex]))
|
||||
return new UserAccountData[] { m_DataByName[values[findex] + " " + values[lindex]] };
|
||||
}
|
||||
if (fieldsLst.Contains("Email"))
|
||||
{
|
||||
userAccounts = new UserAccountData[] { m_DataByName[values[findex] + " " + values[lindex]] };
|
||||
}
|
||||
}
|
||||
else if (fieldsLst.Contains("Email"))
|
||||
{
|
||||
int i = fieldsLst.IndexOf("Email");
|
||||
if (m_DataByEmail.ContainsKey(values[i]))
|
||||
return new UserAccountData[] { m_DataByEmail[values[i]] };
|
||||
userAccounts = new UserAccountData[] { m_DataByEmail[values[i]] };
|
||||
}
|
||||
|
||||
// Fail
|
||||
return new UserAccountData[0];
|
||||
|
||||
// if (m_log.IsDebugEnabled)
|
||||
// {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// foreach (UserAccountData uad in userAccounts)
|
||||
// sb.AppendFormat("({0} {1} {2}) ", uad.FirstName, uad.LastName, uad.PrincipalID);
|
||||
//
|
||||
// m_log.DebugFormat(
|
||||
// "[NULL USER ACCOUNT DATA]: Returning {0} user accounts out of {1}: [{2}]", userAccounts.Length, m_DataByName.Count, sb);
|
||||
// }
|
||||
|
||||
return userAccounts;
|
||||
}
|
||||
|
||||
public bool Store(UserAccountData data)
|
||||
{
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
|
||||
m_log.DebugFormat(
|
||||
"[NULL USER ACCOUNT DATA]: Storing user account {0} {1} {2} {3}",
|
||||
data.FirstName, data.LastName, data.PrincipalID, this.GetHashCode());
|
||||
|
||||
m_DataByUUID[data.PrincipalID] = data;
|
||||
m_DataByName[data.FirstName + " " + data.LastName] = data;
|
||||
if (data.Data.ContainsKey("Email") && data.Data["Email"] != null && data.Data["Email"] != string.Empty)
|
||||
m_DataByEmail[data.Data["Email"]] = data;
|
||||
|
||||
// m_log.DebugFormat("m_DataByUUID count is {0}, m_DataByName count is {1}", m_DataByUUID.Count, m_DataByName.Count);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public UserAccountData[] GetUsers(UUID scopeID, string query)
|
||||
{
|
||||
// m_log.DebugFormat(
|
||||
// "[NULL USER ACCOUNT DATA]: Called GetUsers with scope [{0}], query [{1}]", scopeID, query);
|
||||
|
||||
string[] words = query.Split(new char[] { ' ' });
|
||||
|
||||
for (int i = 0; i < words.Length; i++)
|
||||
|
||||
Reference in New Issue
Block a user