Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge

  • Loading branch information...
commit 28097f370c6aa4ebf1718eba28a2d8b993fd0678 1 parent 5d461ea
@JakeGinnivan authored
View
2  WebApi.Hal.Tests/ResourceLinkerTests.throws_meaningful_exception_when_cannot_find_linker.approved.txt
@@ -1 +1 @@
-No resource linker found for System.Collections.Generic.List<WebApi.Hal.HalResource>
+No resource linker found for System.Collections.Generic.List<WebApi.Hal.Resource>
View
15 WebApi.Hal.Web/Api/BeersController.cs
@@ -1,11 +1,10 @@
using System;
-using System.Collections.Generic;
+using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebApi.Hal.Web.Api.Resources;
using WebApi.Hal.Web.Data;
-using System.Linq;
using WebApi.Hal.Web.Models;
namespace WebApi.Hal.Web.Api
@@ -43,8 +42,8 @@ public BeerListResource GetPage(int page)
new Link {Href = string.Format("/beers?page={0}", page+1), Rel = "next"}
}
};
- resourceLinker.CreateLinks(resourceList);
- return resourceList;
+
+ return resourceLinker.CreateLinks(resourceList);
}
// GET api/beers/5
@@ -85,12 +84,4 @@ public void Delete(int id)
{
}
}
-
- public class BeerListResource : ResourceList<BeerResource>
- {
- public BeerListResource(List<BeerResource> beers) : base(beers)
- {
-
- }
- }
}
View
12 WebApi.Hal.Web/Api/Resources/BeerListResource.cs
@@ -0,0 +1,12 @@
+using System.Collections.Generic;
+
+namespace WebApi.Hal.Web.Api.Resources
+{
+ public class BeerListResource : ResourceList<BeerResource>
+ {
+ public BeerListResource(List<BeerResource> beers) : base(beers)
+ {
+
+ }
+ }
+}
View
24 WebApi.Hal.Web/Database/0001_InitialData.sql
@@ -0,0 +1,24 @@
+INSERT INTO [BeerDatabase].[dbo].[Beers]
+ ([Name])
+ VALUES
+ ('Budweiser'),
+ ('Iron City'),
+ ('Amstel Light'),
+ ('Red Stripe'),
+ ('Smithwicks'),
+ ('Foster''s'),
+ ('Victory'),
+ ('Corona'),
+ ('Ommegang'),
+ ('Chimay'),
+ ('Stella Artois'),
+ ('Paulaner'),
+ ('Newcastle'),
+ ('Samuel Adams'),
+ ('Rogue'),
+ ('Sam Smith''s'),
+ ('Yuengling'),
+ ('Guinness'),
+ ('Sierra Nevada'),
+ ('Westvleteren')
+GO
View
25 WebApi.Hal.Web/DbUpDatabaseInitializer.cs
@@ -0,0 +1,25 @@
+using System.Data.Entity;
+using DbUp;
+using WebApi.Hal.Web.Data;
+
+namespace WebApi.Hal.Web
+{
+ public class DbUpDatabaseInitializer : IDatabaseInitializer<BeerDbContext>
+ {
+ readonly string connectionString;
+
+ public DbUpDatabaseInitializer(string connectionString)
+ {
+ this.connectionString = connectionString;
+ }
+
+ public void InitializeDatabase(BeerDbContext context)
+ {
+ DeployChanges.To
+ .SqlDatabase(connectionString)
+ .WithScriptsEmbeddedInAssembly(typeof(WebApiApplication).Assembly)
+ .Build()
+ .PerformUpgrade();
+ }
+ }
+}
View
13 WebApi.Hal.Web/Global.asax.cs
@@ -1,4 +1,5 @@
using System.Configuration;
+using System.Data.Entity;
using System.Reflection;
using System.Web.Http;
using System.Web.Mvc;
@@ -7,7 +8,6 @@
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
-using DbUp;
using WebApi.Hal.Web.Api;
using WebApi.Hal.Web.Api.Resources;
using WebApi.Hal.Web.App_Start;
@@ -43,21 +43,12 @@ protected void Application_Start()
resourceLinker.AddLinker(new BeerListLinker());
ConfigureContainer(containerBuilder, resourceLinker);
- EnsureDatabaseUpgraded();
+ Database.SetInitializer(new DbUpDatabaseInitializer(connectionString));
container = containerBuilder.Build();
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
- void EnsureDatabaseUpgraded()
- {
- DeployChanges.To
- .SqlDatabase(connectionString)
- .WithScriptsEmbeddedInAssembly(typeof(WebApiApplication).Assembly)
- .Build()
- .PerformUpgrade();
- }
-
private void ConfigureContainer(ContainerBuilder containerBuilder, ResourceLinker resourceLinker)
{
// Register API controllers using assembly scanning.
View
3  WebApi.Hal.Web/WebApi.Hal.Web.csproj
@@ -143,10 +143,12 @@
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
+ <Compile Include="Api\Resources\BeerListResource.cs" />
<Compile Include="Api\Resources\BeerResource.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Api\BeersController.cs" />
<Compile Include="Data\BeerDbContext.cs" />
+ <Compile Include="DbUpDatabaseInitializer.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
@@ -214,6 +216,7 @@
<Content Include="Content\themes\base\minified\jquery.ui.tabs.min.css" />
<Content Include="Content\themes\base\minified\jquery.ui.theme.min.css" />
<EmbeddedResource Include="Data\Scripts\Script001.sql" />
+ <EmbeddedResource Include="Database\0001_InitialData.sql" />
<Content Include="favicon.ico" />
<Content Include="Global.asax" />
<Content Include="Properties\Settings.settings">
View
5 WebApi.Hal.sln
@@ -8,6 +8,11 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi.Hal.Tests", "WebApi.Hal.Tests\WebApi.Hal.Tests.csproj", "{4678CA34-3289-4597-9B2C-93D7257A303A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{3E505D36-07B0-41A2-A184-0C6080D3F89B}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\NuGet.Config = .nuget\NuGet.Config
+ .nuget\NuGet.exe = .nuget\NuGet.exe
+ .nuget\NuGet.targets = .nuget\NuGet.targets
+ EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
View
2  WebApi.Hal/JsonHalMediaTypeFormatter.cs
@@ -37,6 +37,4 @@ public override bool CanWriteType(Type type)
return typeof(Resource).IsAssignableFrom(type);
}
}
-
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.