Skip to content

Commit

Permalink
Add regression test for issue#13669
Browse files Browse the repository at this point in the history
Resolves #13669
  • Loading branch information
smitpatel committed Aug 27, 2020
1 parent 2b6334e commit 557eaa1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/EFCore.Specification.Tests/CustomConvertersTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,43 @@ protected class OwnedWithConverter
public int Value { get; set; }
}

[ConditionalFact]
public virtual void Id_object_as_entity_key()
{
using var context = CreateContext();
var books = context.Set<Book>().Where(b => b.Id == new BookId(1)).ToList();

Assert.Equal("Book1", Assert.Single(books).Value);
}

public class Book
{
public BookId Id { get; set; }

public string Value { get; set; }

public Book(BookId id)
{
Id = id;
}
}

public class BookId
{
public readonly int Id;

public BookId(int id)
{
Id = id;
}

public override bool Equals(object obj)
=> obj is BookId item && Id == item.Id;

public override int GetHashCode()
=> Id.GetHashCode();
}

public abstract class CustomConvertersFixtureBase : BuiltInDataTypesFixtureBase
{
protected override string StoreName { get; } = "CustomConverters";
Expand Down Expand Up @@ -1172,6 +1209,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
new Parent { Id = 1 },
new Parent { Id = 2 });
});

modelBuilder.Entity<Book>(
b =>
{
b.HasKey(e => e.Id);
b.Property(e => e.Id).HasConversion(
e => e.Id,
e => new BookId(e));
b.HasData(new Book(new BookId(1)) { Value = "Book1" });
});
}

private static class StringToDictionarySerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public virtual void Columns_have_expected_data_types()
Blog.IsVisible ---> [nvarchar] [MaxLength = 1]
Blog.RssUrl ---> [nullable nvarchar] [MaxLength = -1]
Blog.Url ---> [nullable nvarchar] [MaxLength = -1]
Book.Id ---> [int] [Precision = 10 Scale = 0]
Book.Value ---> [nullable nvarchar] [MaxLength = -1]
BuiltInDataTypes.Enum16 ---> [bigint] [Precision = 19 Scale = 0]
BuiltInDataTypes.Enum32 ---> [bigint] [Precision = 19 Scale = 0]
BuiltInDataTypes.Enum64 ---> [bigint] [Precision = 19 Scale = 0]
Expand Down Expand Up @@ -264,6 +266,16 @@ public override void Object_to_string_conversion()
// Return values are not string
}

public override void Id_object_as_entity_key()
{
base.Id_object_as_entity_key();

AssertSql(
@"SELECT [b].[Id], [b].[Value]
FROM [Book] AS [b]
WHERE [b].[Id] = 1");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down

0 comments on commit 557eaa1

Please sign in to comment.