Skip to content

Commit aa6faf4

Browse files
committed
test(sparse-fieldsets): validate the use of the Select extension
1 parent 1b8b6cb commit aa6faf4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Threading.Tasks;
2+
using DotNetCoreDocs;
3+
using DotNetCoreDocs.Writers;
4+
using JsonApiDotNetCoreExample;
5+
using Xunit;
6+
using Microsoft.EntityFrameworkCore;
7+
using JsonApiDotNetCoreExample.Data;
8+
using JsonApiDotNetCore.Extensions;
9+
using JsonApiDotNetCoreExample.Models;
10+
using System.Linq;
11+
12+
namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec
13+
{
14+
[Collection("WebHostCollection")]
15+
public class SparseFieldSetTests
16+
{
17+
private DocsFixture<Startup, JsonDocWriter> _fixture;
18+
private readonly AppDbContext _dbContext;
19+
20+
public SparseFieldSetTests(DocsFixture<Startup, JsonDocWriter> fixture)
21+
{
22+
_fixture = fixture;
23+
_dbContext = fixture.GetService<AppDbContext>();
24+
}
25+
26+
[Fact]
27+
public async Task Can_Select_Sparse_Fieldsets()
28+
{
29+
// arrange
30+
var fields = new string[] { "Id", "Description" };
31+
var todoItem = new TodoItem {
32+
Description = "description",
33+
Ordinal = 1
34+
};
35+
_dbContext.TodoItems.Add(todoItem);
36+
await _dbContext.SaveChangesAsync();
37+
38+
// act
39+
var result = await _dbContext
40+
.TodoItems
41+
.Where(t=>t.Id == todoItem.Id)
42+
.Select(fields)
43+
.FirstAsync();
44+
45+
// assert
46+
Assert.Equal(0, result.Ordinal);
47+
Assert.Equal(todoItem.Description, result.Description);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)