Skip to content

Commit

Permalink
Test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 21, 2024
1 parent 1c7d160 commit bb1465d
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 206 deletions.
20 changes: 9 additions & 11 deletions test/EFCore.Cosmos.FunctionalTests/Query/FromSqlQueryCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ SELECT VALUE s
FROM (
"""
+ " "
+ """
""" + " " + """
Expand All @@ -199,8 +197,8 @@ public Task FromSqlRaw_queryable_composed_compiled(bool async)
(NorthwindContext context) => context.Set<Customer>()
.FromSqlRaw(
"""
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
.Where(c => c.ContactName.Contains("z")));

using (var context = CreateContext())
Expand Down Expand Up @@ -588,8 +586,8 @@ public virtual Task FromSqlRaw_queryable_simple_as_no_tracking_not_composed(bool
using var context = CreateContext();
var query = context.Set<Customer>().FromSqlRaw(
"""
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
.AsNoTracking();

var actual = a
Expand Down Expand Up @@ -649,8 +647,8 @@ public virtual Task FromSqlRaw_composed_with_nullable_predicate(bool async)
using var context = CreateContext();
var query = context.Set<Customer>().FromSqlRaw(
"""
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
.Where(c => c.ContactName == c.CompanyName);

var actual = a
Expand Down Expand Up @@ -697,8 +695,8 @@ public virtual Task FromSqlRaw_queryable_simple_projection_not_composed(bool asy
using var context = CreateContext();
var query = context.Set<Customer>().FromSqlRaw(
"""
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
SELECT * FROM root c WHERE c["$type"] = "Customer"
""")
.Select(
c => new { c.CustomerID, c.City })
.AsNoTracking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public InheritanceQueryCosmosTest(InheritanceQueryCosmosFixture fixture, ITestOu
: base(fixture)
=> ClearLog();

//TestLoggerFactory.TestOutputHelper = testOutputHelper;
[ConditionalFact]
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public virtual async Task Select_enumerable_navigation_backed_by_collection(bool
}
}

private class Context21803(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context21803(DbContextOptions options) : DbContext(options)
{
public DbSet<AppEntity> Entities { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ public virtual async Task NoTracking_split_query_creates_only_required_instances
Assert.Equal(1, Context25400.Test.ConstructorCallCount);
}

private class Context25400(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context25400(DbContextOptions options) : DbContext(options)
{
public DbSet<Test> Tests { get; }
public DbSet<Test> Tests { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Test>().HasKey(e => e.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public virtual async Task An_optional_dependent_without_any_columns_and_nested_d
message);
}

private class Context23198(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context23198(DbContextOptions options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<AnAggregateRoot>().OwnsOne(
Expand All @@ -47,8 +48,8 @@ public class AnAggregateRoot

public class AnOwnedTypeWithOwnedProperties
{
public AnOwnedTypeWithPrimitiveProperties1 AnOwnedTypeWithPrimitiveProperties1 { get; }
public AnOwnedTypeWithPrimitiveProperties2 AnOwnedTypeWithPrimitiveProperties2 { get; }
public AnOwnedTypeWithPrimitiveProperties1 AnOwnedTypeWithPrimitiveProperties1 { get; set; }
public AnOwnedTypeWithPrimitiveProperties2 AnOwnedTypeWithPrimitiveProperties2 { get; set; }
}

public class AnOwnedTypeWithPrimitiveProperties1
Expand Down Expand Up @@ -81,9 +82,10 @@ public virtual async Task Multiple_owned_reference_mapped_to_own_table_containin
Assert.Equal(2, root3.ModdleA.Leaves.Count);
}

private class Context24777(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context24777(DbContextOptions options) : DbContext(options)
{
public DbSet<Root> Roots { get; }
public DbSet<Root> Roots { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Root>(
Expand Down Expand Up @@ -422,9 +424,10 @@ public virtual async Task Owned_entity_with_all_null_properties_property_access_
});
}

private class Context28247(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context28247(DbContextOptions options) : DbContext(options)
{
public DbSet<RotRutCase> RotRutCases { get; }
public DbSet<RotRutCase> RotRutCases { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<RotRutCase>(
Expand Down Expand Up @@ -505,10 +508,11 @@ join magus in context.Magi.Where(x => x.Name.Contains("Bayaz")) on monarch.Ruler
Assert.Equal("The Divider", result[0].magus.ToolUsed.Name);
}

private class Context30358(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context30358(DbContextOptions options) : DbContext(options)
{
public DbSet<Monarch> Monarchs { get; }
public DbSet<Magus> Magi { get; }
public DbSet<Monarch> Monarchs { get; set; }
public DbSet<Magus> Magi { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Magus>().OwnsOne(x => x.ToolUsed, x => x.ToTable("MagicTools"));
Expand Down Expand Up @@ -579,7 +583,8 @@ public async Task Can_have_required_owned_type_on_derived_type()
context.Set<Context31107.BaseEntity>().ToList();
}

private class Context31107(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context31107(DbContextOptions options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public virtual async Task Setting_IsUnicode_generates_unicode_literal_in_SQL()
var query = context.Set<Context9582.TipoServicio>().Where(xx => xx.Nombre.Contains("lla")).ToList();
}

private class Context9582(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context9582(DbContextOptions options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -82,10 +83,11 @@ public virtual async Task Projecting_correlated_collection_along_with_non_mapped
}
}

private class Context11835(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context11835(DbContextOptions options) : DbContext(options)
{
public DbSet<Blog> Blogs { get; }
public DbSet<Post> Posts { get; }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }

public Task SeedAsync()
{
Expand Down Expand Up @@ -144,10 +146,11 @@ from c in grouping.DefaultIfEmpty()
Assert.Equal(2, result.Count);
}

private class Context15684(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context15684(DbContextOptions options) : DbContext(options)
{
public DbSet<Category> Categories { get; }
public DbSet<Product> Products { get; }
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder
Expand Down Expand Up @@ -238,10 +241,13 @@ public virtual async Task Expression_tree_constructed_via_interface_works()
}
}

private class Context17276(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context17276(DbContextOptions options) : DbContext(options)
{
public DbSet<RemovableEntity> RemovableEntities { get; }
public DbSet<Parent> Parents { get; }
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public DbSet<RemovableEntity> RemovableEntities { get; set; }
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public DbSet<Parent> Parents { get; set; }

public static List<T> List<T>(IQueryable<T> query)
where T : IRemovable
Expand Down Expand Up @@ -274,8 +280,8 @@ public class Parent : IHasId<int>
[Owned]
public class OwnedEntity : IOwned
{
public string OwnedValue { get; }
public int Exists { get; }
public string OwnedValue { get; set; }
public int Exists { get; set; }
}

public interface IHasId<out T>
Expand Down Expand Up @@ -311,9 +317,10 @@ public virtual async Task Double_convert_interface_created_expression_tree()
Assert.Equal(1, query);
}

private class Context17794(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context17794(DbContextOptions options) : DbContext(options)
{
public DbSet<Offer> Offers { get; }
public DbSet<Offer> Offers { get; set; }
public DbSet<OfferAction> OfferActions { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand Down Expand Up @@ -407,9 +414,10 @@ public virtual async Task Casts_are_removed_from_expression_tree_when_redundant(
}
}

private class Context18087(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context18087(DbContextOptions options) : DbContext(options)
{
public DbSet<MockEntity> MockEntities { get; }
public DbSet<MockEntity> MockEntities { get; set; }

public Task SeedAsync()
{
Expand Down Expand Up @@ -453,9 +461,10 @@ public virtual async Task Can_query_hierarchy_with_non_nullable_property_on_deri
Assert.Equal(3, query.Count);
}

private class Context18346(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context18346(DbContextOptions options) : DbContext(options)
{
public DbSet<Business> Businesses { get; }
public DbSet<Business> Businesses { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Business>()
Expand Down Expand Up @@ -575,9 +584,10 @@ public virtual async Task Query_generates_correct_timespan_parameter_definition(
_ = context.Entities.Where(x => x.TimeSpan == parameter).Select(e => e.TimeSpan).FirstOrDefault();
}

private class Context26742(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class Context26742(DbContextOptions options) : DbContext(options)
{
public DbSet<Entity> Entities { get; }
public DbSet<Entity> Entities { get; set; }

public class Entity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ from organisation in context.Organisations.Where(o => o.OrganisationUsers.Any())
Assert.Equal(2, users.Count);
}

private class MyContext7973(DbContextOptions options) : DbContext(options)
// Protected so that it can be used by inheriting tests, and so that things like unused setters are not removed.
protected class MyContext7973(DbContextOptions options) : DbContext(options)
{
public DbSet<User> Users { get; }
public DbSet<Organisation> Organisations { get; }
public DbSet<User> Users { get; set; }
public DbSet<Organisation> Organisations { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
Loading

0 comments on commit bb1465d

Please sign in to comment.