Work on permissions, added tests for permission linked list

This commit is contained in:
Kwoth
2016-09-27 15:26:37 +02:00
parent 597b73d38c
commit 210ca07cde
29 changed files with 13146 additions and 36 deletions

111
src/tests/Tests.cs Normal file
View File

@ -0,0 +1,111 @@
using NadekoBot.Modules.Permissions;
using NadekoBot.Services.Database.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Tests
{
public class Tests
{
private Permission GetRoot()
{
Permission root = new Permission();
root.SecondaryTargetName = "Root";
var cur = root;
for (var i = 1; i < 10; i++)
{
var p = new Permission();
p.SecondaryTargetName = i.ToString();
p.Previous = cur;
cur.Next = p;
cur = p;
}
return root;
}
[Fact]
public void CountTest()
{
var root = GetRoot();
Assert.Equal(10, root.Count());
}
[Fact]
public void AddTest()
{
var root = GetRoot();
root.Add(new Permission() { SecondaryTargetName = "Added" });
Assert.Equal(11, root.Count());
Assert.Equal("Added", root.AsEnumerable().Last().SecondaryTargetName);
}
[Fact]
public void GetAtTest()
{
var root = GetRoot();
Assert.Equal("Root", root.GetAt(0).SecondaryTargetName);
Assert.Equal("1", root.GetAt(1).SecondaryTargetName);
Assert.Equal("5", root.GetAt(5).SecondaryTargetName);
Assert.Equal("9", root.GetAt(9).SecondaryTargetName);
Assert.Throws(typeof(IndexOutOfRangeException), () => { root.GetAt(-5); });
Assert.Throws(typeof(IndexOutOfRangeException), () => { root.GetAt(10); });
}
[Fact]
public void InsertTest() {
var root = GetRoot();
root.Insert(5, new Permission() { SecondaryTargetName = "in2" });
Assert.Equal(11, root.Count());
Assert.Equal("in2", root.GetAt(5).SecondaryTargetName);
root.Insert(0, new Permission() { SecondaryTargetName = "Inserted" });
root = root.Previous;
Assert.Equal("Inserted", root.SecondaryTargetName);
Assert.Equal(12, root.Count());
Assert.Equal("Root", root.GetAt(1).SecondaryTargetName);
Assert.Throws(typeof(IndexOutOfRangeException), () => { root.GetAt(12); });
}
[Fact]
public void RemoveAtTest()
{
var root = GetRoot();
var removed = root.RemoveAt(3);
Assert.Equal("3", removed.SecondaryTargetName);
Assert.Equal(9, root.Count());
var temp = root.Next;
removed = root.RemoveAt(0);
Assert.Equal(8, temp.Count());
Assert.Equal(null, temp.Previous);
Assert.Throws(typeof(IndexOutOfRangeException), () => { temp.RemoveAt(8); });
Assert.Throws(typeof(IndexOutOfRangeException), () => { temp.RemoveAt(-1); });
}
[Fact]
public void TestGetRoot()
{
var root = GetRoot();
var random = root.GetAt(5).GetRoot();
Assert.Equal("Root", random.SecondaryTargetName);
}
}
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>Discord.Net.Commands</name>
</assembly>
<members>
<member name="T:Discord.Commands.AliasAttribute">
<summary> Provides aliases for a command. </summary>
</member>
<member name="P:Discord.Commands.AliasAttribute.Aliases">
<summary> The aliases which have been defined for the command. </summary>
</member>
<member name="M:Discord.Commands.AliasAttribute.#ctor(System.String[])">
<summary> Creates a new <see cref="T:Discord.Commands.AliasAttribute"/> with the given aliases. </summary>
</member>
<member name="T:Discord.Commands.PriorityAttribute">
<summary> Sets priority of commands </summary>
</member>
<member name="P:Discord.Commands.PriorityAttribute.Priority">
<summary> The priority which has been set for the command </summary>
</member>
<member name="M:Discord.Commands.PriorityAttribute.#ctor(System.Int32)">
<summary> Creates a new <see cref="T:Discord.Commands.PriorityAttribute"/> with the given priority. </summary>
</member>
</members>
</doc>

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Kwoth\\.nuget\\packages"
]
}
}

View File

@ -0,0 +1,8 @@
{
"runtimeOptions": {
"framework": {
"name": "Microsoft.NETCore.App",
"version": "1.0.0"
}
}
}

27
src/tests/project.json Normal file
View File

@ -0,0 +1,27 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable"
},
"dependencies": {
"System.Runtime.Serialization.Primitives": "4.1.1",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-192208-24",
"NadekoBot": "1.0.0-*"
},
"testRunner": "xunit",
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
}
}

9841
src/tests/project.lock.json Normal file

File diff suppressed because it is too large Load Diff

21
src/tests/tests.xproj Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>14cbada0-971c-44e3-b331-c7d01dd74f0b</ProjectGuid>
<RootNamespace>tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>