Merge remote-tracking branch 'remotes/origin/general-devel'
Conflicts: TShockAPI/Commands.cs TShockAPI/DB/GroupManager.cs TShockAPI/DB/RegionManager.cs TShockAPI/Properties/AssemblyInfo.cs Terraria.sln
This commit is contained in:
commit
5c59ebf71a
18 changed files with 660 additions and 15 deletions
10
Local.testsettings
Normal file
10
Local.testsettings
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<TestSettings name="Local" id="943ada2e-478e-45be-b4b8-6f7d6d949602" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<Description>These are default test settings for a local test run.</Description>
|
||||
<Deployment enabled="false" />
|
||||
<Execution>
|
||||
<TestTypeSpecific />
|
||||
<AgentRule name="Execution Agents">
|
||||
</AgentRule>
|
||||
</Execution>
|
||||
</TestSettings>
|
||||
|
|
@ -138,6 +138,9 @@ namespace TShockAPI
|
|||
ChatCommands.Add(new Command("warp", UseWarp, "warp"));
|
||||
ChatCommands.Add(new Command("managewarp", SetWarp, "setwarp"));
|
||||
ChatCommands.Add(new Command("managewarp", DeleteWarp, "delwarp"));
|
||||
ChatCommands.Add(new Command("managegroup", AddGroup, "addGroup"));
|
||||
ChatCommands.Add(new Command("managegroup", DeleteGroup, "delGroup"));
|
||||
ChatCommands.Add(new Command("managegroup", ModifyGroup, "modGroup"));
|
||||
ChatCommands.Add(new Command("cfg", SetSpawn, "setspawn"));
|
||||
ChatCommands.Add(new Command("cfg", Reload, "reload"));
|
||||
ChatCommands.Add(new Command("cfg", DebugConfiguration, "debug-config"));
|
||||
|
|
@ -1204,6 +1207,72 @@ namespace TShockAPI
|
|||
|
||||
#endregion Teleport Commands
|
||||
|
||||
|
||||
#region Group Management
|
||||
|
||||
private static void AddGroup(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count > 0)
|
||||
{
|
||||
String groupname = args.Parameters[0];
|
||||
args.Parameters.RemoveAt(0);
|
||||
String permissions = String.Join(",", args.Parameters );
|
||||
|
||||
String response = TShock.Groups.addGroup(groupname, permissions);
|
||||
if( response.Length > 0 )
|
||||
args.Player.SendMessage(response, Color.Green);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Player.SendMessage("Incorrect format: /addGroup <group name> [optional permissions]", Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DeleteGroup(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count > 0)
|
||||
{
|
||||
String groupname = args.Parameters[0];
|
||||
|
||||
String response = TShock.Groups.delGroup(groupname);
|
||||
if (response.Length > 0)
|
||||
args.Player.SendMessage(response, Color.Green);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Player.SendMessage("Incorrect format: /delGroup <group name>", Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ModifyGroup(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count > 2)
|
||||
{
|
||||
String com = args.Parameters[0];
|
||||
args.Parameters.RemoveAt(0);
|
||||
|
||||
String groupname = args.Parameters[0];
|
||||
args.Parameters.RemoveAt(0);
|
||||
|
||||
if (com.Equals("add"))
|
||||
{
|
||||
String response = TShock.Groups.addPermission(groupname, args.Parameters);
|
||||
if (response.Length > 0)
|
||||
args.Player.SendMessage(response, Color.Green);
|
||||
return;
|
||||
}
|
||||
else if (com.Equals("del") || com.Equals("delete"))
|
||||
{
|
||||
String response = TShock.Groups.delPermission(groupname, args.Parameters);
|
||||
if (response.Length > 0)
|
||||
args.Player.SendMessage(response, Color.Green);
|
||||
return;
|
||||
}
|
||||
}
|
||||
args.Player.SendMessage("Incorrect format: /modGroup add|del <group name> <permission to add or remove>", Color.Red);
|
||||
}
|
||||
|
||||
#endregion Group Management
|
||||
#region Server Config Commands
|
||||
|
||||
private static void SetSpawn(CommandArgs args)
|
||||
|
|
@ -1966,8 +2035,13 @@ namespace TShockAPI
|
|||
return;
|
||||
}
|
||||
int itemAmount = 0;
|
||||
int.TryParse(args.Parameters[args.Parameters.Count - 1], out itemAmount);
|
||||
var items = Tools.GetItemByIdOrName(args.Parameters[0]);
|
||||
args.Parameters.RemoveAt(0);
|
||||
string plStr = args.Parameters[0];
|
||||
args.Parameters.RemoveAt(0);
|
||||
if( args.Parameters.Count > 0 )
|
||||
int.TryParse(args.Parameters[args.Parameters.Count - 1], out itemAmount);
|
||||
|
||||
|
||||
if (items.Count == 0)
|
||||
{
|
||||
|
|
@ -1982,7 +2056,6 @@ namespace TShockAPI
|
|||
var item = items[0];
|
||||
if (item.type >= 1 && item.type < Main.maxItemTypes)
|
||||
{
|
||||
string plStr = args.Parameters[1];
|
||||
var players = Tools.FindPlayer(plStr);
|
||||
if (players.Count == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ namespace TShockAPI.DB
|
|||
AddGroup("default", "canwater,canlava,warp,canbuild");
|
||||
AddGroup("vip", "default,canwater,canlava,warp,canbuild,reservedslot");
|
||||
|
||||
|
||||
String file = Path.Combine(TShock.SavePath, "groups.txt");
|
||||
if (File.Exists(file))
|
||||
{
|
||||
|
|
@ -124,6 +123,96 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
public String addGroup(String name, String permissions)
|
||||
{
|
||||
String message = "";
|
||||
if( GroupExists( name ) )
|
||||
return "Error: Group already exists. Use /modGroup to change permissions.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
if (TShock.Config.StorageType.ToLower() == "sqlite")
|
||||
com.CommandText = "INSERT OR IGNORE INTO GroupList (GroupName, Commands, OrderBy) VALUES (@groupname, @commands, @order);";
|
||||
else if (TShock.Config.StorageType.ToLower() == "mysql")
|
||||
com.CommandText = "INSERT IGNORE INTO GroupList SET GroupName=@groupname, Commands=@commands, OrderBy=@order;";
|
||||
com.AddParameter("@groupname", name);
|
||||
com.AddParameter("@commands", permissions);
|
||||
com.AddParameter("@order", "0");
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been created successfully.";
|
||||
Group g = new Group(name);
|
||||
g.permissions.Add(permissions);
|
||||
groups.Add(g);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String delGroup(String name)
|
||||
{
|
||||
String message = "";
|
||||
if (!GroupExists(name))
|
||||
return "Error: Group doesn't exists.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
com.CommandText = "Delete FROM GroupList WHERE GroupName=@groupname;";
|
||||
com.AddParameter("@groupname", name);
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been deleted successfully.";
|
||||
groups.Remove(Tools.GetGroup(name));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String addPermission(String name, List<String> permissions)
|
||||
{
|
||||
String message = "";
|
||||
if (!GroupExists(name))
|
||||
return "Error: Group doesn't exists.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
Group g = Tools.GetGroup(name);
|
||||
List<String> perm = g.permissions;
|
||||
foreach (String p in permissions)
|
||||
{
|
||||
if (!perm.Contains(p))
|
||||
{
|
||||
if (perm.Count > 0 && perm[0].Equals(""))
|
||||
perm[0] = p;
|
||||
else
|
||||
g.permissions.Add(p);
|
||||
}
|
||||
}
|
||||
com.CommandText = "UPDATE GroupList SET Commands=@perm WHERE GroupName=@name;";
|
||||
com.AddParameter("@perm", String.Join(",", perm));
|
||||
com.AddParameter("@name", name);
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been modified successfully.";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String delPermission(String name, List<String> permissions)
|
||||
{
|
||||
String message = "";
|
||||
if (!GroupExists(name))
|
||||
return "Error: Group doesn't exists.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
Group g = Tools.GetGroup(name);
|
||||
List<String> perm = g.permissions;
|
||||
foreach (String p in permissions)
|
||||
{
|
||||
if (perm.Contains(p))
|
||||
g.permissions.Remove(p);
|
||||
}
|
||||
com.CommandText = "UPDATE GroupList SET Commands=@perm WHERE GroupName=@name;";
|
||||
com.AddParameter("@perm", String.Join(",", perm));
|
||||
com.AddParameter("@name", name);
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been modified successfully.";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public void LoadPermisions()
|
||||
{
|
||||
groups = new List<Group>();
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace TShockAPI.DB
|
|||
String line;
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
if (!line.Equals("") && !line.Substring( 0, 1 ).Equals("#") )
|
||||
if (!line.Equals("") && !line.Substring(0, 1).Equals("#"))
|
||||
{
|
||||
if (TShock.Config.StorageType.ToLower() == "sqlite")
|
||||
com.CommandText = "INSERT OR IGNORE INTO 'ItemBans' (ItemName) VALUES (@name);";
|
||||
|
|
@ -44,8 +44,8 @@ namespace TShockAPI.DB
|
|||
com.CommandText = "INSERT IGNORE INTO ItemBans SET ItemName=@name;";
|
||||
|
||||
int id = 0;
|
||||
int.TryParse(line, out id );
|
||||
com.AddParameter("@name", Tools.GetItemById( id ).name );
|
||||
int.TryParse(line, out id);
|
||||
com.AddParameter("@name", Tools.GetItemById(id).name);
|
||||
com.ExecuteNonQuery();
|
||||
com.Parameters.Clear();
|
||||
}
|
||||
|
|
@ -60,19 +60,25 @@ namespace TShockAPI.DB
|
|||
File.Delete(file2);
|
||||
File.Move(file, file2);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateItemBans();
|
||||
}
|
||||
|
||||
public void UpdateItemBans()
|
||||
{
|
||||
ItemBans.Clear();
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
com.CommandText = "SELECT * FROM ItemBans";
|
||||
|
||||
using (var reader = com.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
while (reader!=null&&reader.Read())
|
||||
ItemBans.Add(reader.Get<string>("ItemName"));
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddNewBan(string itemname = "")
|
||||
{
|
||||
try
|
||||
|
|
@ -82,6 +88,8 @@ namespace TShockAPI.DB
|
|||
com.CommandText = "INSERT INTO ItemBans (ItemName) VALUES (@itemname);";
|
||||
com.AddParameter("@itemname", Tools.GetItemByName(itemname)[0].name);
|
||||
com.ExecuteNonQuery();
|
||||
if( !ItemIsBanned( itemname ) )
|
||||
ItemBans.Add(itemname);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -92,13 +100,16 @@ namespace TShockAPI.DB
|
|||
|
||||
public void RemoveBan(string itemname)
|
||||
{
|
||||
if (!ItemIsBanned(itemname))
|
||||
return;
|
||||
try
|
||||
{
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
com.CommandText = "DELETE FROM ItemBans WHERE ItemName=@itemname;";
|
||||
com.CommandText = "Delete FROM 'ItemBans' WHERE ItemName=@itemname;";
|
||||
com.AddParameter("@itemname", Tools.GetItemByName(itemname)[0].name);
|
||||
com.ExecuteNonQuery();
|
||||
ItemBans.Remove(itemname);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -201,7 +201,6 @@ namespace TShockAPI.DB
|
|||
File.Delete(file2);
|
||||
//File.Move(file, file2);
|
||||
}
|
||||
|
||||
if (updates > 0)
|
||||
ReloadAllRegions();
|
||||
}
|
||||
|
|
@ -249,7 +248,7 @@ namespace TShockAPI.DB
|
|||
int Protected = reader.Get<int>("Protected");
|
||||
string MergedIDs = DbExt.Get<string>(reader, "UserIds");
|
||||
string name = DbExt.Get<string>(reader, "RegionName");
|
||||
|
||||
System.Console.WriteLine(MergedIDs);
|
||||
string[] SplitIDs = MergedIDs.Split(',');
|
||||
|
||||
Region r = new Region(new Rectangle(X1, Y1, width, height), name, Protected, Main.worldID.ToString());
|
||||
|
|
@ -262,6 +261,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
break;
|
||||
}
|
||||
//System.Console.WriteLine(SplitIDs[i]);
|
||||
r.RegionAllowedIDs[i] = Convert.ToInt32(SplitIDs[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -303,7 +303,7 @@ namespace TShockAPI.DB
|
|||
com.AddParameter("@protected", 1);
|
||||
if (com.ExecuteNonQuery() > 0)
|
||||
{
|
||||
ReloadAllRegions();
|
||||
Regions.Add(new Region(new Rectangle(tx, ty, width, height), regionname, 0, worldid));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,5 +35,6 @@ using System.Runtime.InteropServices;
|
|||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
|
||||
[assembly: AssemblyVersion("3.1.3.0723")]
|
||||
[assembly: AssemblyFileVersion("3.1.3.0723")]
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@
|
|||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
|
||||
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#tp - allow player to teleport
|
||||
#tphere - allow a player to teleport players to their position
|
||||
#managewarp - allow player to add/delete warp locations
|
||||
#managegroup - allow player to add/delete/modify groups
|
||||
#editspawn - allow player to enable/disable build protection
|
||||
#cfg - allow player to view/change tshock configuration
|
||||
#time - allow player to change time
|
||||
|
|
|
|||
12
Terraria.sln
12
Terraria.sln
|
|
@ -5,7 +5,19 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockAPI", "TShockAPI\TSho
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockDBEditor", "DBEditor\TShockDBEditor.csproj", "{F1AE395C-6B4D-40E0-8BF8-0D8A126488D3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{F3742F51-D7BF-4754-A68A-CD944D2A21FF}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{755F5B05-0924-47E9-9563-26EB20FE3F67}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Local.testsettings = Local.testsettings
|
||||
Terraria.vsmdi = Terraria.vsmdi
|
||||
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(TestCaseManagementSettings) = postSolution
|
||||
CategoryFile = Terraria.vsmdi
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
|
|
|
|||
6
Terraria.vsmdi
Normal file
6
Terraria.vsmdi
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
|
||||
<RunConfiguration id="943ada2e-478e-45be-b4b8-6f7d6d949602" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
</TestList>
|
||||
</TestLists>
|
||||
53
UnitTests/BanManagerTest.cs
Normal file
53
UnitTests/BanManagerTest.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Community.CsharpSqlite.SQLiteClient;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TShockAPI;
|
||||
using TShockAPI.DB;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class BanManagerTest
|
||||
{
|
||||
public static IDbConnection DB;
|
||||
private BanManager Bans;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
TShock.Config = new ConfigFile();
|
||||
TShock.Config.StorageType = "sqlite";
|
||||
|
||||
DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", "tshock.test.sqlite"));
|
||||
DB.Open();
|
||||
|
||||
Bans = new BanManager(DB);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDBNotNull()
|
||||
{
|
||||
Assert.IsNotNull(Bans);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddBanTest()
|
||||
{
|
||||
Assert.IsTrue(Bans.AddBan("127.0.0.1", "BanTest", "Ban Testing"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FindBanTest()
|
||||
{
|
||||
Assert.IsNotNull(Bans.GetBanByIp("127.0.0.1"));
|
||||
TShock.Config.EnableBanOnUsernames = true;
|
||||
Assert.IsNotNull(Bans.GetBanByName("BanTest"));
|
||||
TShock.Config.EnableBanOnUsernames = false;
|
||||
Assert.IsNull(Bans.GetBanByName("BanTest"));
|
||||
}
|
||||
}
|
||||
}
|
||||
8
UnitTests/BanManagerTest.orderedtest
Normal file
8
UnitTests/BanManagerTest.orderedtest
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OrderedTest name="BanManagerTest" storage="c:\users\shank\dropbox\design and development\csharp\tshock\unittests\banmanagertest.orderedtest" id="f28695ef-8181-4996-8783-b5059ce904b1" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<TestLinks>
|
||||
<TestLink id="58b9a622-39c1-640a-6713-3ee97b0d99e2" name="TestDBNotNull" storage="bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestLink id="67a76536-c5c2-4d99-515a-498708451061" name="AddBanTest" storage="bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestLink id="9265845c-1bec-1156-2e22-1a64c5bd689f" name="FindBanTest" storage="bin\debug\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
</TestLinks>
|
||||
</OrderedTest>
|
||||
103
UnitTests/ItemManagerTest.cs
Normal file
103
UnitTests/ItemManagerTest.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Community.CsharpSqlite.SQLiteClient;
|
||||
using TShockAPI.DB;
|
||||
using TShockAPI;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for UnitTest1
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class ItemManagerTest
|
||||
{
|
||||
public static IDbConnection DB;
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
TShock.Config = new ConfigFile();
|
||||
TShock.Config.StorageType = "sqlite";
|
||||
|
||||
DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", "tshock.test.sqlite"));
|
||||
DB.Open();
|
||||
/*try
|
||||
{
|
||||
var hostport = Config.MySqlHost.Split(':');
|
||||
DB = new MySqlConnection();
|
||||
DB.ConnectionString = String.Format("Server='{0}'; Port='{1}'; Database='{2}'; Uid='{3}'; Pwd='{4}';",
|
||||
hostport[0],
|
||||
hostport.Length > 1 ? hostport[1] : "3306",
|
||||
Config.MySqlDbName,
|
||||
Config.MySqlUsername,
|
||||
Config.MySqlPassword
|
||||
);
|
||||
DB.Open();
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
throw new Exception("MySql not setup correctly");
|
||||
}*/
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SQLiteItemTest_AddBan()
|
||||
{
|
||||
//
|
||||
// TODO: Add test logic here
|
||||
//
|
||||
ItemManager manager = new ItemManager(DB);
|
||||
Assert.IsNotNull(manager);
|
||||
Assert.IsFalse( manager.ItemIsBanned("Dirt Block"), "Item isn't banned" );
|
||||
manager.AddNewBan("Dirt Block");
|
||||
Assert.IsTrue( manager.ItemIsBanned("Dirt Block"), "New item is added");
|
||||
Assert.IsFalse( manager.ItemIsBanned("Green Brick"), "Item isn't banned");
|
||||
manager.AddNewBan("Green Brick");
|
||||
Assert.IsTrue( manager.ItemIsBanned("Green Brick"), "New item is added");
|
||||
Assert.AreEqual(2, manager.ItemBans.Count, "Adding both items");
|
||||
manager.AddNewBan("Green Brick" );
|
||||
Assert.AreEqual(2, manager.ItemBans.Count, "Adding duplicate items");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SQLiteItemTest_RemoveBan()
|
||||
{
|
||||
//
|
||||
// TODO: Add test logic here
|
||||
//
|
||||
ItemManager manager = new ItemManager(DB);
|
||||
Assert.IsNotNull(manager);
|
||||
Assert.AreEqual(2, manager.ItemBans.Count);
|
||||
manager.AddNewBan("Dirt Block");
|
||||
Assert.AreEqual(2, manager.ItemBans.Count);
|
||||
Assert.AreEqual(true, manager.ItemIsBanned("Dirt Block"));
|
||||
manager.RemoveBan("Dirt Block");
|
||||
manager.UpdateItemBans();
|
||||
Assert.AreEqual(1, manager.ItemBans.Count);
|
||||
Assert.AreEqual(false, manager.ItemIsBanned("Dirt Block"));
|
||||
manager.RemoveBan("Dirt Block");
|
||||
Assert.AreEqual(false, manager.ItemIsBanned("Dirt Block"));
|
||||
Assert.AreEqual(true, manager.ItemIsBanned("Green Brick"));
|
||||
manager.RemoveBan("Green Brick");
|
||||
Assert.AreEqual(false, manager.ItemIsBanned("Green Brick"));
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
DB.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
UnitTests/ItemManagerTest.orderedtest
Normal file
7
UnitTests/ItemManagerTest.orderedtest
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OrderedTest name="ItemManagerTest" storage="c:\users\virus\git\tshock\unittests\itemmanagertest.orderedtest" id="b9c6b3d7-52d8-4b49-bfbf-933efa073ca8" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<TestLinks>
|
||||
<TestLink id="851eff7f-13e8-7778-e7ca-71ff3ce24234" name="SQLiteItemTest_AddBan" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestLink id="26cf8396-064b-1c1d-c511-37969c68dfbd" name="SQLiteItemTest_RemoveBan" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
</TestLinks>
|
||||
</OrderedTest>
|
||||
35
UnitTests/Properties/AssemblyInfo.cs
Normal file
35
UnitTests/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("UnitTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("UnitTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("edd69981-21b0-42af-bb55-25088efab253")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
85
UnitTests/RegionManagerTest.cs
Normal file
85
UnitTests/RegionManagerTest.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Data;
|
||||
using TShockAPI;
|
||||
using Community.CsharpSqlite.SQLiteClient;
|
||||
using TShockAPI.DB;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for RegionManagerTest
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class RegionManagerTest
|
||||
{
|
||||
public static IDbConnection DB;
|
||||
public static RegionManager manager;
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
TShock.Config = new ConfigFile();
|
||||
TShock.Config.StorageType = "sqlite";
|
||||
|
||||
DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", "tshock.test.sqlite"));
|
||||
DB.Open();
|
||||
|
||||
manager = new RegionManager(DB);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void AddRegion()
|
||||
{
|
||||
Region r = new Region( new Rectangle(100,100,100,100), "test", 0, "test world");
|
||||
Assert.IsTrue(manager.AddRegion(r.RegionArea.X, r.RegionArea.Y, r.RegionArea.Width, r.RegionArea.Height, r.RegionName, r.RegionWorldID));
|
||||
Assert.AreEqual(1, manager.Regions.Count);
|
||||
|
||||
Region r2 = new Region(new Rectangle(201, 201, 100, 100), "test2", 0, "test world");
|
||||
manager.AddRegion(r2.RegionArea.X, r2.RegionArea.Y, r2.RegionArea.Width, r2.RegionArea.Height, r2.RegionName, r2.RegionWorldID);
|
||||
Assert.AreEqual(2, manager.Regions.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteRegion()
|
||||
{
|
||||
Assert.IsTrue(manager.DeleteRegion("test"));
|
||||
Assert.IsTrue(manager.DeleteRegion("test2"));
|
||||
Assert.AreEqual(0, manager.Regions.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InRegion()
|
||||
{
|
||||
//
|
||||
// TODO: Add test logic here
|
||||
//
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethod2()
|
||||
{
|
||||
//
|
||||
// TODO: Add test logic here
|
||||
//
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethod3()
|
||||
{
|
||||
//
|
||||
// TODO: Add test logic here
|
||||
//
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
DB.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
UnitTests/RegionManagerTest.orderedtest
Normal file
10
UnitTests/RegionManagerTest.orderedtest
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OrderedTest name="RegionManagerTest" storage="c:\users\virus\git\tshock\unittests\regionmanagertest.orderedtest" id="7601a790-d2fb-45d2-a612-1ae4de84eb61" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<TestLinks>
|
||||
<TestLink id="8d92e80b-8c9d-7a14-5c3a-eba6790be784" name="AddRegion" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestLink id="a8d03dce-530d-a255-9115-3b783c8a973c" name="DeleteRegion" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestLink id="57686a56-2684-8c17-1564-ed9a3c37b167" name="InRegion" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestLink id="c77a874e-5605-7aec-f487-110deaa7fafb" name="TestMethod2" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<TestLink id="521a8e25-1f75-066f-b839-56fee4f2a1b1" name="TestMethod3" storage="bin\release\unittests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
</TestLinks>
|
||||
</OrderedTest>
|
||||
141
UnitTests/UnitTests.csproj
Normal file
141
UnitTests/UnitTests.csproj
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>
|
||||
</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F3742F51-D7BF-4754-A68A-CD944D2A21FF}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>UnitTests</RootNamespace>
|
||||
<AssemblyName>UnitTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Community.CsharpSqlite">
|
||||
<HintPath>..\SqlBins\Community.CsharpSqlite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Community.CsharpSqlite.SQLiteClient">
|
||||
<HintPath>..\SqlBins\Community.CsharpSqlite.SQLiteClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_32\Microsoft.Xna.Framework\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data">
|
||||
<HintPath>..\SqlBins\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Web">
|
||||
<HintPath>..\SqlBins\MySql.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="TerrariaServerAPI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\TerrariaServerBins\TerrariaServerAPI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="XNAHelpers, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\TerrariaServerBins\XNAHelpers.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
|
||||
<Visible>False</Visible>
|
||||
</CodeAnalysisDependentAssemblyPaths>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BanManagerTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ItemManagerTest.cs" />
|
||||
<Compile Include="RegionManagerTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj">
|
||||
<Project>{49606449-072B-4CF5-8088-AA49DA586694}</Project>
|
||||
<Name>TShockAPI</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="BanManagerTest.orderedtest">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="ItemManagerTest.orderedtest">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="RegionManagerTest.orderedtest">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Loading…
Add table
Add a link
Reference in a new issue