Skip to content

Commit 566c921

Browse files
author
Chris Santero
committed
add test for getting heterogeneous collections
1 parent e6908e2 commit 566c921

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
using System.Data.Entity;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using System.Web.Http;
6+
using JSONAPI.EntityFramework.Tests.TestWebApp.Models;
7+
8+
namespace JSONAPI.EntityFramework.Tests.TestWebApp.Controllers
9+
{
10+
public class SearchController : ApiController
11+
{
12+
private readonly TestDbContext _dbContext;
13+
14+
public SearchController(TestDbContext dbContext)
15+
{
16+
_dbContext = dbContext;
17+
}
18+
19+
public async Task<IEnumerable<object>> Get(string s)
20+
{
21+
IEnumerable<object> posts = await _dbContext.Posts.Where(p => p.Title.Contains(s)).ToArrayAsync();
22+
IEnumerable<object> comments = await _dbContext.Comments.Where(p => p.Text.Contains(s)).ToArrayAsync();
23+
return posts.Concat(comments);
24+
}
25+
}
26+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
<Content Include="Web.config" />
116116
</ItemGroup>
117117
<ItemGroup>
118+
<Compile Include="Controllers\SearchController.cs" />
118119
<Compile Include="Controllers\CommentsController.cs" />
119120
<Compile Include="Controllers\UserGroupsController.cs" />
120121
<Compile Include="Controllers\UsersController.cs" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"data": [
3+
{
4+
"type": "posts",
5+
"id": "201",
6+
"title": "Post 1",
7+
"content": "Post 1 content",
8+
"created": "2015-01-31T14:00:00+00:00",
9+
"links": {
10+
"author": "401",
11+
"comments": [ "101", "102", "103" ],
12+
"tags": [ "301", "302" ]
13+
}
14+
},
15+
{
16+
"type": "comments",
17+
"id": "101",
18+
"text": "Comment 1",
19+
"created": "2015-01-31T14:30:00+00:00",
20+
"links": {
21+
"author": "403",
22+
"post": "201"
23+
}
24+
}
25+
]
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Net;
2+
using System.Threading.Tasks;
3+
using FluentAssertions;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace JSONAPI.EntityFramework.Tests.Acceptance
7+
{
8+
[TestClass]
9+
public class HeterogeneousTests : AcceptanceTestsBase
10+
{
11+
[TestMethod]
12+
[DeploymentItem(@"Acceptance\Data\Comment.csv", @"Acceptance\Data")]
13+
[DeploymentItem(@"Acceptance\Data\Post.csv", @"Acceptance\Data")]
14+
[DeploymentItem(@"Acceptance\Data\PostTagLink.csv", @"Acceptance\Data")]
15+
[DeploymentItem(@"Acceptance\Data\Tag.csv", @"Acceptance\Data")]
16+
[DeploymentItem(@"Acceptance\Data\User.csv", @"Acceptance\Data")]
17+
public async Task Get()
18+
{
19+
using (var effortConnection = GetEffortConnection())
20+
{
21+
var response = await SubmitGet(effortConnection, "search?s=1");
22+
23+
await AssertResponseContent(response, @"Acceptance\Fixtures\Heterogeneous\Responses\GetSearchResultsResponse.json", HttpStatusCode.OK);
24+
}
25+
}
26+
}
27+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
</CodeAnalysisDependentAssemblyPaths>
111111
</ItemGroup>
112112
<ItemGroup>
113+
<Compile Include="Acceptance\HeterogeneousTests.cs" />
113114
<Compile Include="Acceptance\UserGroupsTests.cs" />
114115
<Compile Include="Acceptance\PostsTests.cs" />
115116
<Compile Include="Acceptance\AcceptanceTestsBase.cs" />
@@ -162,6 +163,7 @@
162163
<EmbeddedResource Include="Acceptance\Fixtures\Posts\Responses\PutWithToManyHomogeneousDataUpdateResponse.json" />
163164
<EmbeddedResource Include="Acceptance\Fixtures\Posts\Responses\PutWithToManyEmptyDataUpdateResponse.json" />
164165
<EmbeddedResource Include="Acceptance\Fixtures\Posts\Requests\PutWithToManyEmptyDataUpdateRequest.json" />
166+
<EmbeddedResource Include="Acceptance\Fixtures\Heterogeneous\Responses\GetSearchResultsResponse.json" />
165167
<None Include="App.Config">
166168
<SubType>Designer</SubType>
167169
</None>

0 commit comments

Comments
 (0)