diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index ecd0569..99f0a47 100644 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Dan Barua, Matt Vane, Thomas Eizinger, Richard Bennett")] [assembly: AssemblyProduct("Nancy.Hal")] [assembly: AssemblyCopyright("Copyright (C) Dan Barua, Matt Vane, Thomas Eizinger, Richard Bennett and other contributors")] -[assembly: AssemblyVersion("1.2.1")] +[assembly: AssemblyVersion("2.0.0")] diff --git a/rakefile.rb b/rakefile.rb index d3ea35e..bbb4896 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -4,8 +4,12 @@ require 'rake/clean' require 'rexml/document' -NANCY_VERSION = "1.4.3" -LIB_VERSION = "1.3.0" +NANCY_VERSION = "2.0.0-beta" +LIB_VERSION = "2.0.0-beta0001" +ASSEMBLY_VERSION = LIB_VERSION +if LIB_VERSION.include? "-" + ASSEMBLY_VERSION = LIB_VERSION.gsub(/\-\S+/, '') +end OUTPUT = "build" CONFIGURATION = 'Release' @@ -16,7 +20,7 @@ Albacore.configure do |config| config.log_level = :verbose config.msbuild.use :net4 - config.xunit.command = "tools/xunit/xunit.console.clr4.x86.exe" + config.xunit.command = "tools/xunit/xunit.console.clr4.x86.exe" end desc "Compiles solution and runs unit tests" @@ -28,7 +32,7 @@ desc "Update shared assemblyinfo file for the build" assemblyinfo :version => [:clean] do |asm| - asm.version = LIB_VERSION + asm.version = ASSEMBLY_VERSION asm.company_name = "#{CONTRIBUTORS}" asm.product_name = "Nancy.Hal" asm.title = "Nancy.Hal" @@ -81,7 +85,7 @@ desc "Generates NuGet packages for each project that contains a nuspec" task :nuget_package => [:publish] do - Dir.mkdir("#{OUTPUT}/nuget") + Dir.mkdir("#{OUTPUT}/nuget") nuspecs = FileList["src/**/*.nuspec"] root = File.dirname(__FILE__) @@ -159,4 +163,4 @@ def get_assembly_version(file) return result[1] if !result.nil? end end -end +end \ No newline at end of file diff --git a/src/Nancy.Hal.Example/Model/Users/RolesModule.cs b/src/Nancy.Hal.Example/Model/Users/RolesModule.cs index 366e983..abeb166 100644 --- a/src/Nancy.Hal.Example/Model/Users/RolesModule.cs +++ b/src/Nancy.Hal.Example/Model/Users/RolesModule.cs @@ -1,63 +1,53 @@ -namespace Nancy.Hal.Example.Model.Users -{ - using Nancy; +namespace Nancy.Hal.Example.Model.Users { using Nancy.Hal.Example.Model.Users.Commands; using Nancy.Hal.Example.Model.Users.Queries; using Nancy.ModelBinding; + using Nancy; + + public class RolesModule : NancyModule { + public RolesModule (Database db) : base ("/roles") { + this.Get ("/", _ => { + var request = this.Bind (); + var roles = db.GetAllRoles (); + return Negotiate.WithModel (roles); + }); + + this.Get ("/{roleId:guid}", _ => { + var req = this.Bind (); + var role = db.GetRoleById (req.RoleId); + + if (role == null) { + return 404; + } + + return Negotiate.WithModel (role); + }); + + this.Post ("/", _ => { + var req = this.Bind (); + db.CreateRole (req); + var role = db.GetRoleById (req.Id.GetValueOrDefault ()); + return Negotiate + .WithHeader ("Location", "/roles/" + req.Id.GetValueOrDefault ()) + .WithModel (role) + .WithStatusCode (HttpStatusCode.Created); + }); + + this.Put ("/{roleId:guid}", _ => { + var req = this.Bind (); + db.UpdateRole (req); + var role = db.GetRoleById (req.RoleId); + + return + Negotiate.WithHeader ("Location", "/roles/" + req.RoleId) + .WithModel (role); + }); - public class RolesModule : NancyModule - { - public RolesModule(Database db) - : base("/roles") - { - this.Get["/"] = _ => - { - var request = this.Bind(); - var roles = db.GetAllRoles(); - return Negotiate.WithModel(roles); - }; - - this.Get["/{roleId:guid}"] = _ => - { - var req = this.Bind(); - var role = db.GetRoleById(req.RoleId); - - if (role == null) - { - return 404; - } - - return Negotiate.WithModel(role); - }; - - this.Post["/"] = _ => - { - var req = this.Bind(); - db.CreateRole(req); - var role = db.GetRoleById(req.Id.GetValueOrDefault()); - return Negotiate - .WithHeader("Location", "/roles/" + req.Id.GetValueOrDefault()) - .WithModel(role) - .WithStatusCode(HttpStatusCode.Created); - }; - - this.Put["/{roleId:guid}"] = _ => - { - var req = this.Bind(); - db.UpdateRole(req); - var role = db.GetRoleById(req.RoleId); - - return - Negotiate.WithHeader("Location", "/roles/" + req.RoleId) - .WithModel(role); - }; - - this.Delete["/{roleId:guid}"] = _ => - { - var req = this.Bind(); - db.DeleteRole(req); - return this.Negotiate.WithStatusCode(HttpStatusCode.NoContent); - }; + this.Delete ("/{roleId:guid}", _ => { + var req = this.Bind (); + db.DeleteRole (req); + return this.Negotiate.WithStatusCode (HttpStatusCode.NoContent); + }); } } } \ No newline at end of file diff --git a/src/Nancy.Hal.Example/Model/Users/UsersModule.cs b/src/Nancy.Hal.Example/Model/Users/UsersModule.cs index 36f3b82..4ed4155 100644 --- a/src/Nancy.Hal.Example/Model/Users/UsersModule.cs +++ b/src/Nancy.Hal.Example/Model/Users/UsersModule.cs @@ -1,86 +1,75 @@ -namespace Nancy.Hal.Example.Model.Users -{ - using Nancy; - using Nancy.Hal.Example.Model.Users.Commands; - using Nancy.Hal.Example.Model.Users.Queries; - using Nancy.ModelBinding; +using Nancy; +using Nancy.Hal.Example.Model.Users.Commands; +using Nancy.Hal.Example.Model.Users.Queries; +using Nancy.ModelBinding; +namespace Nancy.Hal.Example.Model.Users { - public class UsersModule : NancyModule - { - public UsersModule(Database db) - : base("/users") - { - this.Get["/"] = _ => - { - var request = this.Bind(); - var users = db.GetAllUsersPaged(request); + public class UsersModule : NancyModule { + public UsersModule (Database db) : base ("/users") { + this.Get ("/", _ => { + var request = this.Bind (); + var users = db.GetAllUsersPaged (request); - return Negotiate.WithModel(users); - }; + return Negotiate.WithModel (users); + }); - this.Get["/{userId:guid}"] = _ => - { - var request = this.Bind(); - var user = db.GetUserById(request.UserId); - if (user == null) - { - return 404; - } + this.Get ("/{userId:guid}", _ => { + var request = this.Bind (); + var user = db.GetUserById (request.UserId); + if (user == null) { + return 404; + } - return Negotiate.WithModel(user); - }; + return Negotiate.WithModel (user); + }); - this.Post["/"] = _ => - { - var request = this.Bind(); - db.CreateUser(request); - var user = db.GetUserById(request.Id.GetValueOrDefault()); + this.Post ("/", _ => { + var request = this.Bind (); + db.CreateUser (request); + var user = db.GetUserById (request.Id.GetValueOrDefault ()); - return - this.Negotiate.WithHeader("Location", LinkTemplates.Users.GetUser.CreateLink(new { Id = user.Id }).ToString()) - .WithModel(user) - .WithStatusCode(HttpStatusCode.Created); - }; + return + this.Negotiate.WithHeader ("Location", LinkTemplates.Users.GetUser.CreateLink (new { Id = user.Id }).ToString ()) + .WithModel (user) + .WithStatusCode (HttpStatusCode.Created); + }); - this.Put["/{userId:guid}"] = _ => - { - var request = this.Bind(); - db.UpdateUser(request); - var user = db.GetUserById(request.UserId); + this.Put ("/{userId:guid}", _ => { + var request = this.Bind (); + db.UpdateUser (request); + var user = db.GetUserById (request.UserId); - return this.Negotiate.WithModel(user) - .WithStatusCode(HttpStatusCode.OK); - }; + return this.Negotiate.WithModel (user) + .WithStatusCode (HttpStatusCode.OK); + }); - this.Put["/{userId:guid}/deactivate"] = _ => - { - var request = this.Bind(); - db.Deactivate(request); - var user = db.GetUserById(request.UserId); + this.Put ("/{userId:guid}/deactivate", _ => { + var request = this.Bind (); + db.Deactivate (request); + var user = db.GetUserById (request.UserId); - return this.Negotiate.WithModel(user) - .WithStatusCode(HttpStatusCode.OK); - }; + return this.Negotiate.WithModel (user) + .WithStatusCode (HttpStatusCode.OK); + }); - this.Put["/{userId:guid}/reactivate"] = _ => - { - var request = this.Bind(); - db.Reactivate(request); - var user = db.GetUserById(request.UserId); + this.Put ("/{userId:guid}/reactivate", _ => { + var request = this.Bind (); + db.Reactivate (request); + var user = db.GetUserById (request.UserId); - return this.Negotiate.WithModel(user) - .WithStatusCode(HttpStatusCode.OK); - }; + return this.Negotiate.WithModel (user) + .WithStatusCode (HttpStatusCode.OK); + }); - this.Put["/{userId:guid}/role/{roleId:guid}"] = _ => - { - var request = this.Bind(); - db.ChangeRole(request); - var user = db.GetUserById(request.UserId); + this.Put ("/{userId:guid}/role/{roleId:guid}", _ => { + var request = this.Bind (); + db.ChangeRole (request); + var user = db.GetUserById (request.UserId); - return this.Negotiate.WithModel(user) - .WithStatusCode(HttpStatusCode.OK); - }; + return this.Negotiate.WithModel (user) + .WithStatusCode (HttpStatusCode.OK); + + }); } } } \ No newline at end of file diff --git a/src/Nancy.Hal.Example/Nancy.Hal.Example.csproj b/src/Nancy.Hal.Example/Nancy.Hal.Example.csproj index 4e138e6..cecc75c 100644 --- a/src/Nancy.Hal.Example/Nancy.Hal.Example.csproj +++ b/src/Nancy.Hal.Example/Nancy.Hal.Example.csproj @@ -1,117 +1,19 @@ - - - + + - Debug - AnyCPU - {763C7EA5-6A09-43EA-9597-5CBF239A0D51} Exe - Properties - Nancy.Hal.Example - Nancy.Hal.Example - v4.5 - 512 - ..\..\src\ - true + netcoreapp2.0 - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\packages\AutoMapper.3.2.1\lib\net40\AutoMapper.dll - - - False - ..\packages\AutoMapper.3.2.1\lib\net40\AutoMapper.Net4.dll - - - ..\packages\Nancy.0.23.0\lib\net40\Nancy.dll - - - ..\packages\Nancy.Hosting.Self.0.23.0\lib\net40\Nancy.Hosting.Self.dll - - - ..\packages\AutoFixture.3.19.0\lib\net40\Ploeh.AutoFixture.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + + + + + - - {1b360192-4675-45a9-a2cd-2bacbf5bc282} - Nancy.Hal - + - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/src/Nancy.Hal.Example/Program.cs b/src/Nancy.Hal.Example/Program.cs index f9bbd9a..ed2edb6 100644 --- a/src/Nancy.Hal.Example/Program.cs +++ b/src/Nancy.Hal.Example/Program.cs @@ -3,21 +3,22 @@ using Nancy.Hal.Example.Model.Users.ViewModels; using Nancy.Hosting.Self; -namespace Nancy.Hal.Example -{ - static class Program - { - static void Main() - { - Mapper.CreateMap(); - Mapper.CreateMap(); +namespace Nancy.Hal.Example { + static class Program { + static void Main () { - using (var host = new NancyHost(new Uri("http://localhost:1234"))) - { - host.Start(); - Console.WriteLine("Server running on http://localhost:1234"); - Console.ReadLine(); + using (var host = new NancyHost (new Uri ("http://localhost:1234"))) { + host.Start (); + Console.WriteLine ("Server running on http://localhost:1234"); + Console.ReadLine (); + } + } + + public class DomainProfile : Profile { + public DomainProfile () { + CreateMap (); + CreateMap (); } } } -} +} \ No newline at end of file diff --git a/src/Nancy.Hal.Example/packages.config b/src/Nancy.Hal.Example/packages.config deleted file mode 100644 index 01e139b..0000000 --- a/src/Nancy.Hal.Example/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/Nancy.Hal.Tests/JsonResponseProcessorTests.cs b/src/Nancy.Hal.Tests/JsonResponseProcessorTests.cs index c2d13a4..cbcb4a2 100644 --- a/src/Nancy.Hal.Tests/JsonResponseProcessorTests.cs +++ b/src/Nancy.Hal.Tests/JsonResponseProcessorTests.cs @@ -11,15 +11,33 @@ using System.IO; using Nancy.Responses; using Nancy.Responses.Negotiation; -using Nancy.Serializers.Json.ServiceStack; +using Nancy.Serialization.ServiceStack; +using Nancy.Json; using Newtonsoft.Json.Linq; -using JsonSerializer = Newtonsoft.Json.JsonSerializer; +using ServiceStack; +using JsonSerializer = Newtonsoft.Json.JsonSerializer; +using Nancy.Configuration; namespace Nancy.Hal.Tests { public abstract class JsonResponseProcessorTests { + public static INancyEnvironment GetTestingEnvironment() + { + var environment = + new DefaultNancyEnvironment(); + + environment.Tracing( + enabled: true, + displayErrorTraces: true); + + environment.Json(); + environment.Globalization(new[] { "en-US" }); + + return environment; + } + [Fact] public void ShouldBuildStaticLinks() { @@ -222,7 +240,7 @@ public void ShouldIgnoreIgnoredProperties() [Fact] public void ShouldSetContentTypeToApplicationHalJson() { - var context = new NancyContext(); + var context = new NancyContext { Environment = GetTestingEnvironment() }; var config = new HalConfiguration(); var processor = new HalJsonResponseProcessor(config, new[] { JsonSerializer }); @@ -256,8 +274,7 @@ public void ShouldTakeLocalConfigurationIntoAccount() globalConfig.For(). Links("rel1", "/staticAddress1"); - var context = new NancyContext(); - + var context = new NancyContext {Environment = GetTestingEnvironment()}; context.LocalHalConfigFor() .Links("rel2", "/staticAddress2"); @@ -286,7 +303,7 @@ protected virtual string AdjustName(string name) private static NancyContext CreateTestContext(dynamic query) { - var context = new NancyContext { Request = new Request("method", "path", "http") { Query = query } }; + var context = new NancyContext { Request = new Request("method", "path", "http") { Query = query }, Environment = GetTestingEnvironment() }; return context; } @@ -294,7 +311,7 @@ private static NancyContext CreateTestContext(dynamic query) private JObject Serialize(object model, IProvideHalTypeConfiguration config, NancyContext context = null) { - if (context == null) context = new NancyContext(); + if (context == null) context = new NancyContext { Environment = GetTestingEnvironment() }; var processor = new HalJsonResponseProcessor(config, new[] { JsonSerializer }); var response = (JsonResponse)processor.Process(new MediaRange("application/hal+json"), model, context); @@ -310,10 +327,8 @@ private JObject Serialize(object model, IProvideHalTypeConfiguration config, Nan public class DefaultJsonSerializerTests : JsonResponseProcessorTests { - protected override ISerializer JsonSerializer - { - get { return new DefaultJsonSerializer(); } - } + + protected override ISerializer JsonSerializer => new DefaultJsonSerializer(GetTestingEnvironment()); // Serialiser converts names to camel case protected override string AdjustName(string name) @@ -342,6 +357,7 @@ protected override ISerializer JsonSerializer // Serialiser converts names to camel case protected override string AdjustName(string name) { + return name.ToCamelCase(); } } diff --git a/src/Nancy.Hal.Tests/Nancy.Hal.Tests.csproj b/src/Nancy.Hal.Tests/Nancy.Hal.Tests.csproj index c0b5c44..3a34b6e 100644 --- a/src/Nancy.Hal.Tests/Nancy.Hal.Tests.csproj +++ b/src/Nancy.Hal.Tests/Nancy.Hal.Tests.csproj @@ -1,121 +1,26 @@ - - - - + + - Debug - AnyCPU - {79B818A0-4C33-4963-A0F6-835F127A67A6} - Library - Properties - Nancy.Hal.Tests - Nancy.Hal.Tests - v4.5 - 512 - ..\..\src\ - true - - + netcoreapp2.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\packages\AutoMapper.3.2.1\lib\net40\AutoMapper.dll - - - ..\packages\AutoMapper.3.2.1\lib\net40\AutoMapper.Net4.dll - - - ..\packages\CsQuery.1.3.3\lib\net40\CsQuery.dll - - - ..\packages\FakeItEasy.1.22.0\lib\net40\FakeItEasy.dll - - - False - ..\packages\Nancy.0.23.2\lib\net40\Nancy.dll - - - ..\packages\Nancy.Serialization.JsonNet.0.23.2\lib\net40\Nancy.Serialization.JsonNet.dll - - - ..\packages\Nancy.Serialization.ServiceStack.0.23.0\lib\net40\Nancy.Serialization.ServiceStack.dll - - - ..\packages\Nancy.Testing.0.23.0\lib\net40\Nancy.Testing.dll - - - False - ..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll - - - ..\packages\ServiceStack.Text.3.9.11\lib\net35\ServiceStack.Text.dll - - - - - - - - - - False - ..\packages\xunit.1.9.2\lib\net20\xunit.dll - - - - - - - - - - - - - Designer - - + - - {1B360192-4675-45A9-A2CD-2BACBF5BC282} - Nancy.Hal - + + + + + + + + + + + + + - + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file + + diff --git a/src/Nancy.Hal.Tests/packages.config b/src/Nancy.Hal.Tests/packages.config deleted file mode 100644 index d945568..0000000 --- a/src/Nancy.Hal.Tests/packages.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Nancy.Hal/Configuration/Extensions.cs b/src/Nancy.Hal/Configuration/Extensions.cs index 2a5a7c7..51c3535 100644 --- a/src/Nancy.Hal/Configuration/Extensions.cs +++ b/src/Nancy.Hal/Configuration/Extensions.cs @@ -14,7 +14,7 @@ internal static string ToCamelCaseString(this string input) if (string.IsNullOrEmpty(input) || !char.IsUpper(input[0])) return input; string lowerCasedFirstChar = - char.ToLower(input[0], CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); + CultureInfo.InvariantCulture.TextInfo.ToLower(input[0]).ToString(); if (input.Length > 1) lowerCasedFirstChar = lowerCasedFirstChar + input.Substring(1); diff --git a/src/Nancy.Hal/Nancy.Hal.csproj b/src/Nancy.Hal/Nancy.Hal.csproj index 7b19c24..c94247b 100644 --- a/src/Nancy.Hal/Nancy.Hal.csproj +++ b/src/Nancy.Hal/Nancy.Hal.csproj @@ -1,81 +1,12 @@ - - - + + - Debug - AnyCPU - {1B360192-4675-45A9-A2CD-2BACBF5BC282} - Library - Properties - Nancy.Hal - Nancy.Hal - v4.5 - 512 - ..\ - true + netstandard1.6 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - ..\packages\Nancy.1.4.3\lib\net40\Nancy.dll - True - - - - - - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - - + - - + + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - + \ No newline at end of file diff --git a/src/Nancy.Hal/Nancy.Hal.nuspec b/src/Nancy.Hal/Nancy.Hal.nuspec index a8e90fd..79a1be9 100644 --- a/src/Nancy.Hal/Nancy.Hal.nuspec +++ b/src/Nancy.Hal/Nancy.Hal.nuspec @@ -2,7 +2,7 @@ Nancy.Hal - 1.2.2 + 2.0.0-beta0001 Nancy.Hal Dan Barua, Matt Vane, Thomas Eizinger, Richard Bennett Dan Barua @@ -11,6 +11,7 @@ false Provides Hal+JSON media type support for Nancy. + 2.0.0-beta - Build for Nancy 2.0.0-clienteastwood 1.3.0 - Updates Nancy Dependency to 1.4.3 - Adds support for `.haljson` extension 1.2.2 - Fixes UriKind issues on Mono with relative URIs @@ -22,8 +23,9 @@ Copyright 2014-2016 - + + Nancy Hal Hal+JSON Hypermedia - \ No newline at end of file + diff --git a/src/Nancy.Hal/Processors/HalJsonResponseProcessor.cs b/src/Nancy.Hal/Processors/HalJsonResponseProcessor.cs index 5e48389..715fa42 100644 --- a/src/Nancy.Hal/Processors/HalJsonResponseProcessor.cs +++ b/src/Nancy.Hal/Processors/HalJsonResponseProcessor.cs @@ -46,7 +46,7 @@ public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context) { - return new JsonResponse(BuildHypermedia(model, context), serializer) + return new JsonResponse(BuildHypermedia(model, context), serializer, context.Environment) { ContentType = "application/hal+json" }; diff --git a/src/Nancy.Hal/packages.config b/src/Nancy.Hal/packages.config deleted file mode 100644 index 53aeeaf..0000000 --- a/src/Nancy.Hal/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file