Delete a bunch of cruft that has gone unmaintained for too long.

Fix warps to have an auto-increment primary key column, and unique on name/WorldID
Same for regions.
Changed SqliteTableCreator to do proper unique syntax.
This commit is contained in:
Zack Piispanen 2014-09-03 02:41:53 -04:00
parent 34b268f1db
commit 1c7fe908b6
19 changed files with 15 additions and 2321 deletions

View file

@ -1,10 +0,0 @@
<?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>

View file

@ -2,15 +2,9 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2010
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
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockAPI", "TShockAPI\TShockAPI.csproj", "{49606449-072B-4CF5-8088-AA49DA586694}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{F3742F51-D7BF-4754-A68A-CD944D2A21FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockRestTestPlugin", "TShockRestTestPlugin\TShockRestTestPlugin.csproj", "{F2FEDAFB-58DE-4611-9168-A86112C346C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerrariaAPI-Server", "TerrariaServerAPI\TerrariaAPI-Server.csproj", "{549A7941-D9C9-4544-BAC8-D9EEEAB4D777}"
@ -38,12 +32,6 @@ Global
{49606449-072B-4CF5-8088-AA49DA586694}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{49606449-072B-4CF5-8088-AA49DA586694}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{49606449-072B-4CF5-8088-AA49DA586694}.Release|x86.ActiveCfg = Release|Any CPU
{F3742F51-D7BF-4754-A68A-CD944D2A21FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3742F51-D7BF-4754-A68A-CD944D2A21FF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F3742F51-D7BF-4754-A68A-CD944D2A21FF}.Debug|x86.ActiveCfg = Debug|Any CPU
{F3742F51-D7BF-4754-A68A-CD944D2A21FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3742F51-D7BF-4754-A68A-CD944D2A21FF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F3742F51-D7BF-4754-A68A-CD944D2A21FF}.Release|x86.ActiveCfg = Release|Any CPU
{F2FEDAFB-58DE-4611-9168-A86112C346C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2FEDAFB-58DE-4611-9168-A86112C346C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2FEDAFB-58DE-4611-9168-A86112C346C7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU

View file

@ -44,10 +44,15 @@ namespace TShockAPI.DB
var columns =
table.Columns.Select(
c =>
"'{0}' {1} {2} {3} {4} {5}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), c.Primary ? "PRIMARY KEY" : "",
c.AutoIncrement ? "AUTOINCREMENT" : "", c.NotNull ? "NOT NULL" : "",
c.Unique ? "UNIQUE" : ""));
return "CREATE TABLE {0} ({1})".SFormat(EscapeTableName(table.Name), string.Join(", ", columns));
"'{0}' {1} {2} {3} {4}".SFormat(c.Name,
DbTypeToString(c.Type, c.Length),
c.Primary ? "PRIMARY KEY" : "",
c.AutoIncrement ? "AUTOINCREMENT" : "",
c.NotNull ? "NOT NULL" : ""));
var uniques = table.Columns.Where(c => c.Unique).Select(c => c.Name);
return "CREATE TABLE {0} ({1} {2})".SFormat(EscapeTableName(table.Name),
string.Join(", ", columns),
uniques.Count() > 0 ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) : "");
}
public override string RenameTable(string from, string to)

View file

@ -38,12 +38,13 @@ namespace TShockAPI.DB
{
database = db;
var table = new SqlTable("Regions",
new SqlColumn("Id", MySqlDbType.Int32) {Primary = true, AutoIncrement = true},
new SqlColumn("X1", MySqlDbType.Int32),
new SqlColumn("Y1", MySqlDbType.Int32),
new SqlColumn("width", MySqlDbType.Int32),
new SqlColumn("height", MySqlDbType.Int32),
new SqlColumn("RegionName", MySqlDbType.VarChar, 50) {Primary = true},
new SqlColumn("WorldID", MySqlDbType.Text),
new SqlColumn("RegionName", MySqlDbType.VarChar, 50) {Unique = true},
new SqlColumn("WorldID", MySqlDbType.Text) {Unique = true},
new SqlColumn("UserIds", MySqlDbType.Text),
new SqlColumn("Protected", MySqlDbType.Int32),
new SqlColumn("Groups", MySqlDbType.Text),
@ -114,53 +115,6 @@ namespace TShockAPI.DB
}
}
public void ReloadForUnitTest(String n)
{
using (var reader = database.QueryReader("SELECT * FROM Regions WHERE WorldID=@0", n))
{
Regions.Clear();
while (reader.Read())
{
int X1 = reader.Get<int>("X1");
int Y1 = reader.Get<int>("Y1");
int height = reader.Get<int>("height");
int width = reader.Get<int>("width");
int Protected = reader.Get<int>("Protected");
string MergedIDs = reader.Get<string>("UserIds");
string name = reader.Get<string>("RegionName");
string[] SplitIDs = MergedIDs.Split(',');
string owner = reader.Get<string>("Owner");
string groups = reader.Get<string>("Groups");
int z = reader.Get<int>("Z");
Region r = new Region(new Rectangle(X1, Y1, width, height), name, owner, Protected != 0, Main.worldID.ToString(), z);
r.SetAllowedGroups(groups);
try
{
for (int i = 0; i < SplitIDs.Length; i++)
{
int id;
if (Int32.TryParse(SplitIDs[i], out id)) // if unparsable, it's not an int, so silently skip
r.AllowedIDs.Add(id);
else if (SplitIDs[i] == "") // Split gotcha, can return an empty string with certain conditions
// but we only want to let the user know if it's really a nonparsable integer.
Log.Warn("UnitTest: One of your UserIDs is not a usable integer: " + SplitIDs[i]);
}
}
catch (Exception e)
{
Log.Error("Your database contains invalid UserIDs (they should be ints).");
Log.Error("A lot of things will fail because of this. You must manually delete and re-create the allowed field.");
Log.Error(e.Message);
Log.Error(e.StackTrace);
}
Regions.Add(r);
}
}
}
public bool AddRegion(int tx, int ty, int width, int height, string regionname, string owner, string worldid, int z = 0)
{
if (GetRegionByName(regionname) != null)
@ -469,16 +423,6 @@ namespace TShockAPI.DB
return Regions.FirstOrDefault(r => r.Name.Equals(name) && r.WorldID == Main.worldID.ToString());
}
public Region ZacksGetRegionByName(String name)
{
foreach (Region r in Regions)
{
if (r.Name.Equals(name))
return r;
}
return null;
}
public bool ChangeOwner(string regionName, string newOwner)
{
var region = GetRegionByName(regionName);

View file

@ -40,10 +40,11 @@ namespace TShockAPI.DB
database = db;
var table = new SqlTable("Warps",
new SqlColumn("WarpName", MySqlDbType.VarChar, 50) {Primary = true},
new SqlColumn("Id", MySqlDbType.Int32){Primary = true, AutoIncrement = true},
new SqlColumn("WarpName", MySqlDbType.VarChar, 50) {Unique = true},
new SqlColumn("X", MySqlDbType.Int32),
new SqlColumn("Y", MySqlDbType.Int32),
new SqlColumn("WorldID", MySqlDbType.Text),
new SqlColumn("WorldID", MySqlDbType.Text) {Unique = true},
new SqlColumn("Private", MySqlDbType.Text)
);
var creator = new SqlTableCreator(db,

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestList name="Bamboo" id="63a4ff11-fe54-4b77-97f5-2e5034a7c905" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
<TestLinks>
<TestLink id="7601a790-d2fb-45d2-a612-1ae4de84eb61" name="regionmanagertest" storage="unittests\regionmanagertest.orderedtest" type="Microsoft.VisualStudio.TestTools.TestTypes.Ordered.AutoSuite, Microsoft.VisualStudio.QualityTools.Tips.OrderedTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />
<TestLink id="f28695ef-8181-4996-8783-b5059ce904b1" name="banmanagertest" storage="unittests\banmanagertest.orderedtest" type="Microsoft.VisualStudio.TestTools.TestTypes.Ordered.AutoSuite, Microsoft.VisualStudio.QualityTools.Tips.OrderedTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />
<TestLink id="b9c6b3d7-52d8-4b49-bfbf-933efa073ca8" name="itemmanagertest" storage="unittests\itemmanagertest.orderedtest" type="Microsoft.VisualStudio.TestTools.TestTypes.Ordered.AutoSuite, Microsoft.VisualStudio.QualityTools.Tips.OrderedTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />
<TestLink id="ec2aa146-8548-415b-a9f5-80472ce3c7d9" name="groupmanagertest" storage="unittests\groupmanagertest.orderedtest" type="Microsoft.VisualStudio.TestTools.TestTypes.Ordered.AutoSuite, Microsoft.VisualStudio.QualityTools.Tips.OrderedTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />
</TestLinks>
</TestList>
<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>

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Trace and Test Impact" id="8af8e0df-7e31-4229-8e49-54b1487fd7e4" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are test settings for Trace and Test Impact.</Description>
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
</TestSettings>

View file

@ -1,68 +0,0 @@
/*
TShock, a server mod for Terraria
Copyright (C) 2011-2012 The TShock Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Mono.Data.Sqlite;
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 TestBansDBNotNull()
{
Assert.IsNotNull(Bans);
}
[TestMethod]
public void AddBanTest()
{
Assert.IsTrue(Bans.AddBan("127.0.0.1", "BanTest", "BanTest2", "Ban Testing"));
}
[TestMethod]
public void FindBanTest()
{
Assert.IsNotNull(Bans.GetBanByIp("127.0.0.1"));
Assert.IsNotNull(Bans.GetBanByName("BanTest"));
Assert.IsNotNull(Bans.GetBanByUUID("BanTest2"));
}
}
}

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<OrderedTest name="banmanagertest" storage="c:\users\virus\git\tshock\unittests\banmanagertest.orderedtest" id="f28695ef-8181-4996-8783-b5059ce904b1" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestLinks>
<TestLink id="7cc70e31-eeb8-f6b8-afa2-17bf975873ed" name="TestBansDBNotNull" 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>

View file

@ -1,80 +0,0 @@
/*
TShock, a server mod for Terraria
Copyright (C) 2011-2012 The TShock Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Mono.Data.Sqlite;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TShockAPI;
using TShockAPI.DB;
namespace UnitTests
{
[TestClass]
public class GroupManagerTest
{
public static IDbConnection DB;
private GroupManager Groups;
[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();
Groups = new GroupManager(DB);
TShock.Groups = this.Groups;
}
[TestMethod]
public void TestGroupsDBNotNull()
{
Assert.IsNotNull(Groups);
}
[TestMethod]
public void CreateGroup()
{
Assert.IsTrue(Groups.AddGroup("test1", "heal") != "");
Assert.IsTrue(Groups.GroupExists("test1"));
Assert.IsTrue(TShock.Utils.GetGroup("test1").HasPermission("heal"));
}
[TestMethod]
public void DeleteGroup()
{
Assert.IsTrue(Groups.AddGroup("test1", "heal") != "");
Assert.IsTrue(Groups.GroupExists("test1"));
Assert.IsTrue(Groups.DeleteGroup("test1") != "");
Assert.IsFalse( Groups.GroupExists( "test1") );
}
/*[TestMethod]
public void CreateGroup()
{
Assert.IsTrue(Groups.AddGroup("test1", "heal") != "");
Assert.IsTrue(Groups.GroupExists("test1"));
Assert.IsTrue(Tools.GetGroup("test1").HasPermission("heal"));
}*/
}
}

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<OrderedTest name="groupmanagertest" storage="c:\users\virus\git\tshock\unittests\groupmanagertest.orderedtest" id="ec2aa146-8548-415b-a9f5-80472ce3c7d9" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestLinks>
<TestLink id="4b09514b-0cca-b305-b9af-a4ceaaaf12dd" name="TestGroupsDBNotNull" 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="6ea1e597-9c3c-745b-5307-55ff47787810" name="DeleteGroup" 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="a66f56ff-803a-ff91-0bca-9abde10363de" name="CreateGroup" 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>

View file

@ -1,97 +0,0 @@
/*
TShock, a server mod for Terraria
Copyright (C) 2011-2012 The TShock Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 Mono.Data.Sqlite;
using TShockAPI.DB;
using TShockAPI;
namespace UnitTests
{
/// <summary>
/// Summary description for UnitTest1
/// </summary>
[TestClass]
public class ItemManagerTest
{
public static IDbConnection DB;
public static ItemManager 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 ItemManager(DB);
}
[TestMethod]
public void SQLiteItemTest_AddBan()
{
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()
{
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();
}
}
}

View file

@ -1,7 +0,0 @@
<?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>

View file

@ -1,52 +0,0 @@
/*
TShock, a server mod for Terraria
Copyright (C) 2011-2012 The TShock Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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")]

View file

@ -1,141 +0,0 @@
/*
TShock, a server mod for Terraria
Copyright (C) 2011-2012 The TShock Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using TShockAPI;
using Mono.Data.Sqlite;
using TShockAPI.DB;
using Region = TShockAPI.DB.Region;
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);
TShock.Regions = manager;
manager.ReloadForUnitTest("test");
}
[TestMethod]
public void AddRegion()
{
Region r = new Region( new Rectangle(100,100,100,100), "test", "test", true, "test", 0);
Assert.IsTrue(manager.AddRegion(r.Area.X, r.Area.Y, r.Area.Width, r.Area.Height, r.Name, r.Owner, r.WorldID));
Assert.AreEqual(1, manager.Regions.Count);
Assert.IsNotNull(manager.ZacksGetRegionByName("test"));
Region r2 = new Region(new Rectangle(201, 201, 100, 100), "test2", "test2", true, "test", 0);
manager.AddRegion(r2.Area.X, r2.Area.Y, r2.Area.Width, r2.Area.Height, r2.Name, r2.Owner, r2.WorldID);
Assert.AreEqual(2, manager.Regions.Count);
Assert.IsNotNull(manager.ZacksGetRegionByName("test2"));
}
[TestMethod]
public void DeleteRegion()
{
Assert.IsTrue(2 == manager.Regions.Count);
Assert.IsTrue(manager.DeleteRegion("test"));
Assert.IsTrue(1 == manager.Regions.Count);
Assert.IsTrue(manager.DeleteRegion("test2"));
Assert.IsTrue(0 == manager.Regions.Count);
}
[TestMethod]
public void InRegion()
{
Assert.IsTrue(manager.InArea(100, 100));
Assert.IsTrue(manager.InArea(150, 150));
Assert.IsTrue(manager.InArea(200, 200));
Assert.IsTrue(manager.InArea(201, 201));
Assert.IsTrue(manager.InArea(251, 251));
Assert.IsTrue(manager.InArea(301, 301));
Assert.IsFalse(manager.InArea(311, 311));
Assert.IsFalse(manager.InArea(99, 99));
}
[TestMethod]
public void SetRegionState()
{
Assert.IsTrue(manager.ZacksGetRegionByName("test").DisableBuild);
manager.SetRegionStateTest("test", "test", false);
Assert.IsTrue(!manager.ZacksGetRegionByName("test").DisableBuild);
manager.SetRegionStateTest("test", "test", true);
Assert.IsTrue(manager.ZacksGetRegionByName("test").DisableBuild);
Assert.IsTrue(manager.ZacksGetRegionByName("test2").DisableBuild);
manager.SetRegionStateTest("test2", "test", false);
Assert.IsTrue(!manager.ZacksGetRegionByName("test2").DisableBuild);
manager.SetRegionStateTest("test2", "test", true);
Assert.IsTrue(manager.ZacksGetRegionByName("test2").DisableBuild);
}
[TestMethod]
public void CanBuild()
{
/**
* For now, this test is useless. Need to implement user groups so we can alter Canbuild permission.
*/
}
[TestMethod]
public void AddUser()
{
/**
* For now, this test is useless. Need to implement users so we have names to get ids from.
*/
}
[TestMethod]
public void ListID()
{
Assert.IsTrue(RegionManager.ListIDs("1,2,3,4,5").Count == 5);
Assert.IsTrue(RegionManager.ListIDs("").Count == 0);
}
[TestMethod]
public void ListRegions()
{
//needs a little more work.
}
[TestCleanup]
public void Cleanup()
{
DB.Close();
}
}
}

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<OrderedTest name="regionmanagertest" storage="c:\users\shank\dropbox\design and development\csharp\tshock\unittests\regionmanagertest.orderedtest" id="7601a790-d2fb-45d2-a612-1ae4de84eb61" continueAfterFailure="true" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Execution id="41a9a1cc-4b4c-466c-b54a-8bd056d3489f" />
<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="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="05a473bf-6457-6122-6150-b1aa82e8f869" name="SetRegionState" 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="999dec4b-8a9b-3d06-02fb-622ecb449e82" name="CanBuild" 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="80e781d1-fd68-212a-9099-8791ad55ed9f" name="AddUser" 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="dc9d05c0-db88-716a-bbe0-aff585f7681d" name="ListID" 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="e13e8546-b310-71c3-e068-1ecd18bfec8f" name="ListRegions" 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" />
</TestLinks>
</OrderedTest>

File diff suppressed because it is too large Load diff

View file

@ -1,176 +0,0 @@
<?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>
<IsWebBootstrapper>false</IsWebBootstrapper>
<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>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>WebTest</TestProjectType>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
</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="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Mono.Data.Sqlite">
<HintPath>..\SqlBins\Mono.Data.Sqlite.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="TerrariaServer, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<ExecutableExtension>.exe</ExecutableExtension>
<HintPath>..\TerrariaServerBins\TerrariaServer.exe</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="BanManagerTest.cs" />
<Compile Include="GroupManagerTest.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>
<ProjectReference Include="..\TShockRestTestPlugin\TShockRestTestPlugin.csproj">
<Project>{F2FEDAFB-58DE-4611-9168-A86112C346C7}</Project>
<Name>TShockRestTestPlugin</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="BanManagerTest.orderedtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ItemManagerTest.orderedtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="GroupManagerTest.orderedtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="RegionManagerTest.orderedtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="UnitTests.licenseheader" />
<None Include="RestApiTests.webtest">
<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>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy .\..\..\..\SqlBins\sqlite3.dll . /Y</PostBuildEvent>
</PropertyGroup>
<!-- 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>

View file

@ -1,18 +0,0 @@
extensions: .cs
/*
TShock, a server mod for Terraria
Copyright (C) 2011-2012 The TShock Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/