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

Test: Update Sql assertion in OwnedQuerySqlServerTest #20353

Merged
merged 2 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 11 additions & 7 deletions test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
ab.IndexedProperty<string>("AddressLine");
ab.IndexedProperty(typeof(int), "ZipCode");
ab.HasData(
new { OwnedPersonId = 1, AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 },
new { OwnedPersonId = 2, AddressLine = "7 Church Dr.", ZipCode = 28655 },
new { OwnedPersonId = 3, AddressLine = "72 Hickory Rd.", ZipCode = 07728 },
new { OwnedPersonId = 4, AddressLine = "28 Strawberry St.", ZipCode = 19053 });
new { OwnedPersonId = 1, PlaceType = "Land", AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 },
new { OwnedPersonId = 2, PlaceType = "Land", AddressLine = "7 Church Dr.", ZipCode = 28655 },
new { OwnedPersonId = 3, PlaceType = "Land", AddressLine = "72 Hickory Rd.", ZipCode = 07728 },
new { OwnedPersonId = 4, PlaceType = "Land", AddressLine = "28 Strawberry St.", ZipCode = 19053 });

ab.OwnsOne(
a => a.Country, cb =>
Expand Down Expand Up @@ -542,8 +542,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
eb.OwnsOne(
p => p.BranchAddress, ab =>
{
ab.IndexedProperty<string>("BranchName");
ab.HasData(
new { BranchId = 2 }, new { BranchId = 3 });
new { BranchId = 2, PlaceType = "Land", BranchName = "BranchA" },
new { BranchId = 3, PlaceType = "Land", BranchName = "BranchB" });

ab.OwnsOne(
a => a.Country, cb =>
Expand Down Expand Up @@ -574,8 +576,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
eb.OwnsOne(
p => p.LeafAAddress, ab =>
{
ab.IndexedProperty<int>("LeafType");
ab.HasData(
new { LeafAId = 3 });
new { LeafAId = 3, PlaceType = "Land", LeafType = 1 });

ab.OwnsOne(
a => a.Country, cb =>
Expand All @@ -600,8 +603,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
eb.OwnsOne(
p => p.LeafBAddress, ab =>
{
ab.IndexedProperty<string>("LeafBType");
ab.HasData(
new { LeafBId = 4 });
new { LeafBId = 4, PlaceType = "Land", LeafBType = "Green" });

ab.OwnsOne(
a => a.Country, cb =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ protected override QueryAsserter<PoolableDbContext> CreateQueryAsserter(
entitySorters,
entityAsserters,
CanExecuteQueryString);

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
base.OnModelCreating(modelBuilder, context);

// TODO: See issue#20334
//modelBuilder.Entity<OwnedPerson>().OwnsOne(e => e.PersonAddress).Property(e => e.PlaceType).HasColumnName("PlaceType");
//modelBuilder.Entity<Branch>().OwnsOne(e => e.BranchAddress).Property(e => e.PlaceType).HasColumnName("PlaceType");
//modelBuilder.Entity<LeafA>().OwnsOne(e => e.LeafAAddress).Property(e => e.PlaceType).HasColumnName("PlaceType");
//modelBuilder.Entity<LeafB>().OwnsOne(e => e.LeafBAddress).Property(e => e.PlaceType).HasColumnName("PlaceType");
}
}
}
}
111 changes: 71 additions & 40 deletions test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public virtual Task Query_for_branch_type_loads_all_owned_navs(bool async)
ss => ss.Set<Branch>());
}

[ConditionalTheory(Skip = "Issue#20336")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Query_for_branch_type_loads_all_owned_navs_tracking(bool async)
{
Expand Down Expand Up @@ -408,7 +408,7 @@ public virtual async Task Preserve_includes_when_applying_skip_take_after_anonym
}
}

[ConditionalTheory(Skip = "Issue#20336")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Unmapped_property_projection_loads_owned_navigations(bool async)
{
Expand Down Expand Up @@ -750,6 +750,10 @@ private static void AssertAddress(OwnedAddress expectedAddress, OwnedAddress act
{
Assert.Equal(expectedAddress["AddressLine"], actualAddress["AddressLine"]);
Assert.Equal(expectedAddress["ZipCode"], actualAddress["ZipCode"]);
Assert.Equal(expectedAddress["BranchName"], actualAddress["BranchName"]);
Assert.Equal(expectedAddress["LeafType"], actualAddress["LeafType"]);
Assert.Equal(expectedAddress["LeafBType"], actualAddress["LeafBType"]);
Assert.Equal(expectedAddress.PlaceType, actualAddress.PlaceType);
Assert.Equal(expectedAddress.Country.PlanetId, actualAddress.Country.PlanetId);
Assert.Equal(expectedAddress.Country.Name, actualAddress.Country.Name);
}
Expand Down Expand Up @@ -1042,10 +1046,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
ab.IndexedProperty<string>("AddressLine");
ab.IndexedProperty(typeof(int), "ZipCode");
ab.HasData(
new { OwnedPersonId = 1, AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 },
new { OwnedPersonId = 2, AddressLine = "7 Church Dr.", ZipCode = 28655 },
new { OwnedPersonId = 3, AddressLine = "72 Hickory Rd.", ZipCode = 07728 },
new { OwnedPersonId = 4, AddressLine = "28 Strawberry St.", ZipCode = 19053 });
new { OwnedPersonId = 1, PlaceType = "Land", AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 },
new { OwnedPersonId = 2, PlaceType = "Land", AddressLine = "7 Church Dr.", ZipCode = 28655 },
new { OwnedPersonId = 3, PlaceType = "Land", AddressLine = "72 Hickory Rd.", ZipCode = 07728 },
new { OwnedPersonId = 4, PlaceType = "Land", AddressLine = "28 Strawberry St.", ZipCode = 19053 });

ab.OwnsOne(
a => a.Country, cb =>
Expand Down Expand Up @@ -1103,8 +1107,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
eb.OwnsOne(
p => p.BranchAddress, ab =>
{
ab.IndexedProperty<string>("BranchName");
ab.HasData(
new { BranchId = 2 }, new { BranchId = 3 });
new { BranchId = 2, PlaceType = "Land", BranchName = "BranchA" },
new { BranchId = 3, PlaceType = "Land", BranchName = "BranchB" });

ab.OwnsOne(
a => a.Country, cb =>
Expand Down Expand Up @@ -1136,8 +1142,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
eb.OwnsOne(
p => p.LeafAAddress, ab =>
{
ab.IndexedProperty<int>("LeafType");

ab.HasData(
new { LeafAId = 3 });
new { LeafAId = 3, PlaceType = "Land", LeafType = 1 });

ab.OwnsOne(
a => a.Country, cb =>
Expand Down Expand Up @@ -1166,8 +1174,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
eb.OwnsOne(
p => p.LeafBAddress, ab =>
{
ab.IndexedProperty<string>("LeafBType");
ab.HasData(
new { LeafBId = 4 });
new { LeafBId = 4, PlaceType = "Land", LeafBType = "Green" });

ab.OwnsOne(
a => a.Country, cb =>
Expand Down Expand Up @@ -1354,7 +1363,7 @@ private static IReadOnlyList<Moon> CreateMoons()

private static IReadOnlyList<OwnedPerson> CreateOwnedPeople()
{
var personAddress1 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
var personAddress1 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
personAddress1["AddressLine"] = "804 S. Lakeshore Road";
personAddress1["ZipCode"] = 38654;
var ownedPerson1 = new OwnedPerson
Expand All @@ -1364,37 +1373,46 @@ private static IReadOnlyList<OwnedPerson> CreateOwnedPeople()
};
ownedPerson1["Name"] = "Mona Cy";

var personAddress2 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
var personAddress2 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
personAddress2["AddressLine"] = "7 Church Dr.";
personAddress2["ZipCode"] = 28655;
var branchAddress2 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } };
branchAddress2["BranchName"] = "BranchA";

var ownedPerson2 = new Branch
{
Id = 2,
PersonAddress = personAddress2,
BranchAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } }
BranchAddress = branchAddress2
};
ownedPerson2["Name"] = "Antigonus Mitul";

var personAddress3 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
var personAddress3 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
personAddress3["AddressLine"] = "72 Hickory Rd.";
personAddress3["ZipCode"] = 07728;
var branchAddress3 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } };
branchAddress3["BranchName"] = "BranchB";
var leafAAddress3 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Mexico", PlanetId = 1 } };
leafAAddress3["LeafType"] = 1;
var ownedPerson3 = new LeafA
{
Id = 3,
PersonAddress = personAddress3,
BranchAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } },
LeafAAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Mexico", PlanetId = 1 } }
BranchAddress = branchAddress3,
LeafAAddress = leafAAddress3
};
ownedPerson3["Name"] = "Madalena Morana";

var personAddress4 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
var personAddress4 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } };
personAddress4["AddressLine"] = "28 Strawberry St.";
personAddress4["ZipCode"] = 19053;
var leafBAddress4 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Panama", PlanetId = 1 } };
leafBAddress4["LeafBType"] = "Green";
var ownedPerson4 = new LeafB
{
Id = 4,
PersonAddress = personAddress4,
LeafBAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Panama", PlanetId = 1 } }
LeafBAddress = leafBAddress4
};
ownedPerson4["Name"] = "Vanda Waldemar";

Expand Down Expand Up @@ -1474,37 +1492,50 @@ protected class OwnedAddress
{
private string _addressLine;
private int _zipCode;
private string _branchName;
private int _leafAType;
private string _leafBType;

public string PlaceType { get; set; }
public OwnedCountry Country { get; set; }
public object this[string name]
{
get
get => name switch
{
if (string.Equals(name, "AddressLine", StringComparison.Ordinal))
{
return _addressLine;
}

if (string.Equals(name, "ZipCode", StringComparison.Ordinal))
{
return _zipCode;
}

throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}.");
}
"AddressLine" => _addressLine,
"ZipCode" => _zipCode,
"BranchName" => _branchName,
"LeafType" => _leafAType,
"LeafBType" => _leafBType,
_ => throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}."),
};

set
{
if (string.Equals(name, "AddressLine", StringComparison.Ordinal))
{
_addressLine = (string)value;
}
else if (string.Equals(name, "ZipCode", StringComparison.Ordinal))
{
_zipCode = (int)value;
}
else
switch (name)
{
throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}.");
case "AddressLine":
_addressLine = (string)value;
break;

case "ZipCode":
_zipCode = (int)value;
break;

case "BranchName":
_branchName = (string)value;
break;

case "LeafType":
_leafAType = (int)value;
break;

case "LeafBType":
_leafBType = (string)value;
break;

default:
throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}.");
}
}
}
Expand Down
Loading