Skip to content

Commit 21293d4

Browse files
committed
Added Lite sample and tests (#229)
1 parent 64f4bb1 commit 21293d4

File tree

30 files changed

+34841
-12
lines changed

30 files changed

+34841
-12
lines changed

MyTested.AspNetCore.Mvc.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Hel
142142
EndProject
143143
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Lite", "src\MyTested.AspNetCore.Mvc.Lite\MyTested.AspNetCore.Mvc.Lite.xproj", "{092CEA1D-84CC-43D8-9978-15F359163084}"
144144
EndProject
145+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Lite.Test", "test\MyTested.AspNetCore.Mvc.Lite.Test\MyTested.AspNetCore.Mvc.Lite.Test.xproj", "{E65581E8-9E3E-4F5B-ACE6-519456EE2407}"
146+
EndProject
147+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lite", "Lite", "{903CDAD0-820B-4AD5-9529-97E7FC3B2ECA}"
148+
EndProject
149+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Lite.Web", "samples\Lite\Lite.Web\Lite.Web.xproj", "{4D74DC49-D297-4CE6-B8E5-C93006816C0F}"
150+
EndProject
151+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Lite.Test", "samples\Lite\Lite.Test\Lite.Test.xproj", "{DD268C6F-32E2-46D8-A01C-9DAFDDCDEA4E}"
152+
EndProject
145153
Global
146154
GlobalSection(SolutionConfigurationPlatforms) = preSolution
147155
Debug|Any CPU = Debug|Any CPU
@@ -392,6 +400,18 @@ Global
392400
{092CEA1D-84CC-43D8-9978-15F359163084}.Debug|Any CPU.Build.0 = Debug|Any CPU
393401
{092CEA1D-84CC-43D8-9978-15F359163084}.Release|Any CPU.ActiveCfg = Release|Any CPU
394402
{092CEA1D-84CC-43D8-9978-15F359163084}.Release|Any CPU.Build.0 = Release|Any CPU
403+
{E65581E8-9E3E-4F5B-ACE6-519456EE2407}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
404+
{E65581E8-9E3E-4F5B-ACE6-519456EE2407}.Debug|Any CPU.Build.0 = Debug|Any CPU
405+
{E65581E8-9E3E-4F5B-ACE6-519456EE2407}.Release|Any CPU.ActiveCfg = Release|Any CPU
406+
{E65581E8-9E3E-4F5B-ACE6-519456EE2407}.Release|Any CPU.Build.0 = Release|Any CPU
407+
{4D74DC49-D297-4CE6-B8E5-C93006816C0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
408+
{4D74DC49-D297-4CE6-B8E5-C93006816C0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
409+
{4D74DC49-D297-4CE6-B8E5-C93006816C0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
410+
{4D74DC49-D297-4CE6-B8E5-C93006816C0F}.Release|Any CPU.Build.0 = Release|Any CPU
411+
{DD268C6F-32E2-46D8-A01C-9DAFDDCDEA4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
412+
{DD268C6F-32E2-46D8-A01C-9DAFDDCDEA4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
413+
{DD268C6F-32E2-46D8-A01C-9DAFDDCDEA4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
414+
{DD268C6F-32E2-46D8-A01C-9DAFDDCDEA4E}.Release|Any CPU.Build.0 = Release|Any CPU
395415
EndGlobalSection
396416
GlobalSection(SolutionProperties) = preSolution
397417
HideSolutionNode = FALSE
@@ -461,5 +481,9 @@ Global
461481
{1CF0545A-8800-4ED1-8A89-A95FE557EE57} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
462482
{FE5913FD-CD0A-4ED9-9C43-F2892C72ED6E} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
463483
{092CEA1D-84CC-43D8-9978-15F359163084} = {09353A03-2B0C-496B-8EB1-2CB6A22D758B}
484+
{E65581E8-9E3E-4F5B-ACE6-519456EE2407} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
485+
{903CDAD0-820B-4AD5-9529-97E7FC3B2ECA} = {88CC5098-E49F-4AA4-B964-1C2BF4ECA3C3}
486+
{4D74DC49-D297-4CE6-B8E5-C93006816C0F} = {903CDAD0-820B-4AD5-9529-97E7FC3B2ECA}
487+
{DD268C6F-32E2-46D8-A01C-9DAFDDCDEA4E} = {903CDAD0-820B-4AD5-9529-97E7FC3B2ECA}
464488
EndGlobalSection
465489
EndGlobal
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace Lite.Test.Internal
2+
{
3+
using MyTested.AspNetCore.Mvc;
4+
using System.Collections.Generic;
5+
using System.Threading.Tasks;
6+
using Web.Controllers;
7+
using Xunit;
8+
9+
public class FreeLicenseTest
10+
{
11+
[Fact]
12+
public async Task UsingOnlyLitePackageShouldNotRequireLicense()
13+
=> await Task.Run(async () =>
14+
{
15+
var tasks = new List<Task>();
16+
17+
for (int i = 0; i < 200; i++)
18+
{
19+
tasks.Add(Task.Run(() =>
20+
{
21+
MyController<ValuesController>
22+
.Instance()
23+
.Calling(c => c.Get())
24+
.ShouldReturn()
25+
.Ok();
26+
}));
27+
}
28+
29+
await Task.WhenAll(tasks);
30+
});
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>dd268c6f-32e2-46d8-a01c-9dafddcdea4e</ProjectGuid>
10+
<RootNamespace>Lite.Test</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
13+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<ItemGroup>
19+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
20+
</ItemGroup>
21+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
22+
</Project>

samples/Lite/Lite.Test/Mocks.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Lite.Test
2+
{
3+
using Moq;
4+
using Web.Services;
5+
6+
public static class Mocks
7+
{
8+
public static IData GetData()
9+
{
10+
var mock = new Mock<IData>();
11+
12+
mock.Setup(m => m.Get()).Returns(new[] { "Mocked", "Test", "Data" });
13+
14+
return mock.Object;
15+
}
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
using Xunit;
4+
5+
[assembly: AssemblyProduct("Lite.Test")]
6+
[assembly: ComVisible(false)]
7+
8+
[assembly: CollectionBehavior(MaxParallelThreads = -1)]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Lite.Test
2+
{
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using MyTested.AspNetCore.Mvc;
6+
using Web;
7+
using Web.Services;
8+
9+
public class TestStartup : Startup
10+
{
11+
public TestStartup(IHostingEnvironment env)
12+
: base(env)
13+
{
14+
}
15+
16+
public void ConfigureTestServices(IServiceCollection services)
17+
{
18+
base.ConfigureServices(services);
19+
20+
services.Replace<IData>(sp => Mocks.GetData(), ServiceLifetime.Scoped);
21+
}
22+
}
23+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace Lite.Test
2+
{
3+
using MyTested.AspNetCore.Mvc;
4+
using Web.Controllers;
5+
using Xunit;
6+
7+
public class ValuesControllerTest
8+
{
9+
[Fact]
10+
public void GetShouldReturnOk()
11+
=> MyMvc
12+
.Controller<ValuesController>()
13+
.Calling(c => c.Get())
14+
.ShouldReturn()
15+
.Ok();
16+
17+
[Fact]
18+
public void GetByIdShouldReturnNotFoundWithNoId()
19+
=> MyMvc
20+
.Controller<ValuesController>()
21+
.Calling(c => c.Get(0))
22+
.ShouldReturn()
23+
.NotFound();
24+
25+
[Fact]
26+
public void GetByIdShouldReturnOkWithId()
27+
=> MyMvc
28+
.Controller<ValuesController>()
29+
.Calling(c => c.Get(1))
30+
.ShouldReturn()
31+
.Ok();
32+
33+
[Fact]
34+
public void PostShouldReturnCreated()
35+
=> MyMvc
36+
.Controller<ValuesController>()
37+
.Calling(c => c.Post("Test"))
38+
.ShouldReturn()
39+
.Created()
40+
.AtLocation("/Created/Mocked");
41+
42+
[Fact]
43+
public void PutShouldReturnCreated()
44+
=> MyMvc
45+
.Controller<ValuesController>()
46+
.Calling(c => c.Put(1, "Test"))
47+
.ShouldReturn()
48+
.Created()
49+
.AtLocation("/Updated/1");
50+
51+
[Fact]
52+
public void DeleteShouldReturnBadRequestWithInvalidId()
53+
=> MyMvc
54+
.Controller<ValuesController>()
55+
.Calling(c => c.Delete(0))
56+
.ShouldReturn()
57+
.BadRequest();
58+
59+
[Fact]
60+
public void DeleteShouldReturnUnauthorizedWithValidId()
61+
=> MyMvc
62+
.Controller<ValuesController>()
63+
.Calling(c => c.Delete(1))
64+
.ShouldReturn()
65+
.Unauthorized();
66+
}
67+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"buildOptions": {
3+
"warningsAsErrors": true,
4+
"preserveCompilationContext": true
5+
},
6+
7+
"dependencies": {
8+
"dotnet-test-xunit": "2.2.0-*",
9+
"xunit": "2.2.0-*",
10+
"MyTested.AspNetCore.Mvc.Lite": "1.0.0-*",
11+
"Moq": "4.6.38-alpha",
12+
"Lite.Web": "*"
13+
},
14+
15+
"frameworks": {
16+
"netcoreapp1.0": {
17+
"imports": "dotnet5.4",
18+
"dependencies": {
19+
"Microsoft.NETCore.App": {
20+
"version": "1.0.0-*",
21+
"type": "platform"
22+
}
23+
}
24+
},
25+
"net451": {}
26+
},
27+
28+
"testRunner": "xunit"
29+
}

0 commit comments

Comments
 (0)