diff --git a/.gitignore b/.gitignore index 47762a7..9f8c412 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,8 @@ /bin/ /obj/ appsettings.Testing.json +test/nuget.host.tests/bin/ +test/nuget.host.tests/obj +appsettings.Development.json +src/nuget-host/bin/ +src/nuget-host/obj/ diff --git a/.vscode/launch.json b/.vscode/launch.json index 1d1011d..e9915cc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "configurations": [ { "name": ".NET Core Launch (web)", - "type": "coreclr", + "type": "clr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/src/nuget-host/bin/Debug/netcoreapp2.1/nuget-host.dll", @@ -27,7 +27,7 @@ }, { "name": ".NET Core Launch (prod)", - "type": "coreclr", + "type": "clr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/src/nuget-host/bin/Debug/netcoreapp2.1/nuget-host.dll", diff --git a/.vscode/solution-explorer/class.cs-template b/.vscode/solution-explorer/class.cs-template new file mode 100644 index 0000000..015da46 --- /dev/null +++ b/.vscode/solution-explorer/class.cs-template @@ -0,0 +1,8 @@ +using System; + +namespace {{namespace}} +{ + public class {{name}} + { + } +} diff --git a/.vscode/solution-explorer/class.ts-template b/.vscode/solution-explorer/class.ts-template new file mode 100644 index 0000000..ff2edef --- /dev/null +++ b/.vscode/solution-explorer/class.ts-template @@ -0,0 +1,3 @@ +export class {{name}} { + +} \ No newline at end of file diff --git a/.vscode/solution-explorer/class.vb-template b/.vscode/solution-explorer/class.vb-template new file mode 100644 index 0000000..38ef67f --- /dev/null +++ b/.vscode/solution-explorer/class.vb-template @@ -0,0 +1,9 @@ +Imports System + +Namespace {{namespace}} + + Public Class {{name}} + + End Class + +End Namespace diff --git a/.vscode/solution-explorer/default.ts-template b/.vscode/solution-explorer/default.ts-template new file mode 100644 index 0000000..04af870 --- /dev/null +++ b/.vscode/solution-explorer/default.ts-template @@ -0,0 +1,3 @@ +export default {{name}} { + +} \ No newline at end of file diff --git a/.vscode/solution-explorer/enum.cs-template b/.vscode/solution-explorer/enum.cs-template new file mode 100644 index 0000000..7d4cdee --- /dev/null +++ b/.vscode/solution-explorer/enum.cs-template @@ -0,0 +1,8 @@ +using System; + +namespace {{namespace}} +{ + public enum {{name}} + { + } +} diff --git a/.vscode/solution-explorer/interface.cs-template b/.vscode/solution-explorer/interface.cs-template new file mode 100644 index 0000000..6b5dec1 --- /dev/null +++ b/.vscode/solution-explorer/interface.cs-template @@ -0,0 +1,8 @@ +using System; + +namespace {{namespace}} +{ + public interface {{name}} + { + } +} diff --git a/.vscode/solution-explorer/interface.ts-template b/.vscode/solution-explorer/interface.ts-template new file mode 100644 index 0000000..3ea404b --- /dev/null +++ b/.vscode/solution-explorer/interface.ts-template @@ -0,0 +1,3 @@ +export interface {{name}} { + +} \ No newline at end of file diff --git a/.vscode/solution-explorer/template-list.json b/.vscode/solution-explorer/template-list.json new file mode 100644 index 0000000..2849622 --- /dev/null +++ b/.vscode/solution-explorer/template-list.json @@ -0,0 +1,46 @@ +{ + "templates": [ + { + "name": "Class", + "extension": "cs", + "file": "./class.cs-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Interface", + "extension": "cs", + "file": "./interface.cs-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Enum", + "extension": "cs", + "file": "./enum.cs-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Class", + "extension": "ts", + "file": "./class.ts-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Interface", + "extension": "ts", + "file": "./interface.ts-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Default", + "extension": "ts", + "file": "./default.ts-template", + "parameters": "./template-parameters.js" + }, + { + "name": "Class", + "extension": "vb", + "file": "./class.vb-template", + "parameters": "./template-parameters.js" + } + ] +} \ No newline at end of file diff --git a/.vscode/solution-explorer/template-parameters.js b/.vscode/solution-explorer/template-parameters.js new file mode 100644 index 0000000..daba8b2 --- /dev/null +++ b/.vscode/solution-explorer/template-parameters.js @@ -0,0 +1,17 @@ +var path = require("path"); + +module.exports = function(filename, projectPath, folderPath) { + var namespace = "Unknown"; + if (projectPath) { + namespace = path.basename(projectPath, path.extname(projectPath)); + if (folderPath) { + namespace += "." + folderPath.replace(path.dirname(projectPath), "").substring(1).replace(/[\\\/]/g, "."); + } + namespace = namespace.replace(/[\\\-]/g, "_"); + } + + return { + namespace: namespace, + name: path.basename(filename, path.extname(filename)) + } +}; \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b5f0821..d3e1e2e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,6 @@ "type": "process", "args": [ "restore", - "${workspaceFolder}/nuget-host.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", "--ignore-failed-sources" @@ -20,7 +19,6 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/nuget-host.csproj", "/p:Configuration=Debug", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", diff --git a/nuget-host.sln b/nuget-host.sln new file mode 100644 index 0000000..7fbea65 --- /dev/null +++ b/nuget-host.sln @@ -0,0 +1,56 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.6.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3C312E42-9A47-4BED-8265-A405FCA6AFFF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nuget.host.tests", "test\nuget.host.tests\nuget.host.tests.csproj", "{9D758F00-17FF-433D-B088-F9C2D97C9BD1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E8A2DF68-847A-4D88-B002-64FB666F696C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nuget-host", "src\nuget-host\nuget-host.csproj", "{468DB0E4-6221-4E01-BEFF-F452865E59C1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Debug|x64.ActiveCfg = Debug|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Debug|x64.Build.0 = Debug|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Debug|x86.ActiveCfg = Debug|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Debug|x86.Build.0 = Debug|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Release|Any CPU.Build.0 = Release|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Release|x64.ActiveCfg = Release|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Release|x64.Build.0 = Release|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Release|x86.ActiveCfg = Release|Any CPU + {9D758F00-17FF-433D-B088-F9C2D97C9BD1}.Release|x86.Build.0 = Release|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Debug|x64.ActiveCfg = Debug|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Debug|x64.Build.0 = Debug|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Debug|x86.ActiveCfg = Debug|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Debug|x86.Build.0 = Debug|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Release|Any CPU.Build.0 = Release|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Release|x64.ActiveCfg = Release|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Release|x64.Build.0 = Release|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Release|x86.ActiveCfg = Release|Any CPU + {468DB0E4-6221-4E01-BEFF-F452865E59C1}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {9D758F00-17FF-433D-B088-F9C2D97C9BD1} = {3C312E42-9A47-4BED-8265-A405FCA6AFFF} + {468DB0E4-6221-4E01-BEFF-F452865E59C1} = {E8A2DF68-847A-4D88-B002-64FB666F696C} + EndGlobalSection +EndGlobal diff --git a/src/nuget-host/Startup.cs b/src/nuget-host/Startup.cs index c1c133f..8cf2307 100644 --- a/src/nuget-host/Startup.cs +++ b/src/nuget-host/Startup.cs @@ -72,20 +72,7 @@ namespace nuget_host { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); - try - { - dbContext.Database.Migrate(); - } - catch (TargetInvocationException ex) - { - if (ex.InnerException is InvalidOperationException) - // nothing to do ? - { - // TODO (or not) Hit the developper - } - else throw ex; - } - + dbContext.Database.Migrate(); } app.UseStaticFiles(); diff --git a/test/nuget.host.tests/UnitTestWebHost.cs b/test/nuget.host.tests/UnitTestWebHost.cs index 7d94702..5c7f151 100644 --- a/test/nuget.host.tests/UnitTestWebHost.cs +++ b/test/nuget.host.tests/UnitTestWebHost.cs @@ -6,35 +6,32 @@ using Xunit; using nuget_host.Data; using Microsoft.Extensions.Options; using nuget_host.Entities; +using System.Threading.Tasks; namespace nuget.host.tests { public class UnitTestWebHost { - + const string testingUrl = "http://localhost:5003"; [Fact] - public void TestHaveTestDbContext() + public async Task TestHaveTestDbContext() { - IWebHost webhost = BuildWebHost( new string[] { "--urls", "localhost:5003" }); + IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl}); Assert.NotNull(webhost); - ApplicationDbContext dbcontext = (ApplicationDbContext) webhost.Services.GetService(typeof(ApplicationDbContext)); - Assert.NotNull(dbcontext); - dbcontext.Database.EnsureCreated(); + webhost.Start(); + await webhost.StopAsync(); } [Fact] - public void TestHaveConfig() + public async Task TestHaveConfig() { string envVar = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); - Assert.Equal("Testing", envVar); - IWebHost webhost = BuildWebHost( new string[] { "--urls", "localhost:5003" }); + Assert.Equal("Development", envVar); + IWebHost webhost = BuildWebHost( new string[] { "--urls", testingUrl }); Assert.NotNull(webhost); - IOptions configOptions = (IOptions) webhost.Services.GetService(typeof(IOptions)); - NugetSettings nugetConfig = configOptions.Value; - - Assert.NotNull(nugetConfig.ProtectionTitle); - Assert.NotNull(nugetConfig.PackagesRootDir); - Assert.True(nugetConfig.MaxUserKeyCount>0); + webhost.Start(); + + await webhost.StopAsync(); }