Skip to content

Commit

Permalink
Small fix to JSON update tests - we were not adding converters to som…
Browse files Browse the repository at this point in the history
…e of the enum properties with converters, which resulted in missing coverage.
  • Loading branch information
maumar committed Apr 3, 2023
1 parent bdd9846 commit 5122d0e
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
b.ToJson();
b.Property(x => x.TestMaxLengthString).HasMaxLength(5);
b.Property(x => x.TestDecimal).HasPrecision(18, 3);
b.Property(x => x.TestEnumWithIntConverter).HasConversion<int>();
b.Property(x => x.TestNullableEnumWithIntConverter).HasConversion<int>();
b.Property(x => x.TestNullableEnumWithConverterThatHandlesNulls).HasConversion(
new ValueConverter<JsonEnum?, string>(
x => x == null
? "Null"
: x == JsonEnum.One
? "One"
: x == JsonEnum.Two
? "Two"
: x == JsonEnum.Three
? "Three"
: "INVALID",
x => x == "One"
? JsonEnum.One
: x == "Two"
? JsonEnum.Two
: x == "Three"
? JsonEnum.Three
: null,
convertsNulls: true));
});

modelBuilder.Entity<JsonEntityConverters>().Property(x => x.Id).ValueGeneratedNever();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,57 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
x => x.Reference, b =>
{
b.ToJson();
b.Property(x => x.TestMaxLengthString).HasMaxLength(5);
b.Property(x => x.TestDecimal).HasPrecision(18, 3);
b.Property(x => x.TestEnumWithIntConverter).HasConversion<int>();
b.Property(x => x.TestNullableEnumWithIntConverter).HasConversion<int>();
b.Property(x => x.TestNullableEnumWithConverterThatHandlesNulls).HasConversion(
new ValueConverter<JsonEnum?, string>(
x => x == null
? "Null"
: x == JsonEnum.One
? "One"
: x == JsonEnum.Two
? "Two"
: x == JsonEnum.Three
? "Three"
: "INVALID",
x => x == "One"
? JsonEnum.One
: x == "Two"
? JsonEnum.Two
: x == "Three"
? JsonEnum.Three
: null,
convertsNulls: true));
});
modelBuilder.Entity<JsonEntityAllTypes>().OwnsMany(
x => x.Collection, b =>
{
b.ToJson();
b.Property(x => x.TestMaxLengthString).HasMaxLength(5);
b.Property(x => x.TestDecimal).HasPrecision(18, 3);
b.Property(x => x.TestEnumWithIntConverter).HasConversion<int>();
b.Property(x => x.TestNullableEnumWithIntConverter).HasConversion<int>();
b.Property(x => x.TestNullableEnumWithConverterThatHandlesNulls).HasConversion(
new ValueConverter<JsonEnum?, string>(
x => x == null
? "Null"
: x == JsonEnum.One
? "One"
: x == JsonEnum.Two
? "Two"
: x == JsonEnum.Three
? "Three"
: "INVALID",
x => x == "One"
? JsonEnum.One
: x == "Two"
? JsonEnum.Two
: x == "Three"
? JsonEnum.Three
: null,
convertsNulls: true));
});

modelBuilder.Entity<JsonEntityConverters>().Property(x => x.Id).ValueGeneratedNever();
Expand Down
Loading

0 comments on commit 5122d0e

Please sign in to comment.