using System;
using System.Collections.Generic;
using UserGroups.Transport;
namespace UserGroups.Database
{
/// <summary>
/// Mock DB for generating data
/// </summary>
public static class MockDB
{
/// <summary>
/// Randomizer
/// </summary>
private static readonly Random _random = new Random();
/// <summary>
/// sample data to work with
/// </summary>
private static readonly GroupTransport _sampleData = _BuildGroupTree();
/// <summary>
/// Static method to get a single "database" instance
/// </summary>
/// <returns></returns>
public static GroupTransport GetGroupTree()
{
return _sampleData;
}
/// <summary>
/// Build out a sample group tree
/// </summary>
/// <returns></returns>
private static GroupTransport _BuildGroupTree()
{
GroupTransport retVal = new GroupTransport
{
GroupName = "Global",
Children = new List<GroupTransport>
{
new GroupTransport
{
GroupName = "North America",
Children = new List<GroupTransport>
{
new GroupTransport
{
GroupName = "Windows Users",
Children = new List<GroupTransport>
{
new GroupTransport
{
GroupName =
"Admins"
},
new GroupTransport
{
GroupName =
"Report Writers"
},
new GroupTransport
{
GroupName =
"End Users"
}
}
},
new GroupTransport
{
GroupName = "Apple Users"
},
new GroupTransport
{
GroupName = "Unix Users"
}
}
},
new GroupTransport
{
GroupName = "South America"
},
new GroupTransport
{
GroupName = "Europe"
},
new GroupTransport
{
GroupName = "Asia"
},
new GroupTransport
{
GroupName = "Africa"
}
}
};
_UsersAdd(retVal);
return retVal;
}
/// <summary>
/// Recursively adds children
/// </summary>
/// <param name="group"></param>
private static void _UsersAdd(GroupTransport group)
{
group.AddUsers(_MakeUsers(_random.Next(5)+1));
foreach(GroupTransport child in group.Children)
{
_UsersAdd(child);
}
}
/// <summary>
/// Make users
/// </summary>
/// <param name="number">Number of users to make</param>
/// <returns>The list of users</returns>
private static List<UserTransport> _MakeUsers(int number)
{
string[] firstnames = new[]
{
"Alex", "Bob", "Chris", "David", "Evan", "Frank", "Gina", "Horton", "India",
"Jade", "Kim", "Larry", "Mat", "Nancy", "Ollie",
"Pat", "Ron", "Sally", "Tim", "Vina", "Wilma"
};
string[] lastnames = new[]
{
"Smith", "Brown", "Wang", "Li", "Sato", "Lee", "Santos", "Lim", "Chen",
"Nguyen", "Patel", "Hadad", "Cohen", "Smirnov", "Gruber",
"Novak", "Jensen", "Ivanov", "Johansson", "Martin", "Muller", "Murphy", "Rossi"
, "Garcia"
};
List<UserTransport> retVal = new List<UserTransport>();
while (number-- > 0)
{
UserTransport newUser = new UserTransport
{
FirstName = firstnames[_random.Next(firstnames.Length)],
LastName = lastnames[_random.Next(lastnames.Length)]
};
newUser.Username = string.Format("{0}{1}", newUser.FirstName, newUser.LastName);
newUser.Email = string.Format(@"{0}@company.com", newUser.Username);
retVal.Add(newUser);
}
return retVal;
}
}
}