Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToJson with EF Core 8 #165

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class JsonData
public int ID { get; set; }
public string Data { get; set; }
public ChildObject Child { get; set; }
public ChildObject Poco { get; set; }
}

public class ChildObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<JsonData>().Property(j => j.Data).HasColumnType("jsonb");
modelBuilder.Entity<JsonData>().Property(j => j.Child).HasColumnType("jsonb");
modelBuilder.Entity<JsonData>().OwnsOne(j => j.Poco, x => x.ToJson());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1143,14 +1143,17 @@
var timestamp = new DateTime(2021, 2, 3, 4, 5, 6, DateTimeKind.Utc);
var updatedJson = new JsonData
{
Child = new ChildObject { Value = "test", Time = timestamp }
Child = new ChildObject { Value = "test", Time = timestamp },
Poco = new ChildObject { Value = "test", Time = timestamp }
};

dbContext.JsonDatas.Upsert(updatedJson)
.Run();

dbContext.JsonDatas.OrderBy(c => c.ID).Should().SatisfyRespectively(
j => j.Child.Time.Should().Be(timestamp));
dbContext.JsonDatas.OrderBy(c => c.ID).Should().SatisfyRespectively(
j => j.Poco.Time.Should().Be(timestamp));

Check failure on line 1156 in test/FlexLabs.EntityFrameworkCore.Upsert.IntegrationTests/DbTestsBase.cs

View workflow job for this annotation

GitHub Actions / Test Results (Ubuntu)

FlexLabs.EntityFrameworkCore.Upsert.IntegrationTests.DbTests_Postgres ► Upsert_JsonData_Update_ComplexObject

Failed test found in: test/FlexLabs.EntityFrameworkCore.Upsert.IntegrationTests/TestResults/test-results.trx Error: System.NullReferenceException : Object reference not set to an instance of an object.
Raw output
System.NullReferenceException : Object reference not set to an instance of an object.
   at FlexLabs.EntityFrameworkCore.Upsert.Tests.EF.DbTestsBase.<>c__DisplayClass55_0.<Upsert_JsonData_Update_ComplexObject>b__3(JsonData j) in /_/test/FlexLabs.EntityFrameworkCore.Upsert.IntegrationTests/DbTestsBase.cs:line 1156
   at FluentAssertions.Collections.GenericCollectionAssertions`3.CollectFailuresFromInspectors(IEnumerable`1 elementInspectors)
   at FluentAssertions.Collections.GenericCollectionAssertions`3.SatisfyRespectively(IEnumerable`1 expected, String because, Object[] becauseArgs)
   at FluentAssertions.Collections.GenericCollectionAssertions`3.SatisfyRespectively(Action`1[] elementInspectors)
   at FlexLabs.EntityFrameworkCore.Upsert.Tests.EF.DbTestsBase.Upsert_JsonData_Update_ComplexObject() in /_/test/FlexLabs.EntityFrameworkCore.Upsert.IntegrationTests/DbTestsBase.cs:line 1155
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ protected override IContainer BuildContainer()
protected override void ConfigureContextOptions(DbContextOptionsBuilder<TestDbContext> builder)
{
var connectionString = (TestContainer as IDatabaseContainer)?.GetConnectionString()
?? (BuildEnvironment.IsGitHub ? "Server=localhost;Port=5432;Database=testuser;Username=postgres;Password=root" : null);
?? (BuildEnvironment.IsGitHub ? "Server=localhost;Port=54320;Database=testuser;Username=postgres;Password=postgres" : null);
builder.UseNpgsql(new NpgsqlDataSourceBuilder(connectionString)
.EnableDynamicJsonMappings()
.EnableDynamicJson()
.Build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0-rc.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="NSubstitute" Version="4.4.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.15">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading