Skip to content

Commit ec1cda6

Browse files
author
Chris Santero
committed
rearrange acceptance tests
1 parent 41d2b95 commit ec1cda6

68 files changed

Lines changed: 571 additions & 231 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{64ABE648-EFCB-46EE-9E1A-E163F52BF372}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>JSONAPI.Autofac.EntityFramework</RootNamespace>
11+
<AssemblyName>JSONAPI.Autofac.EntityFramework</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="Autofac">
36+
<HintPath>..\packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Xml" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="JsonApiAutofacConfigurationExtensions.cs" />
48+
<Compile Include="JsonApiAutofacEntityFrameworkModule.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="packages.config" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<ProjectReference Include="..\JSONAPI.Autofac\JSONAPI.Autofac.csproj">
56+
<Project>{af7861f3-550b-4f70-a33e-1e5f48d39333}</Project>
57+
<Name>JSONAPI.Autofac</Name>
58+
</ProjectReference>
59+
<ProjectReference Include="..\JSONAPI.EntityFramework\JSONAPI.EntityFramework.csproj">
60+
<Project>{e906356c-93f6-41f6-9a0d-73b8a99aa53c}</Project>
61+
<Name>JSONAPI.EntityFramework</Name>
62+
</ProjectReference>
63+
<ProjectReference Include="..\JSONAPI\JSONAPI.csproj">
64+
<Project>{52b19fd6-efaa-45b5-9c3e-a652e27608d1}</Project>
65+
<Name>JSONAPI</Name>
66+
</ProjectReference>
67+
</ItemGroup>
68+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
69+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
70+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
71+
<PropertyGroup>
72+
<ErrorText>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}.</ErrorText>
73+
</PropertyGroup>
74+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
75+
</Target>
76+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
77+
Other similar extension points exist, see Microsoft.Common.targets.
78+
<Target Name="BeforeBuild">
79+
</Target>
80+
<Target Name="AfterBuild">
81+
</Target>
82+
-->
83+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Autofac.Core;
2+
3+
namespace JSONAPI.Autofac.EntityFramework
4+
{
5+
public static class JsonApiAutofacConfigurationExtensions
6+
{
7+
public static IModule GetEntityFrameworkAutofacModule(this JsonApiAutofacConfiguration jsonApiAutofacConfiguration)
8+
{
9+
return new JsonApiAutofacEntityFrameworkModule();
10+
}
11+
}
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Autofac;
2+
using JSONAPI.ActionFilters;
3+
using JSONAPI.EntityFramework;
4+
using JSONAPI.EntityFramework.ActionFilters;
5+
using JSONAPI.EntityFramework.Http;
6+
7+
namespace JSONAPI.Autofac.EntityFramework
8+
{
9+
public class JsonApiAutofacEntityFrameworkModule : Module
10+
{
11+
protected override void Load(ContainerBuilder builder)
12+
{
13+
builder.RegisterType<AsynchronousEnumerationTransformer>().As<IQueryableEnumerationTransformer>();
14+
builder.RegisterGeneric(typeof(EntityFrameworkPayloadMaterializer<>))
15+
.AsImplementedInterfaces();
16+
builder.RegisterType<EntityFrameworkResourceObjectMaterializer>()
17+
.As<IEntityFrameworkResourceObjectMaterializer>();
18+
}
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("JSONAPI.Autofac.EntityFramework")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("JSONAPI.Autofac.EntityFramework")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("5c85a230-f640-43cf-ae30-b685d237a6dc")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Autofac" version="3.5.2" targetFramework="net45" />
4+
</packages>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Data.Entity;
3+
using System.Threading.Tasks;
4+
using JSONAPI.Core;
5+
using JSONAPI.EntityFramework.Tests.TestWebApp.Models;
6+
using JSONAPI.Payload;
7+
8+
namespace JSONAPI.EntityFramework.Tests.TestWebApp
9+
{
10+
public class CustomEntityFrameworkResourceObjectMaterializer : EntityFrameworkResourceObjectMaterializer
11+
{
12+
public CustomEntityFrameworkResourceObjectMaterializer(DbContext dbContext, IResourceTypeRegistry registry) : base(dbContext, registry)
13+
{
14+
}
15+
16+
protected override Task SetIdForNewResource(IResourceObject resourceObject, object newObject, IResourceTypeRegistration typeRegistration)
17+
{
18+
// This is to facilitate testing creation of a resource with a server-provided ID
19+
if (typeRegistration.Type == typeof (Post) && String.IsNullOrEmpty(resourceObject.Id))
20+
{
21+
((Post) newObject).Id = "230";
22+
return Task.FromResult(0);
23+
}
24+
25+
return base.SetIdForNewResource(resourceObject, newObject, typeRegistration);
26+
}
27+
}
28+
}

JSONAPI.EntityFramework.Tests.TestWebApp/JSONAPI.EntityFramework.Tests.TestWebApp.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<Compile Include="Controllers\UsersController.cs" />
127127
<Compile Include="Controllers\TagsController.cs" />
128128
<Compile Include="Controllers\PostsController.cs" />
129+
<Compile Include="CustomEntityFrameworkResourceObjectMaterializer.cs" />
129130
<Compile Include="Models\Comment.cs" />
130131
<Compile Include="Models\Language.cs" />
131132
<Compile Include="Models\LanguageUserLink.cs" />
@@ -141,6 +142,10 @@
141142
<Compile Include="Startup.cs" />
142143
</ItemGroup>
143144
<ItemGroup>
145+
<ProjectReference Include="..\JSONAPI.Autofac.EntityFramework\JSONAPI.Autofac.EntityFramework.csproj">
146+
<Project>{64abe648-efcb-46ee-9e1a-e163f52bf372}</Project>
147+
<Name>JSONAPI.Autofac.EntityFramework</Name>
148+
</ProjectReference>
144149
<ProjectReference Include="..\JSONAPI.Autofac\JSONAPI.Autofac.csproj">
145150
<Project>{af7861f3-550b-4f70-a33e-1e5f48d39333}</Project>
146151
<Name>JSONAPI.Autofac</Name>

JSONAPI.EntityFramework.Tests.TestWebApp/Startup.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Autofac;
88
using Autofac.Integration.WebApi;
99
using JSONAPI.Autofac;
10+
using JSONAPI.Autofac.EntityFramework;
1011
using JSONAPI.Core;
1112
using JSONAPI.EntityFramework.Http;
1213
using JSONAPI.EntityFramework.Tests.TestWebApp.Models;
@@ -62,14 +63,16 @@ public void Configuration(IAppBuilder app)
6263
configuration.RegisterResourceType(typeof(User));
6364
configuration.RegisterResourceType(typeof(UserGroup));
6465
var module = configuration.GetAutofacModule();
66+
var efModule = configuration.GetEntityFrameworkAutofacModule();
6567

6668
var containerBuilder = new ContainerBuilder();
6769
containerBuilder.RegisterModule(module);
68-
containerBuilder.RegisterGeneric(typeof (EntityFrameworkPayloadMaterializer<>))
69-
.AsImplementedInterfaces();
70+
containerBuilder.RegisterModule(efModule);
7071
containerBuilder.Register(c => HttpContext.Current.GetOwinContext()).As<IOwinContext>();
7172
containerBuilder.Register(c => c.Resolve<IOwinContext>().Get<TestDbContext>(DbContextKey)).AsSelf().As<DbContext>();
7273
containerBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly());
74+
containerBuilder.RegisterType<CustomEntityFrameworkResourceObjectMaterializer>()
75+
.As<IEntityFrameworkResourceObjectMaterializer>();
7376
var container = containerBuilder.Build();
7477

7578
var httpConfig = new HttpConfiguration
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Linq;
3+
using System.Net;
4+
using System.Threading.Tasks;
5+
using FluentAssertions;
6+
using JSONAPI.EntityFramework.Tests.TestWebApp.Models;
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
9+
namespace JSONAPI.EntityFramework.Tests.Acceptance
10+
{
11+
[TestClass]
12+
public class PostsTests : AcceptanceTestsBase
13+
{
14+
[TestMethod]
15+
[DeploymentItem(@"Acceptance\Data\Comment.csv", @"Acceptance\Data")]
16+
[DeploymentItem(@"Acceptance\Data\Post.csv", @"Acceptance\Data")]
17+
[DeploymentItem(@"Acceptance\Data\PostTagLink.csv", @"Acceptance\Data")]
18+
[DeploymentItem(@"Acceptance\Data\Tag.csv", @"Acceptance\Data")]
19+
[DeploymentItem(@"Acceptance\Data\User.csv", @"Acceptance\Data")]
20+
public async Task Post_with_client_provided_id()
21+
{
22+
using (var effortConnection = GetEffortConnection())
23+
{
24+
var response = await SubmitPost(effortConnection, "posts", @"Acceptance\Fixtures\CreatingResources\Requests\Post_with_client_provided_id_Request.json");
25+
26+
await AssertResponseContent(response, @"Acceptance\Fixtures\CreatingResources\Responses\Post_with_client_provided_id_Response.json", HttpStatusCode.OK);
27+
28+
using (var dbContext = new TestDbContext(effortConnection, false))
29+
{
30+
var allPosts = dbContext.Posts.ToArray();
31+
allPosts.Length.Should().Be(5);
32+
var actualPost = allPosts.First(t => t.Id == "205");
33+
actualPost.Id.Should().Be("205");
34+
actualPost.Title.Should().Be("Added post");
35+
actualPost.Content.Should().Be("Added post content");
36+
actualPost.Created.Should().Be(new DateTimeOffset(2015, 03, 11, 04, 31, 0, new TimeSpan(0)));
37+
actualPost.AuthorId.Should().Be("401");
38+
}
39+
}
40+
}
41+
42+
[TestMethod]
43+
[DeploymentItem(@"Acceptance\Data\Comment.csv", @"Acceptance\Data")]
44+
[DeploymentItem(@"Acceptance\Data\Post.csv", @"Acceptance\Data")]
45+
[DeploymentItem(@"Acceptance\Data\PostTagLink.csv", @"Acceptance\Data")]
46+
[DeploymentItem(@"Acceptance\Data\Tag.csv", @"Acceptance\Data")]
47+
[DeploymentItem(@"Acceptance\Data\User.csv", @"Acceptance\Data")]
48+
public async Task Post_with_empty_id()
49+
{
50+
using (var effortConnection = GetEffortConnection())
51+
{
52+
var response = await SubmitPost(effortConnection, "posts", @"Acceptance\Fixtures\CreatingResources\Requests\Post_with_empty_id_Request.json");
53+
54+
await AssertResponseContent(response, @"Acceptance\Fixtures\CreatingResources\Responses\Post_with_empty_id_Response.json", HttpStatusCode.OK);
55+
56+
using (var dbContext = new TestDbContext(effortConnection, false))
57+
{
58+
var allPosts = dbContext.Posts.ToArray();
59+
allPosts.Length.Should().Be(5);
60+
var actualPost = allPosts.First(t => t.Id == "230");
61+
actualPost.Id.Should().Be("230");
62+
actualPost.Title.Should().Be("New post");
63+
actualPost.Content.Should().Be("The server generated my ID");
64+
actualPost.Created.Should().Be(new DateTimeOffset(2015, 04, 13, 12, 09, 0, new TimeSpan(0, 3, 0, 0)));
65+
actualPost.AuthorId.Should().Be("401");
66+
}
67+
}
68+
}
69+
}
70+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Linq;
2+
using System.Net;
3+
using System.Threading.Tasks;
4+
using FluentAssertions;
5+
using JSONAPI.EntityFramework.Tests.TestWebApp.Models;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
namespace JSONAPI.EntityFramework.Tests.Acceptance
9+
{
10+
[TestClass]
11+
public class DeletingResourcesTests : AcceptanceTestsBase
12+
{
13+
[TestMethod]
14+
[DeploymentItem(@"Acceptance\Data\Comment.csv", @"Acceptance\Data")]
15+
[DeploymentItem(@"Acceptance\Data\Post.csv", @"Acceptance\Data")]
16+
[DeploymentItem(@"Acceptance\Data\PostTagLink.csv", @"Acceptance\Data")]
17+
[DeploymentItem(@"Acceptance\Data\Tag.csv", @"Acceptance\Data")]
18+
[DeploymentItem(@"Acceptance\Data\User.csv", @"Acceptance\Data")]
19+
public async Task Delete()
20+
{
21+
using (var effortConnection = GetEffortConnection())
22+
{
23+
var response = await SubmitDelete(effortConnection, "posts/203");
24+
25+
var responseContent = await response.Content.ReadAsStringAsync();
26+
responseContent.Should().Be("");
27+
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
28+
29+
using (var dbContext = new TestDbContext(effortConnection, false))
30+
{
31+
var allTodos = dbContext.Posts.ToArray();
32+
allTodos.Length.Should().Be(3);
33+
var actualTodo = allTodos.FirstOrDefault(t => t.Id == "203");
34+
actualTodo.Should().BeNull();
35+
}
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)