Skip to content

Commit

Permalink
#3 Started moving Database Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Gerbenis committed Oct 5, 2015
1 parent 3a038c1 commit 37c4d24
Show file tree
Hide file tree
Showing 47 changed files with 536 additions and 838 deletions.
7 changes: 7 additions & 0 deletions vNext/BetterModules.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "BetterModules.Sample.Web.Mo
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "BetterModules.Core.Web.Tests", "test\BetterModules.Core.Web.Tests\BetterModules.Core.Web.Tests.xproj", "{F6A470DD-63AB-4A65-9CC2-622BD2B9B372}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "BetterModules.Core.Database.Tests", "test\BetterModules.Core.Database.Tests\BetterModules.Core.Database.Tests.xproj", "{62845479-16DB-4A2D-BB01-04F49B98E6E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,10 @@ Global
{F6A470DD-63AB-4A65-9CC2-622BD2B9B372}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6A470DD-63AB-4A65-9CC2-622BD2B9B372}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6A470DD-63AB-4A65-9CC2-622BD2B9B372}.Release|Any CPU.Build.0 = Release|Any CPU
{62845479-16DB-4A2D-BB01-04F49B98E6E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62845479-16DB-4A2D-BB01-04F49B98E6E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62845479-16DB-4A2D-BB01-04F49B98E6E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62845479-16DB-4A2D-BB01-04F49B98E6E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -87,5 +93,6 @@ Global
{00B11517-DAEB-43AA-B826-B2AA545AE166} = {46ED6C76-1BCC-4177-9A67-492424080985}
{AD8BA351-BC65-4894-B42F-9AC6618A2998} = {E97ED681-48EA-4EF1-97F2-EE7E1EEC516B}
{F6A470DD-63AB-4A65-9CC2-622BD2B9B372} = {46ED6C76-1BCC-4177-9A67-492424080985}
{62845479-16DB-4A2D-BB01-04F49B98E6E0} = {46ED6C76-1BCC-4177-9A67-492424080985}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ public IEnumerable<MethodInfo> GetControllerActions(Type controllerType)
var actions = new List<MethodInfo>();
foreach (var method in methods)
{
if (method.IsPublic && method.ReturnParameter != null && typeof(ActionResult).IsAssignableFrom(method.ReturnParameter.ParameterType) && !actions.Any(f => f.Name == method.Name))
if (method.IsPublic && method.ReturnParameter != null
&& method.DeclaringType == controllerType
&& typeof(IActionResult).IsAssignableFrom(method.ReturnParameter.ParameterType)
&& actions.All(f => f.Name != method.Name))
{
actions.Add(method);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>62845479-16db-4a2d-bb01-04f49b98e6e0</ProjectGuid>
<RootNamespace>BetterModules.Core.Database.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
25 changes: 25 additions & 0 deletions vNext/test/BetterModules.Core.Database.Tests/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "1.0.0-*",
"description": "BetterModules.Core.Database.Tests Class Library",
"authors": [ "user" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",

"dependencies": {
"BetterModules.Core": "1.0.0-*",
"BetterModules.Core.Tests": "1.0.0-*",
"BetterModules.Sample.Module": "1.0.0-*",
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-beta5a-build188",
"Moq": "4.2.1506.2515"
},

"commands": {
"test": "xunit.runner.dnx"
},

"frameworks": {
"dnx451": { }
}
}
2 changes: 2 additions & 0 deletions vNext/test/BetterModules.Core.Tests/coverage.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
C:\Users\user\AppData\Local\Apps\OpenCover\OpenCover.Console.exe -target:"C:\Users\user\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta7\bin\dnx.exe" -targetargs:"--lib C:\DevBridge\source\BetterModules\vNext\artifacts\bin\BetterModules.Core\Debug\dnx451 test" -output:coverage.xml -filter:"+[*]*"
pause
5 changes: 5 additions & 0 deletions vNext/test/BetterModules.Core.Tests/coverage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<CoverageSession xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Summary numSequencePoints="0" visitedSequencePoints="0" numBranchPoints="0" visitedBranchPoints="0" sequenceCoverage="0" branchCoverage="0" maxCyclomaticComplexity="0" minCyclomaticComplexity="0" visitedClasses="0" numClasses="0" visitedMethods="0" numMethods="0" />
<Modules />
</CoverageSession>
2 changes: 1 addition & 1 deletion vNext/test/BetterModules.Core.Tests/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"version": "1.0.0-*",
"description": "BetterModules.Core.Tests Class Library",
"authors": [ "user" ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>f6a470dd-63ab-4a65-9cc2-622bd2b9b372</ProjectGuid>
<RootNamespace>BetterModules.Core.Web.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Linq;
using BetterModules.Core.Web.Models;
using NUnit.Framework;
using Xunit;

namespace BetterModules.Core.Web.Tests.Models
{
[TestFixture]
public class ComboWireJsonTests : TestBase
public class ComboWireJsonTests
{
[Test]
[Fact]
public void Should_Initialize_Properties_Correctly()
{
dynamic data = new { Test = 1 };
Expand All @@ -17,13 +16,13 @@ public void Should_Initialize_Properties_Correctly()

var json = new ComboWireJson(true, html, data, message1, message2);

Assert.AreEqual(json.Success, true);
Assert.AreEqual(json.Html, html);
Assert.AreEqual(json.Data, data);
Assert.IsNotNull(json.Messages);
Assert.AreEqual(json.Messages.Length, 2);
Assert.IsTrue(json.Messages.Any(m => m == message1));
Assert.IsTrue(json.Messages.Any(m => m == message2));
Assert.Equal(json.Success, true);
Assert.Equal(json.Html, html);
Assert.Equal(json.Data, data);
Assert.NotNull(json.Messages);
Assert.Equal(json.Messages.Length, 2);
Assert.True(json.Messages.Any(m => m == message1));
Assert.True(json.Messages.Any(m => m == message2));
}
}
}
87 changes: 43 additions & 44 deletions vNext/test/BetterModules.Core.Web.Tests/Models/UserMessagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,37 @@
using System.Collections.Generic;
using System.Linq;
using BetterModules.Core.Web.Models;
using NUnit.Framework;
using Xunit;

namespace BetterModules.Core.Web.Tests.Models
{
[TestFixture]
public class UserMessagesTests : TestBase
public class UserMessagesTests
{
[Test]
[Fact]
public void Should_Create_Empty_Warn_Messages()
{
var messages = new UserMessages();

Assert.IsNotNull(messages.Error);
Assert.IsNotNull(messages.Success);
Assert.IsNotNull(messages.Warn);
Assert.IsNotNull(messages.Info);
Assert.NotNull(messages.Error);
Assert.NotNull(messages.Success);
Assert.NotNull(messages.Warn);
Assert.NotNull(messages.Info);

Assert.IsEmpty(messages.Error);
Assert.IsEmpty(messages.Success);
Assert.IsEmpty(messages.Warn);
Assert.IsEmpty(messages.Info);
Assert.Empty(messages.Error);
Assert.Empty(messages.Success);
Assert.Empty(messages.Warn);
Assert.Empty(messages.Info);
}

[Test]
[Fact]
public void Should_Add_Return_Messages_Correctly()
{
var messages = new UserMessages();

Assert.IsNotNull(messages.Error);
Assert.IsNotNull(messages.Success);
Assert.IsNotNull(messages.Warn);
Assert.IsNotNull(messages.Info);
Assert.NotNull(messages.Error);
Assert.NotNull(messages.Success);
Assert.NotNull(messages.Warn);
Assert.NotNull(messages.Info);

messages.AddError("E1");
messages.AddError("E2");
Expand All @@ -44,55 +43,55 @@ public void Should_Add_Return_Messages_Correctly()
messages.AddInfo("I1");
messages.AddInfo("I2");

Assert.AreEqual(messages.Error.Count, 2);
Assert.IsTrue(messages.Error.Any(e => e == "E1"));
Assert.IsTrue(messages.Error.Any(e => e == "E2"));
Assert.Equal(messages.Error.Count, 2);
Assert.True(messages.Error.Any(e => e == "E1"));
Assert.True(messages.Error.Any(e => e == "E2"));

Assert.AreEqual(messages.Warn.Count, 2);
Assert.IsTrue(messages.Warn.Any(e => e == "W1"));
Assert.IsTrue(messages.Warn.Any(e => e == "W2"));
Assert.Equal(messages.Warn.Count, 2);
Assert.True(messages.Warn.Any(e => e == "W1"));
Assert.True(messages.Warn.Any(e => e == "W2"));

Assert.AreEqual(messages.Success.Count, 2);
Assert.IsTrue(messages.Success.Any(e => e == "S1"));
Assert.IsTrue(messages.Success.Any(e => e == "S2"));
Assert.Equal(messages.Success.Count, 2);
Assert.True(messages.Success.Any(e => e == "S1"));
Assert.True(messages.Success.Any(e => e == "S2"));

Assert.AreEqual(messages.Info.Count, 2);
Assert.IsTrue(messages.Info.Any(e => e == "I1"));
Assert.IsTrue(messages.Info.Any(e => e == "I2"));
Assert.Equal(messages.Info.Count, 2);
Assert.True(messages.Info.Any(e => e == "I1"));
Assert.True(messages.Info.Any(e => e == "I2"));
}

[Test]
[Fact]
public void Should_Clear_Messages_Correctly()
{
var messages = new UserMessages();

Assert.IsNotNull(messages.Error);
Assert.IsNotNull(messages.Success);
Assert.IsNotNull(messages.Warn);
Assert.IsNotNull(messages.Info);
Assert.NotNull(messages.Error);
Assert.NotNull(messages.Success);
Assert.NotNull(messages.Warn);
Assert.NotNull(messages.Info);

messages.AddError("M");
messages.AddSuccess("M");
messages.AddInfo("M");
messages.AddWarn("M");

Assert.AreEqual(messages.Error.Count, 1);
Assert.AreEqual(messages.Info.Count, 1);
Assert.AreEqual(messages.Warn.Count, 1);
Assert.AreEqual(messages.Success.Count, 1);
Assert.Equal(messages.Error.Count, 1);
Assert.Equal(messages.Info.Count, 1);
Assert.Equal(messages.Warn.Count, 1);
Assert.Equal(messages.Success.Count, 1);

messages.Clear();

Assert.IsEmpty(messages.Error);
Assert.IsEmpty(messages.Success);
Assert.IsEmpty(messages.Warn);
Assert.IsEmpty(messages.Info);
Assert.Empty(messages.Error);
Assert.Empty(messages.Success);
Assert.Empty(messages.Warn);
Assert.Empty(messages.Info);
}

/// <summary>
/// Should not to allow edit the collection (add new item)
/// </summary>
[Test]
[Fact]
public void Should_Throw_ReadOnly_Exception()
{
var thrown = 0;
Expand All @@ -118,7 +117,7 @@ public void Should_Throw_ReadOnly_Exception()
}
});

Assert.AreEqual(thrown, 4);
Assert.Equal(thrown, 4);
}
}
}
Loading

0 comments on commit 37c4d24

Please sign in to comment.