|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.EntityFrameworkCore.Utilities; |
| 7 | +using Npgsql.EntityFrameworkCore.PostgreSQL.FunctionalTests; |
| 8 | +using Xunit; |
| 9 | +using Xunit.Abstractions; |
| 10 | + |
| 11 | +namespace Microsoft.EntityFrameworkCore.Query |
| 12 | +{ |
| 13 | + public class QueryBugsTest : IClassFixture<NpgsqlFixture> |
| 14 | + { |
| 15 | + // ReSharper disable once UnusedParameter.Local |
| 16 | + public QueryBugsTest(NpgsqlFixture fixture, ITestOutputHelper testOutputHelper) |
| 17 | + { |
| 18 | + Fixture = fixture; |
| 19 | + //Fixture.TestSqlLoggerFactory.Clear(); |
| 20 | + //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); |
| 21 | + } |
| 22 | + |
| 23 | + protected NpgsqlFixture Fixture { get; } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public async Task Bug278() |
| 27 | + { |
| 28 | + using (var testStore = NpgsqlTestStore.CreateScratch()) |
| 29 | + using (var context = new Bug278Context(new DbContextOptionsBuilder() |
| 30 | + .UseNpgsql(testStore.Connection) |
| 31 | + .Options)) |
| 32 | + { |
| 33 | + context.Database.EnsureCreated(); |
| 34 | + context.Entities.Add(new Bug278Entity { ChannelCodes = new[] { 1, 1 } }); |
| 35 | + context.SaveChanges(); |
| 36 | + |
| 37 | + var actual = await context.Entities.Select(x => new |
| 38 | + { |
| 39 | + Codes = x.ChannelCodes.Select(c => (ChannelCode)c) |
| 40 | + }).FirstOrDefaultAsync(); |
| 41 | + |
| 42 | + Assert.Equal(new[] { ChannelCode.Code, ChannelCode.Code }, actual.Codes); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public enum ChannelCode { Code = 1 } |
| 47 | + |
| 48 | + public class Bug278Entity |
| 49 | + { |
| 50 | + public int Id { get; set; } |
| 51 | + public int[] ChannelCodes { get; set; } |
| 52 | + } |
| 53 | + |
| 54 | + class Bug278Context : DbContext |
| 55 | + { |
| 56 | + public Bug278Context(DbContextOptions options) : base(options) {} |
| 57 | + public DbSet<Bug278Entity> Entities { get; set; } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments