Skip to content

Commit

Permalink
MQ: Specify facets and store types in Northwind model
Browse files Browse the repository at this point in the history
Fixes #29087
  • Loading branch information
ajcvickers committed Oct 6, 2022
1 parent d8af3f5 commit 00b91c6
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,4 @@ public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder build

protected override bool ShouldLogCategory(string logCategory)
=> logCategory == DbLoggerCategory.Query.Name;

protected override Type ContextType
=> typeof(NorthwindRelationalContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Microsoft.EntityFrameworkCore.TestModels.Northwind;

public class NorthwindRelationalContext : NorthwindContext
public abstract class NorthwindRelationalContext : NorthwindContext
{
public NorthwindRelationalContext(DbContextOptions options)
protected NorthwindRelationalContext(DbContextOptions options)
: base(options)
{
}
Expand Down
24 changes: 24 additions & 0 deletions test/EFCore.Specification.Tests/TestModels/Northwind/Customer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

Expand All @@ -20,16 +21,39 @@ public Customer(DbContext context, ILazyLoader lazyLoader, string customerID)
CustomerID = customerID;
}

[MaxLength(5)]
[Required]
public string CustomerID { get; set; }

[MaxLength(40)]
[Required]
public string CompanyName { get; set; }

[MaxLength(30)]
public string ContactName { get; set; }

[MaxLength(30)]
public string ContactTitle { get; set; }

[MaxLength(60)]
public string Address { get; set; }

[MaxLength(15)]
public string City { get; set; }

[MaxLength(15)]
public string Region { get; set; }

[MaxLength(10)]
public string PostalCode { get; set; }

[MaxLength(15)]
public string Country { get; set; }

[MaxLength(24)]
public string Phone { get; set; }

[MaxLength(24)]
public string Fax { get; set; }

public virtual List<Order> Orders { get; set; }
Expand Down
30 changes: 30 additions & 0 deletions test/EFCore.Specification.Tests/TestModels/Northwind/Employee.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Microsoft.EntityFrameworkCore.TestModels.Northwind;

public class Employee
Expand All @@ -13,22 +16,49 @@ public uint EmployeeID
set => _employeeId = value;
}

[MaxLength(20)]
[Required]
public string LastName { get; set; }

[MaxLength(10)]
[Required]
public string FirstName { get; set; }

[MaxLength(30)]
public string Title { get; set; }

[MaxLength(25)]
public string TitleOfCourtesy { get; set; }

public DateTime? BirthDate { get; set; }
public DateTime? HireDate { get; set; }

[MaxLength(60)]
public string Address { get; set; }

[MaxLength(15)]
public string City { get; set; }

[MaxLength(15)]
public string Region { get; set; }

[MaxLength(10)]
public string PostalCode { get; set; }

[MaxLength(15)]
public string Country { get; set; }

[MaxLength(24)]
public string HomePhone { get; set; }

[MaxLength(4)]
public string Extension { get; set; }

public byte[] Photo { get; set; }
public string Notes { get; set; }
public uint? ReportsTo { get; set; }

[MaxLength(255)]
public string PhotoPath { get; set; }

public Employee Manager { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,24 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
e.HasOne(e1 => e1.Manager).WithMany().HasForeignKey(e1 => e1.ReportsTo);
});

modelBuilder.Entity<Customer>(
e =>
{
e.HasIndex(e => e.City);
e.HasIndex(e => e.CompanyName);
e.HasIndex(e => e.PostalCode);
e.HasIndex(e => e.Region);
});

modelBuilder.Entity<Product>(
e =>
{
e.Ignore(p => p.CategoryID);
e.Ignore(p => p.QuantityPerUnit);
e.Ignore(p => p.ReorderLevel);
e.Ignore(p => p.UnitsOnOrder);
e.HasIndex(e => e.ProductName);
});

modelBuilder.Entity<Order>(
Expand All @@ -62,6 +73,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
e.Ignore(o => o.ShipRegion);
e.Ignore(o => o.ShipVia);
e.Ignore(o => o.ShippedDate);
e.HasIndex(e => e.OrderDate);
});

modelBuilder.Entity<OrderDetail>(
Expand Down
15 changes: 15 additions & 0 deletions test/EFCore.Specification.Tests/TestModels/Northwind/Order.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.DataAnnotations;

namespace Microsoft.EntityFrameworkCore.TestModels.Northwind;

public class Order
Expand All @@ -13,18 +15,31 @@ public int OrderID
set => _orderId = value;
}

[MaxLength(5)]
public string CustomerID { get; set; }
public uint? EmployeeID { get; set; }
public DateTime? OrderDate { get; set; }
public DateTime? RequiredDate { get; set; }
public DateTime? ShippedDate { get; set; }
public int? ShipVia { get; set; }
public decimal? Freight { get; set; }

[MaxLength(40)]
public string ShipName { get; set; }

[MaxLength(60)]
public string ShipAddress { get; set; }

[MaxLength(15)]
public string ShipCity { get; set; }

[MaxLength(15)]
public string ShipRegion { get; set; }

[MaxLength(10)]
public string ShipPostalCode { get; set; }

[MaxLength(15)]
public string ShipCountry { get; set; }

public Customer Customer { get; set; } = new(); // Initialized to test #23851
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.DataAnnotations;

namespace Microsoft.EntityFrameworkCore.TestModels.Northwind;

public class Product
Expand All @@ -18,9 +20,13 @@ public int ProductID
set => _productId = value;
}

[MaxLength(40)]
[Required]
public string ProductName { get; set; }
public int? SupplierID { get; set; }
public int? CategoryID { get; set; }

[MaxLength(20)]
public string QuantityPerUnit { get; set; }
public decimal? UnitPrice { get; set; }
public ushort UnitsInStock { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
{
base.OnModelCreating(modelBuilder, context);

modelBuilder.Entity<Customer>()
.Property(c => c.CustomerID)
.HasColumnType("nchar(5)");

modelBuilder.Entity<Employee>(
b =>
{
b.Property(c => c.EmployeeID).HasColumnType("int");
b.Property(c => c.ReportsTo).HasColumnType("int");
});

modelBuilder.Entity<Order>(
b =>
{
b.Property(o => o.EmployeeID).HasColumnType("int");
b.Property(o => o.OrderDate).HasColumnType("datetime");
});

modelBuilder.Entity<OrderDetail>()
.Property(od => od.UnitPrice)
.HasColumnType("money");

modelBuilder.Entity<Product>(
b =>
{
b.Property(p => p.UnitPrice).HasColumnType("money");
b.Property(p => p.UnitsInStock).HasColumnType("smallint");
});

modelBuilder.Entity<MostExpensiveProduct>()
.Property(p => p.UnitPrice)
.HasColumnType("money");
}

protected override Type ContextType
=> typeof(NorthwindSqlServerContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public override async Task Update_Where_set_parameter(bool async)
await base.Update_Where_set_parameter(async);

AssertExecuteUpdateSql(
@"@__value_0='Abc' (Size = 4000)
@"@__value_0='Abc' (Size = 30)
UPDATE [c]
SET [c].[ContactName] = @__value_0
Expand All @@ -618,7 +618,7 @@ public override async Task Update_Where_set_parameter_from_closure_array(bool as
await base.Update_Where_set_parameter_from_closure_array(async);

AssertExecuteUpdateSql(
@"@__p_0='Abc' (Size = 4000)
@"@__p_0='Abc' (Size = 30)
UPDATE [c]
SET [c].[ContactName] = @__p_0
Expand All @@ -642,7 +642,7 @@ public override async Task Update_Where_set_parameter_from_multilevel_property_a
await base.Update_Where_set_parameter_from_multilevel_property_access(async);

AssertExecuteUpdateSql(
@"@__container_Containee_Property_0='Abc' (Size = 4000)
@"@__container_Containee_Property_0='Abc' (Size = 30)
UPDATE [c]
SET [c].[ContactName] = @__container_Containee_Property_0
Expand Down Expand Up @@ -922,7 +922,7 @@ public override async Task Update_Where_set_property_plus_parameter(bool async)
await base.Update_Where_set_property_plus_parameter(async);

AssertExecuteUpdateSql(
@"@__value_0='Abc' (Size = 4000)
@"@__value_0='Abc' (Size = 30)
UPDATE [c]
SET [c].[ContactName] = COALESCE([c].[ContactName], N'') + @__value_0
Expand Down Expand Up @@ -982,7 +982,7 @@ public override async Task Update_Where_multiple_set(bool async)
await base.Update_Where_multiple_set(async);

AssertExecuteUpdateSql(
@"@__value_0='Abc' (Size = 4000)
@"@__value_0='Abc' (Size = 30)
UPDATE [c]
SET [c].[City] = N'Seattle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public override async Task FromSqlRaw_composed_with_nullable_predicate(bool asyn
FROM (
SELECT * FROM ""Customers""
) AS [m]
WHERE [m].[ContactName] = [m].[CompanyName] OR (([m].[ContactName] IS NULL) AND ([m].[CompanyName] IS NULL))");
WHERE [m].[ContactName] = [m].[CompanyName]");
}

public override async Task FromSqlRaw_with_dbParameter(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

protected override NorthwindContext CreateNoTrackingContext()
=> new NorthwindRelationalContext(
=> new NorthwindSqlServerContext(
new DbContextOptionsBuilder(Fixture.CreateOptions())
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking).Options);
}
Loading

0 comments on commit 00b91c6

Please sign in to comment.