重构代码:删除测试工程

This commit is contained in:
Argo-Lenovo 2017-04-03 18:37:57 +08:00
parent 83b3b95143
commit 9d1f3a2139
12 changed files with 0 additions and 765 deletions

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="cacheManager" type="Longbow.Caching.Configuration.CacheSection, Longbow.V4"/>
</configSections>
<connectionStrings>
<add name="SQL" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"/>
</connectionStrings>
<cacheManager>
<add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" />
</cacheManager>
</configuration>

View File

@ -1,103 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bootstrap.DataAccessTests</RootNamespace>
<AssemblyName>Bootstrap.DataAccessTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<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>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</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="Longbow.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899, processorArchitecture=MSIL" />
<Reference Include="Longbow.V4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Data" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="DictHelperTests.cs" />
<Compile Include="ExceptionHelperTests.cs" />
<Compile Include="RoleHelperTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GroupHelperTests.cs" />
<Compile Include="MenuHelperTests.cs" />
<Compile Include="LogHelperTests.cs" />
<Compile Include="NotificationHelperTest.cs" />
<Compile Include="UserHelperTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj">
<Project>{AF16CA71-B8C6-4F51-B38C-0C0300FDEBD7}</Project>
<Name>Bootstrap.DataAccess</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</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="$(MSBuildToolsPath)\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>

View File

@ -1,62 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class DictHelperTests
{
private Dict Dict { get; set; }
[TestInitialize]
public void Initialized()
{
Dict = new Dict() { Category = "__测试字典__", Name = "__测试子字典1__", Code = "2", Define = 0 };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Dicts where Category = '__测试菜单__'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveDictsTest()
{
Assert.IsTrue(DictHelper.RetrieveDicts().Count() > 1, "不带参数的DictHelper.RetrieveDicts方法调用失败");
}
[TestMethod]
public void SaveDictTest()
{
// 测试插入字典记录方法 ID = 0
Assert.IsTrue(DictHelper.SaveDict(Dict), "插入字典记录操作失败,请检查 DictHelper.SaveDict 方法");
var dicts = DictHelper.RetrieveDicts();
Assert.IsTrue(dicts.Count() > 0, "插入字典记录操作失败,请检查 DictHelper.SaveDict 方法");
// 测试更新字典记录方法 ID != 0
var dict = dicts.FirstOrDefault(d => d.Category == Dict.Category);
dict.Name = "__测试子字典2__";
Assert.IsTrue(DictHelper.SaveDict(dict), string.Format("更新字典记录ID = {0} 操作失败,请检查 DictHelper.SaveDict 方法", dict.Id));
var dest = DictHelper.RetrieveDicts().Where(d => d.Id == dict.Id);
Assert.IsTrue(dest.Count() == 1, "带参数的DictHelper.RetrieveDicts方法调用失败");
Assert.AreEqual(dict.Name, dest.First().Name, string.Format("更新字典记录ID = {0} 操作失败,请检查 DictHelper.SaveDict 方法", dict.Id));
}
[TestMethod]
public void DeleteDictTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var dict = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == Dict.Category);
if (dict == null) DictHelper.SaveDict(Dict);
dict = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == Dict.Category);
Assert.IsTrue(DictHelper.DeleteDict(dict.Id.ToString()), "DictHelper.DeleteDict 方法调用失败");
}
}
}

View File

@ -1,27 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Specialized;
namespace Bootstrap.DataAccess.Tests
{
[TestClass()]
public class ExceptionHelperTests
{
[TestMethod()]
public void LogTest()
{
try
{
throw new Exception("Just for Test", new Exception("Inner Exception"));
}
catch (Exception ex)
{
var nv = new NameValueCollection();
nv.Add("ErrorPage", "UnitTest_Page");
nv.Add("UserIp", "::1");
nv.Add("UserId", "UnitTest");
ExceptionHelper.Log(ex, nv);
}
}
}
}

View File

@ -1,114 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class GroupHelperTests
{
private Group Group { get; set; }
private User User { get; set; }
private Role Role { get; set; }
[TestInitialize]
public void IniInitialized()
{
Group = new Group() { GroupName = "_测试部门_", Description = "我是很厉害的测试部门" };
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试用户" };
Role = new Role() { RoleName = "_测试角色_", Description = "测试角色" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Groups where GroupName = '_测试部门_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveGroupsTest()
{
Assert.IsTrue(GroupHelper.RetrieveGroups().Count() >= 0, "不带参数的GroupHelper.RetrieveGroups方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void SaveGroupTest()
{
// 测试插入部门方法 ID=0
Assert.IsTrue(GroupHelper.SaveGroup(Group), "插入部门操作失败请检查GroupHelper.SaveGroup方法");
var groups = GroupHelper.RetrieveGroups();
Assert.IsTrue(groups.Count() > 0, "插入部门操作失败请检查GroupHelper.SaveGroup方法");
//测试更新部门方法 ID!=0
var group = groups.FirstOrDefault(g => g.GroupName == Group.GroupName);
group.Description = "我是测试部门";
Assert.IsTrue(GroupHelper.SaveGroup(group), string.Format("更新部门ID={0}操作失败请检查GroupHelper.SaveGroup方法", group.Id));
var ret = GroupHelper.RetrieveGroups(group.Id);
Assert.IsTrue(ret.Count() == 1, "带参数的GroupHelper.RetrieveGroups方法失败");
Assert.AreEqual(group.Description, ret.First().Description, string.Format("更新部门ID={0}操作失败请检查GroupHelper.SaveGroup方法", group.Id));
}
[TestMethod]
public void DeleteGroupTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
Assert.IsTrue(GroupHelper.DeleteGroup(group.Id.ToString()), "GroupHelper.DeleteGroup 方法调用失败");
}
[TestMethod]
public void SaveGroupsByUserIdTest()
{
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
Assert.IsTrue(GroupHelper.SaveGroupsByUserId(user.Id, group.Id.ToString()), "存储用户部门信息失败");
Assert.IsTrue(GroupHelper.RetrieveGroupsByUserId(user.Id).Count() >= 1, string.Format("获取用户ID={0}的部门失败", user.Id));
//删除数据
string sql = "Delete from Users where UserName = '_测试用户_';";
sql += "Delete from Groups where GroupName='_测试部门_';";
sql += string.Format("Delete from UserGroup where UserID={0};", user.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveGroupsByRoleIdTest()
{
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
Assert.IsTrue(GroupHelper.SaveGroupsByRoleId(role.Id, group.Id.ToString()), "存储角色部门信息失败");
Assert.IsTrue(GroupHelper.RetrieveGroupsByRoleId(role.Id).Count() >= 1, string.Format("获取角色ID={0}的部门信息失败", role.Id));
//删除数据
string sql = "Delete from Groups where GroupName = '_测试部门_';";
sql += "Delete from Roles where RoleName='_测试角色_';";
sql += string.Format("Delete from RoleGroup where RoleID={0};", role.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -1,47 +0,0 @@
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.Common;
using System.Data;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class LogHelperTests
{
private Log Log { get; set; }
[TestInitialize]
public void Initialized()
{
Log = new Log() { CRUD = "Test", RequestUrl = "Test", UserName = "_测试用户名称_", ClientIp = "0.0.0.0", ClientAgent = "Test" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "delete from Logs where UserName='_测试用户名称_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveLogsTest()
{
Assert.IsTrue(LogHelper.RetrieveLogs().Count() >= 0, "带有参数的LogHelper.RetrieveLogs方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void SaveLogTest()
{
Assert.IsTrue(LogHelper.SaveLog(Log), "新增日志信息出错,请检查LogHelper的SaveLog 方法");
var logs = LogHelper.RetrieveLogs();
Assert.IsTrue(logs.Count() > 0, "新增日志信息出错,请检查LogHelper的SaveLog 方法");
}
[TestMethod]
public void DeleteLogTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var log = LogHelper.RetrieveLogs().FirstOrDefault(l => l.UserName == Log.UserName);
if (log == null) LogHelper.SaveLog(Log);
log = LogHelper.RetrieveLogs().FirstOrDefault(l => l.UserName == Log.UserName);
Assert.IsTrue(LogHelper.DeleteLog(log.Id.ToString()), "删除日志信息出错");
}
}
}

View File

@ -1,112 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class MenuHelperTests
{
private Menu Menu { get; set; }
private Role Role { get; set; }
[TestInitialize]
public void Initialized()
{
Menu = new Menu() { Name = "__测试菜单__", Order = 999, Category = "0" };
Role = new Role() { RoleName = "_测试角色_", Description = "这是一个测试角色", Checked = "0" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Navigations where Name = '__测试菜单__'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveMenusTest()
{
Assert.IsTrue(MenuHelper.RetrieveMenus().Count() > 1, "不带参数的MenuHelper.RetrieveMenus方法调用失败");
}
[TestMethod]
public void RetrieveMenuByRoleIDTest()
{
Assert.IsTrue(MenuHelper.RetrieveMenusByRoleId(1).Count() >= 0, "根据角色ID查询菜单的MenuHelper.RetrieveMenusByRoleId方法调用失败");
}
[TestMethod]
public void SaveMenuTest()
{
// 测试插入菜单方法 ID = 0
Assert.IsTrue(MenuHelper.SaveMenu(Menu), "插入菜单操作失败,请检查 MenuHelper.SaveMenu 方法");
var menus = MenuHelper.RetrieveMenus();
Assert.IsTrue(menus.Count() > 0, "插入菜单操作失败,请检查 MenuHelper.SaveMenu 方法");
// 测试更新菜单方法 ID != 0
var menu = menus.FirstOrDefault(m => m.Name == Menu.Name);
menu.Icon = "fa";
Assert.IsTrue(MenuHelper.SaveMenu(menu), string.Format("更新菜单ID = {0} 操作失败,请检查 MenuHelper.SaveMenu 方法", menu.Id));
}
[TestMethod]
public void DeleteMenuTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
if (menu == null) MenuHelper.SaveMenu(Menu);
menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
Assert.IsTrue(MenuHelper.DeleteMenu(menu.Id.ToString()), "MenuHelper.DeleteMenu 方法调用失败");
}
[TestMethod]
public void SavaRolesByMenuIdTest()
{
var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
if (menu == null) MenuHelper.SaveMenu(Menu);
menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
Assert.IsTrue(RoleHelper.SavaRolesByMenuId(menu.Id, role.Id.ToString()), "保存菜单角色关系失败");
Assert.IsTrue(RoleHelper.RetrieveRolesByMenuId(menu.Id).Count() > 0, string.Format("获取菜单ID={0}的角色关系失败", menu.Id));
//删除数据
string sql = "delete from Navigations where Name='__测试菜单__';";
sql += "delete from Roles where RoleName='_测试角色_';";
sql += string.Format("delete from NavigationRole where NavigationID={0}", menu.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveMenusByRoleIdTest()
{
var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
if (menu == null) MenuHelper.SaveMenu(Menu);
menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
Assert.IsTrue(MenuHelper.SaveMenusByRoleId(role.Id, menu.Id.ToString()), "存储角色菜单信息失败");
int x = MenuHelper.RetrieveMenusByRoleId(role.Id).Count();
Assert.IsTrue(x >= 1, string.Format("获取角色ID={0}的菜单信息失败", role.Id));
//删除数据
string sql = "Delete from Navigations where Name = '__测试菜单__';";
sql += "Delete from Roles where RoleName='_测试角色_';";
sql += string.Format("Delete from NavigationRole where RoleID={0};", role.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -1,20 +0,0 @@
using Bootstrap.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
namespace Bootstrap.DataAccessTests
{
[TestClass]
public class NotificationHelperTest
{
[TestMethod]
public void RetrieveNotificationsTest()
{
Assert.IsTrue(NotificationHelper.RetrieveNotifications().Count() >= 0, "带参数的NotificationHelper.RetrieveNotifications方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void ProcessRegisterUserTest()
{
Assert.IsTrue(NotificationHelper.ProcessRegisterUser("1"), "带参数的NotificationHelper.ProcessRegisterUser方法调用失败请检查数据库连接或者数据库SQL语句");
}
}
}

View File

@ -1,35 +0,0 @@
using System.Reflection;
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("Bootstrap.DataAccessTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Bootstrap.DataAccessTests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("d3a9d339-6e5e-416d-bb71-d3aae105bd16")]
// 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.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,105 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class RoleTests
{
private Role Role { get; set; }
private User User { get; set; }
private Group Group { get; set; }
[TestInitialize]
public void Initialized()
{
Role = new Role() { RoleName = "_测试角色_", Description = "这是一个测试角色", Checked = "0" };
User = new User() { UserName = "_测试用户_", Password = "111", PassSalt = "111", DisplayName = "_测试用户_", Checked = "0", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试用户" };
Group = new Group() { GroupName = "_测试部门_", Description = "这是一个测试部门", Checked = "0" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "delete from Roles where RoleName='_测试角色_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveRoleTest()
{
//测试添加角色方法 ID = 0
Assert.IsTrue(RoleHelper.SaveRole(Role), "添加角色操作失败请检查RoleHelper.SaveRole方法");
var roles = RoleHelper.RetrieveRoles();
Assert.IsTrue(roles.Count() > 0, "添加角色操作失败请检查RoleHelper.SaveRole方法");
//测试编辑角色方法 ID != 0
var role = roles.FirstOrDefault(m => m.RoleName == Role.RoleName);
role.Description = "这是修改后的测试角色";
Assert.IsTrue(RoleHelper.SaveRole(role), string.Format("更新角色ID={0}操作失败请检查RoleHelper.SaveRole方法", role.Id));
var ret = RoleHelper.RetrieveRoles(role.Id);
Assert.IsTrue(ret.Count() == 1, "带参数的RoleHelper.RetrieveRoles方法调用失败");
Assert.AreEqual(role.Description, ret.First().Description, string.Format("更新角色ID={0}操作失败请检查RoleHelper.SaveRole方法", role.Id));
}
[TestMethod]
public void RetrieveRoleTest()
{
var result = RoleHelper.RetrieveRoles();
Assert.IsTrue(result.Count() >= 0, "不带参数的RoleHelper.RetrieveRole方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void DeleteRoleTest()
{
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == "_测试角色_");
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == "_测试角色_");
Assert.IsTrue(RoleHelper.DeleteRole(role.Id.ToString()), "删除角色失败");
}
[TestMethod]
public void SaveRolesByUserIdTest()
{
var role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
var user = UserHelper.RetrieveUsers().FirstOrDefault(m => m.DisplayName == User.DisplayName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(m => m.DisplayName == User.DisplayName);
Assert.IsTrue(RoleHelper.SaveRolesByUserId(user.Id, role.Id.ToString()), "保存用户角色关系失败");
Assert.IsTrue(RoleHelper.RetrieveRolesByUserId(user.Id).Count() >= 1, string.Format("获取用户ID={0}的角色信息失败", user.Id));
//删除数据
string sql = "delete from Roles where RoleName='_测试角色_';";
sql += "delete from Users where UserName='_测试用户_';";
sql += string.Format("delete from UserRole where UserID={0}", user.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveRoleByGroupIDTest()
{
var role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
var group = GroupHelper.RetrieveGroups().FirstOrDefault(m => m.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(m => m.GroupName == Group.GroupName);
Assert.IsTrue(RoleHelper.SaveRolesByGroupId(group.Id, role.Id.ToString()), "保存部门角色关系失败");
Assert.IsTrue(RoleHelper.RetrieveRolesByGroupId(group.Id).Count() > 0, string.Format("获取部门ID={0}的角色关系失败", group.Id));
//删除数据
string sql = "delete from Roles where RoleName='_测试角色_';";
sql += "delete from Groups where GroupName='_测试部门_';";
sql += string.Format("delete from RoleGroup where GroupID={0}", group.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -1,116 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class UserHelperTests
{
private User User { get; set; }
private Role Role { get; set; }
private Group Group { get; set; }
[TestInitialize]
public void Initialized()
{
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试" };
Role = new Role() { RoleName = "_测试角色_", Description = "测试角色" };
Group = new Group() { GroupName = "_测试部门_", Description = "测试部门" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Users where UserName = '_测试用户_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveUsersTest()
{
Assert.IsTrue(UserHelper.RetrieveUsers().Count() >= 1, "不带参数的UserHelper.RetrieveUsers方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void SaveUserTest()
{
// 测试插入用户方法 ID = 0
Assert.IsTrue(UserHelper.SaveUser(User), "插入用户操作失败请检查UserHelper.SaveUser 方法");
var users = UserHelper.RetrieveUsers();
Assert.IsTrue(users.Count() > 0, "插入用户操作失败请检查UserHelper.SaveUser 方法");
// 测试更新用户方法 ID != 0
var user = users.FirstOrDefault(u => u.UserName == User.UserName);
user.DisplayName = "测试者2号";
user.Description = "测试";
Assert.IsTrue(UserHelper.SaveUser(user), string.Format("更新用户ID={0}操作失败请检查UserHelper.SaveUser方法", user.Id));
var ret = UserHelper.RetrieveUsers(user.Id);
Assert.IsTrue(ret.Count() == 1, "带参数的UserHelper.RetrieveUsers方法调用失败");
Assert.AreEqual(user.DisplayName, ret.First().DisplayName, string.Format("更新用户ID={0}操作失败请检查UserHelper.SaveUser方法", user.Id));
}
[TestMethod]
public void DeleteUserTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
Assert.IsTrue(UserHelper.DeleteUser(user.Id.ToString()), "UserHelper.DeleteUserTest方法调用失败");
}
[TestMethod]
public void SaveUsersByRoleIdTest()
{
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
Assert.IsTrue(UserHelper.SaveUsersByRoleId(role.Id, user.Id.ToString()), "存储角色用户信息失败");
Assert.IsTrue(UserHelper.RetrieveUsersByRoleId(role.Id).Count() >= 1, string.Format("获取角色ID={0}的用户信息失败", role.Id));
//删除数据
string sql = "Delete from Users where UserName = '_测试用户_';";
sql += "Delete from Roles where RoleName='_测试角色_';";
sql += string.Format("Delete from UserRole where RoleID={0};", role.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveUsersByGroupIdTest()
{
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
Assert.IsTrue(UserHelper.SaveUsersByGroupId(group.Id, user.Id.ToString()), "存储部门用户信息失败");
Assert.IsTrue(UserHelper.RetrieveUsersByGroupId(group.Id).Count() >= 1, string.Format("获取部门ID={0}的用户失败", group.Id));
//删除数据
string sql = "Delete from Users where UserName = '_测试用户_';";
sql += "Delete from Groups where GroupName='_测试部门_';";
sql += string.Format("Delete from UserGroup where GroupID={0};", group.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -27,8 +27,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{5864
Scripts\Publish.vbs = Scripts\Publish.vbs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccessTests", "Bootstrap.DataAccessTests\Bootstrap.DataAccessTests.csproj", "{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.Client", "Bootstrap.Client\Bootstrap.Client.csproj", "{6B261B2C-9E70-467C-BE76-13C0E280A683}"
EndProject
Global
@ -45,10 +43,6 @@ Global
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Release|Any CPU.Build.0 = Release|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Release|Any CPU.Build.0 = Release|Any CPU
{6B261B2C-9E70-467C-BE76-13C0E280A683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B261B2C-9E70-467C-BE76-13C0E280A683}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B261B2C-9E70-467C-BE76-13C0E280A683}.Release|Any CPU.ActiveCfg = Release|Any CPU