Skip to content

Commit 630acc7

Browse files
author
Jean-Dominique Nguele
committed
Initial commit
0 parents  commit 630acc7

11 files changed

+273
-0
lines changed

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
*.swp
2+
*.*~
3+
project.lock.json
4+
.DS_Store
5+
*.pyc
6+
7+
# Visual Studio Code
8+
.vscode
9+
10+
# User-specific files
11+
*.suo
12+
*.user
13+
*.userosscache
14+
*.sln.docstates
15+
16+
# Build results
17+
[Dd]ebug/
18+
[Dd]ebugPublic/
19+
[Rr]elease/
20+
[Rr]eleases/
21+
x64/
22+
x86/
23+
build/
24+
bld/
25+
[Bb]in/
26+
[Oo]bj/
27+
msbuild.log
28+
msbuild.err
29+
msbuild.wrn
30+
31+
# Visual Studio 2015
32+
.vs/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
12+
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\DotNetCoreSampleApi\DotNetCoreSampleApi.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System.Linq;
3+
using DotNetCoreSampleApi.Controllers;
4+
5+
namespace DotNetCoreSampleApi.Tests
6+
{
7+
[TestClass]
8+
public class ValuesControllerTest
9+
{
10+
[TestMethod]
11+
public void Get_ShouldReturn_Value1AndValue2()
12+
{
13+
var controller = new ValuesController();
14+
15+
var values = controller.Get().ToList(); // retrieves values as a list of string
16+
17+
Assert.IsTrue(values.Contains("value1"), "value1 is not returned");
18+
Assert.IsTrue(values.Contains("value2"), "value2 is not returned");
19+
}
20+
}
21+
}

DotNetCoreSampleApi.sln

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCoreSampleApi", "DotNetCoreSampleApi\DotNetCoreSampleApi.csproj", "{F729A92D-6202-48B7-BCEB-A6E70B748978}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCoreSampleApi.Tests", "DotNetCoreSampleApi.Tests\DotNetCoreSampleApi.Tests.csproj", "{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Debug|x64 = Debug|x64
14+
Debug|x86 = Debug|x86
15+
Release|Any CPU = Release|Any CPU
16+
Release|x64 = Release|x64
17+
Release|x86 = Release|x86
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Debug|x64.ActiveCfg = Debug|x64
26+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Debug|x64.Build.0 = Debug|x64
27+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Debug|x86.ActiveCfg = Debug|x86
28+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Debug|x86.Build.0 = Debug|x86
29+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Release|x64.ActiveCfg = Release|x64
32+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Release|x64.Build.0 = Release|x64
33+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Release|x86.ActiveCfg = Release|x86
34+
{F729A92D-6202-48B7-BCEB-A6E70B748978}.Release|x86.Build.0 = Release|x86
35+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Debug|x64.ActiveCfg = Debug|x64
38+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Debug|x64.Build.0 = Debug|x64
39+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Debug|x86.ActiveCfg = Debug|x86
40+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Debug|x86.Build.0 = Debug|x86
41+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Release|x64.ActiveCfg = Release|x64
44+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Release|x64.Build.0 = Release|x64
45+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Release|x86.ActiveCfg = Release|x86
46+
{B3C7CDD0-B6F5-4777-8E72-DAB435F21F0B}.Release|x86.Build.0 = Release|x86
47+
EndGlobalSection
48+
EndGlobal
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace DotNetCoreSampleApi.Controllers
8+
{
9+
[Route("api/[controller]")]
10+
public class ValuesController : Controller
11+
{
12+
// GET api/values
13+
[HttpGet]
14+
public IEnumerable<string> Get()
15+
{
16+
return new string[] { "value1", "value2" };
17+
}
18+
19+
// GET api/values/5
20+
[HttpGet("{id}")]
21+
public string Get(int id)
22+
{
23+
return "value";
24+
}
25+
26+
// POST api/values
27+
[HttpPost]
28+
public void Post([FromBody]string value)
29+
{
30+
}
31+
32+
// PUT api/values/5
33+
[HttpPut("{id}")]
34+
public void Put(int id, [FromBody]string value)
35+
{
36+
}
37+
38+
// DELETE api/values/5
39+
[HttpDelete("{id}")]
40+
public void Delete(int id)
41+
{
42+
}
43+
}
44+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Folder Include="wwwroot\" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
17+
</ItemGroup>
18+
19+
</Project>

DotNetCoreSampleApi/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace DotNetCoreSampleApi
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
BuildWebHost(args).Run();
18+
}
19+
20+
public static IWebHost BuildWebHost(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>()
23+
.Build();
24+
}
25+
}

DotNetCoreSampleApi/Startup.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Logging;
10+
using Microsoft.Extensions.Options;
11+
12+
namespace DotNetCoreSampleApi
13+
{
14+
public class Startup
15+
{
16+
public Startup(IConfiguration configuration)
17+
{
18+
Configuration = configuration;
19+
}
20+
21+
public IConfiguration Configuration { get; }
22+
23+
// This method gets called by the runtime. Use this method to add services to the container.
24+
public void ConfigureServices(IServiceCollection services)
25+
{
26+
services.AddMvc();
27+
}
28+
29+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
30+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
31+
{
32+
if (env.IsDevelopment())
33+
{
34+
app.UseDeveloperExceptionPage();
35+
}
36+
37+
app.UseMvc();
38+
}
39+
}
40+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Debug",
6+
"System": "Information",
7+
"Microsoft": "Information"
8+
}
9+
}
10+
}

DotNetCoreSampleApi/appsettings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"Debug": {
5+
"LogLevel": {
6+
"Default": "Warning"
7+
}
8+
},
9+
"Console": {
10+
"LogLevel": {
11+
"Default": "Warning"
12+
}
13+
}
14+
}
15+
}

README.md

898 Bytes

dotnetcore-sample

Sample project allowing to get started with .NET Core. Was generated using the .NET Core CLI tools to illustrate a blog post written by Jean-Dominique Nguele and available on blog.iamnguele.com. The commands below show how to quickly get started and must be ran from the root folder.

Run the API

dotnet run --project DotNetCoreSampleApi

Test the API

dotnet test DotNetCoreSampleApi.Tests

0 commit comments

Comments
 (0)