Skip to content

Commit 0753695

Browse files
author
Bart Koelman
committed
Removed DocumentType, suppressed Include warning, updated DbContext mapping
1 parent 16270b6 commit 0753695

File tree

7 files changed

+16
-45
lines changed

7 files changed

+16
-45
lines changed

test/JsonApiDotNetCoreExampleTests/IntegrationTests/Issue988/DocumentType.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/JsonApiDotNetCoreExampleTests/IntegrationTests/Issue988/DocumentTypesController.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/JsonApiDotNetCoreExampleTests/IntegrationTests/Issue988/Engagement.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public sealed class Engagement : EntityBase<Guid>
1717

1818
// Navigation Properties
1919

20-
[HasMany]
21-
public ICollection<DocumentType> DocumentTypes { get; set; } //= new List<DocumentType>();
22-
2320
[HasMany]
2421
[EagerLoad]
2522
public ICollection<EngagementParty> Parties { get; set; } //= new List<EngagementParty>();
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
using JetBrains.Annotations;
22
using Microsoft.EntityFrameworkCore;
33

4+
// @formatter:wrap_chained_method_calls chop_always
5+
46
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.Issue988
57
{
68
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
79
public sealed class IssueDbContext : DbContext
810
{
911
public DbSet<Engagement> Engagements { get; set; }
1012
public DbSet<EngagementParty> EngagementParties { get; set; }
11-
public DbSet<DocumentType> DocumentTypes { get; set; }
1213

1314
public IssueDbContext(DbContextOptions<IssueDbContext> options)
1415
: base(options)
1516
{
1617
}
18+
19+
protected override void OnModelCreating(ModelBuilder builder)
20+
{
21+
builder.Entity<EngagementParty>()
22+
.HasOne(engagementParty => engagementParty.Engagement)
23+
.WithMany(engagement => engagement.Parties)
24+
.IsRequired()
25+
.OnDelete(DeleteBehavior.Restrict);
26+
}
1727
}
1828
}
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System;
22
using Bogus;
3-
using JetBrains.Annotations;
43
using TestBuildingBlocks;
54

65
// @formatter:wrap_chained_method_calls chop_always
76
// @formatter:keep_existing_linebreaks true
87

98
namespace JsonApiDotNetCoreExampleTests.IntegrationTests.Issue988
109
{
11-
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
1210
internal sealed class IssueFakers : FakerContainer
1311
{
1412
private readonly Lazy<Faker<Engagement>> _lazyEngagementFaker = new Lazy<Faker<Engagement>>(() =>
@@ -22,13 +20,7 @@ internal sealed class IssueFakers : FakerContainer
2220
.RuleFor(party => party.Role, faker => faker.Lorem.Word())
2321
.RuleFor(party => party.ShortName, faker => faker.Lorem.Word()));
2422

25-
private readonly Lazy<Faker<DocumentType>> _lazyDocumentTypeFaker = new Lazy<Faker<DocumentType>>(() =>
26-
new Faker<DocumentType>()
27-
.UseSeed(GetFakerSeed())
28-
.RuleFor(documentType => documentType.Description, faker => faker.Lorem.Sentence()));
29-
3023
public Faker<Engagement> Engagement => _lazyEngagementFaker.Value;
3124
public Faker<EngagementParty> EngagementParty => _lazyEngagementPartyFaker.Value;
32-
public Faker<DocumentType> DocumentType => _lazyDocumentTypeFaker.Value;
3325
}
3426
}

test/JsonApiDotNetCoreExampleTests/IntegrationTests/Issue988/IssueTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public IssueTests(ExampleIntegrationTestContext<TestableStartup<IssueDbContext>,
2424

2525
testContext.UseController<EngagementsController>();
2626
testContext.UseController<EngagementPartiesController>();
27-
testContext.UseController<DocumentTypesController>();
2827

2928
testContext.ConfigureServicesAfterStartup(services =>
3029
{
@@ -58,7 +57,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
5857
responseDocument.Included.Should().BeNull();
5958
}
6059

61-
[Fact(Skip = "Fails in EF Core with: Unable to find navigation 'FirstParties' specified in string based include path 'FirstParties'.")]
60+
[Fact]
6261
public async Task Can_get_primary_resource_by_ID_with_includes()
6362
{
6463
// Arrange
@@ -183,7 +182,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
183182
responseDocument.Included.Should().BeNull();
184183
}
185184

186-
[Fact(Skip = "Fails in EF Core with: Unable to find navigation 'FirstParties' specified in string based include path 'FirstParties'.")]
185+
[Fact]
187186
public async Task Can_get_unmapped_secondary_resources_by_ID()
188187
{
189188
// Arrange

test/TestBuildingBlocks/BaseIntegrationTestContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.AspNetCore.Mvc.Testing;
77
using Microsoft.EntityFrameworkCore;
8+
using Microsoft.EntityFrameworkCore.Diagnostics;
89
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Extensions.Hosting;
1011
using Microsoft.Extensions.Logging;
@@ -74,6 +75,8 @@ private WebApplicationFactory<TRemoteStartup> CreateFactory()
7475
options.UseNpgsql(dbConnectionString);
7576
options.EnableSensitiveDataLogging();
7677
options.EnableDetailedErrors();
78+
79+
options.ConfigureWarnings(builder => builder.Ignore(CoreEventId.InvalidIncludePathError));
7780
});
7881
});
7982

0 commit comments

Comments
 (0)