Skip to content

Commit 7246ca9

Browse files
Maurits MoeysMaurits Moeys
Maurits Moeys
authored and
Maurits Moeys
committed
fix: some acceptance tests
1 parent ab02766 commit 7246ca9

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public virtual IQueryable<TEntity> Select(IQueryable<TEntity> entities, List<str
7575

7676
return entities;
7777
}
78-
78+
7979
/// <inheritdoc />
8080
public virtual IQueryable<TEntity> Filter(IQueryable<TEntity> entities, FilterQuery filterQuery)
8181
{
@@ -87,7 +87,7 @@ public virtual IQueryable<TEntity> Filter(IQueryable<TEntity> entities, FilterQu
8787
return defaultQueryFilter(entities, filterQuery);
8888
}
8989
}
90-
return entities;
90+
return entities.Filter(new AttrFilterQuery(_requestManager, _jsonApiContext.ResourceGraph, filterQuery));
9191
}
9292

9393
/// <inheritdoc />

src/JsonApiDotNetCore/Internal/Contracts/IResourceGraph.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public interface IResourceGraph
8686
/// Was built against an EntityFrameworkCore DbContext ?
8787
/// </summary>
8888
bool UsesDbContext { get; }
89-
List<string> IncludedRelationships { get; set; }
9089

9190
ContextEntity GetEntityFromControllerName(string pathParsed);
9291
}

src/JsonApiDotNetCore/Internal/ResourceGraph.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ internal ResourceGraph(List<ContextEntity> entities, bool usesDbContext, List<Va
5656

5757
/// <inheritdoc />
5858
public bool UsesDbContext { get; }
59-
public List<string> IncludedRelationships { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
6059

6160
/// <inheritdoc />
6261
public ContextEntity GetContextEntity(string entityName)

src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ private void SetHasOneForeignKeyValue(object entity, HasOneAttribute hasOneAttr,
259259
/// store the updated relationship values in this property. For now
260260
/// just assigning null as value, will remove this property later as a whole.
261261
/// see #512
262-
if (convertedValue == null) _jsonApiContext.HasOneRelationshipPointers.Add(hasOneAttr, null);
262+
if (convertedValue == null)
263+
{
264+
_jsonApiContext.RequestManager.GetUpdatedRelationships()[hasOneAttr] = null;
265+
//_jsonApiContext.HasOneRelationshipPointers.Add(hasOneAttr, null);
266+
}
267+
263268
}
264269
}
265270

@@ -284,7 +289,8 @@ private void SetHasOneNavigationPropertyValue(object entity, HasOneAttribute has
284289
/// store the updated relationship values in this property. For now
285290
/// just assigning null as value, will remove this property later as a whole.
286291
/// see #512
287-
_jsonApiContext.HasOneRelationshipPointers.Add(hasOneAttr, null);
292+
_jsonApiContext.RequestManager.GetUpdatedRelationships()[hasOneAttr] = null;
293+
288294
}
289295
}
290296

@@ -316,7 +322,8 @@ private object SetHasManyRelationship(object entity,
316322
/// store the updated relationship values in this property. For now
317323
/// just assigning null as value, will remove this property later as a whole.
318324
/// see #512
319-
_jsonApiContext.HasManyRelationshipPointers.Add(attr, null);
325+
_jsonApiContext.RequestManager.GetUpdatedRelationships()[attr] = null;
326+
320327
}
321328

322329
return entity;

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ protected virtual IQueryable<TEntity> ApplySortAndFilterQuery(IQueryable<TEntity
269269
/// <returns></returns>
270270
protected virtual IQueryable<TEntity> IncludeRelationships(IQueryable<TEntity> entities, List<string> relationships)
271271
{
272-
_resourceGraph.IncludedRelationships = relationships;
273272

274273
foreach (var r in relationships)
275274
{

test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/AttributeFilterTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ public async Task Can_Filter_On_Not_In_Array_Values()
215215
{
216216
// arrange
217217
var context = _fixture.GetService<AppDbContext>();
218+
context.TodoItems.RemoveRange(context.TodoItems);
219+
context.SaveChanges();
218220
var todoItems = _todoItemFaker.Generate(5);
219221
var guids = new List<Guid>();
220222
var notInGuids = new List<Guid>();

test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/CreatingDataTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ public async Task Can_Create_And_Set_HasMany_Relationships()
235235

236236
var context = _fixture.GetService<AppDbContext>();
237237

238-
var owner = new JsonApiDotNetCoreExample.Models.Person();
239-
var todoItem = new TodoItem();
240-
todoItem.Owner = owner;
238+
var owner = new Person();
239+
var todoItem = new TodoItem
240+
{
241+
Owner = owner
242+
};
241243
context.People.Add(owner);
242244
context.TodoItems.Add(todoItem);
243245
await context.SaveChangesAsync();

test/JsonApiDotNetCoreExampleTests/Helpers/Startups/ClientGeneratedIdsStartup.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using JsonApiDotNetCore.Extensions;
77
using System;
88
using JsonApiDotNetCoreExample;
9+
using System.Reflection;
910

1011
namespace JsonApiDotNetCoreExampleTests.Startups
1112
{
@@ -18,25 +19,24 @@ public ClientGeneratedIdsStartup(IHostingEnvironment env)
1819
public override IServiceProvider ConfigureServices(IServiceCollection services)
1920
{
2021
var loggerFactory = new LoggerFactory();
21-
22-
loggerFactory.AddConsole();
23-
24-
services.AddSingleton<ILoggerFactory>(loggerFactory);
25-
26-
services.AddDbContext<AppDbContext>(options =>
27-
{
28-
options.UseNpgsql(GetDbConnectionString());
29-
}, ServiceLifetime.Transient);
30-
31-
services.AddJsonApi<AppDbContext>(opt =>
32-
{
33-
opt.Namespace = "api/v1";
34-
opt.DefaultPageSize = 5;
35-
opt.IncludeTotalRecordCount = true;
36-
opt.AllowClientGeneratedIds = true;
37-
});
22+
loggerFactory.AddConsole(LogLevel.Warning);
23+
var mvcBuilder = services.AddMvcCore();
24+
services
25+
.AddSingleton<ILoggerFactory>(loggerFactory)
26+
.AddDbContext<AppDbContext>(options => options.UseNpgsql(GetDbConnectionString()), ServiceLifetime.Transient)
27+
.AddJsonApi(options => {
28+
options.Namespace = "api/v1";
29+
options.DefaultPageSize = 5;
30+
options.IncludeTotalRecordCount = true;
31+
options.EnableResourceHooks = true;
32+
options.LoadDatabaseValues = true;
33+
options.AllowClientGeneratedIds = true;
34+
},
35+
mvcBuilder,
36+
discovery => discovery.AddAssembly(Assembly.Load(nameof(JsonApiDotNetCoreExample))));
3837

3938
return services.BuildServiceProvider();
39+
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)