diff --git a/test/Directory.Build.props b/test/Directory.Build.props new file mode 100644 index 00000000000..15da800c640 --- /dev/null +++ b/test/Directory.Build.props @@ -0,0 +1,8 @@ + + + + + $(NoWarn);xUnit1003;xUnit1010;xUnit1013 + + + diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets deleted file mode 100644 index e4d93f4b6b5..00000000000 --- a/test/Directory.Build.targets +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/test/EFCore.Analyzers.Tests/EFCore.Analyzers.Test.csproj b/test/EFCore.Analyzers.Tests/EFCore.Analyzers.Test.csproj index 2dcb92db539..7201dcf0d97 100644 --- a/test/EFCore.Analyzers.Tests/EFCore.Analyzers.Test.csproj +++ b/test/EFCore.Analyzers.Tests/EFCore.Analyzers.Test.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/test/EFCore.Cosmos.FunctionalTests/ConcurrencyDetectorCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/ConcurrencyDetectorCosmosTest.cs index 397b0740955..ca061a94738 100644 --- a/test/EFCore.Cosmos.FunctionalTests/ConcurrencyDetectorCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/ConcurrencyDetectorCosmosTest.cs @@ -15,13 +15,13 @@ public ConcurrencyDetectorCosmosTest(NorthwindQueryCosmosFixture().OrderBy(o => o.Id).ToListAsync(); var addresses = people[0].Addresses.ToList(); - Assert.Equal(1, addresses.Count); + Assert.Single(addresses); Assert.Equal(address.Street, addresses[0].Street); Assert.Equal(address.City, addresses[0].City); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.ResultOperators.cs b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.ResultOperators.cs index b46693aa792..b3018120eaf 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.ResultOperators.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.ResultOperators.cs @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Query { public partial class SimpleQueryCosmosTest { - [ConditionalTheory(Skip = "Issue#17246")] + [ConditionalFact(Skip = "Issue#17246")] public override void Select_All() { base.Select_All(); @@ -1224,7 +1224,7 @@ public override async Task OrderBy_Skip_Last_gives_correct_result(bool isAsync) WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue#17246 (Contains not implemented)")] + [ConditionalFact(Skip = "Issue#17246 (Contains not implemented)")] public override void Contains_over_entityType_should_rewrite_to_identity_equality() { base.Contains_over_entityType_should_rewrite_to_identity_equality(); @@ -1290,7 +1290,7 @@ public override async Task Contains_with_constant_list_value_type_id(bool isAsyn WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] = 10248))"); } - [ConditionalTheory(Skip = "Issue#17246 (Contains not implemented)")] + [ConditionalFact(Skip = "Issue#17246 (Contains not implemented)")] public override void Contains_over_entityType_with_null_should_rewrite_to_identity_equality() { base.Contains_over_entityType_with_null_should_rewrite_to_identity_equality(); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Select.cs b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Select.cs index a88fa2c485e..65ac4359aa0 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Select.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.Select.cs @@ -270,7 +270,7 @@ public override async Task Select_nested_collection(bool isAsync) WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""City""] = ""London""))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_nested_collection_multi_level() { base.Select_nested_collection_multi_level(); @@ -281,7 +281,7 @@ public override void Select_nested_collection_multi_level() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue#17246")] + [ConditionalFact(Skip = "Issue#17246")] public override void Select_nested_collection_multi_level2() { base.Select_nested_collection_multi_level2(); @@ -292,7 +292,7 @@ public override void Select_nested_collection_multi_level2() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue#17246")] + [ConditionalFact(Skip = "Issue#17246")] public override void Select_nested_collection_multi_level3() { base.Select_nested_collection_multi_level3(); @@ -303,7 +303,7 @@ public override void Select_nested_collection_multi_level3() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue#17246")] + [ConditionalFact(Skip = "Issue#17246")] public override void Select_nested_collection_multi_level4() { base.Select_nested_collection_multi_level4(); @@ -314,7 +314,7 @@ public override void Select_nested_collection_multi_level4() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue#17246")] + [ConditionalFact(Skip = "Issue#17246")] public override void Select_nested_collection_multi_level5() { using (var context = CreateContext()) @@ -335,7 +335,7 @@ public override void Select_nested_collection_multi_level5() }) .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(0, customers.Count(c => c.Order != null && c.Order != 0)); } @@ -345,7 +345,7 @@ public override void Select_nested_collection_multi_level5() WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""CustomerID""] = ""ALFKI""))"); } - [ConditionalTheory(Skip = "Issue#17246")] + [ConditionalFact(Skip = "Issue#17246")] public override void Select_nested_collection_multi_level6() { base.Select_nested_collection_multi_level6(); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.cs index 1d6fcad25b5..def2aca6f43 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/SimpleQueryCosmosTest.cs @@ -44,7 +44,7 @@ public virtual async Task Simple_IQueryable(bool isAsync) WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Shaper_command_caching_when_parameter_names_different() { base.Shaper_command_caching_when_parameter_names_different(); @@ -59,7 +59,7 @@ public override void Shaper_command_caching_when_parameter_names_different() WHERE (((c[""Discriminator""] = ""Customer"") AND (c[""CustomerID""] = ""ALFKI"")) AND true)"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Lifting_when_subquery_nested_order_by_anonymous() { base.Lifting_when_subquery_nested_order_by_anonymous(); @@ -179,7 +179,7 @@ public override async Task Entity_equality_not_null(bool isAsync) WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""CustomerID""] != null))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Query_when_evaluatable_queryable_method_call_with_repository() { using (var context = CreateContext()) @@ -194,7 +194,7 @@ var results .Where(c => orderRepository.Find().Any(o => o.CustomerID == c.CustomerID)) .ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); results = (from c in customerRepository.Find().Where(c => c.CustomerID == "ALFKI") @@ -202,7 +202,7 @@ where orderRepository.Find().Any(o => o.CustomerID == c.CustomerID) select c) .ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); var orderQuery = orderRepository.Find(); @@ -210,7 +210,7 @@ where orderRepository.Find().Any(o => o.CustomerID == c.CustomerID) .Where(c => orderQuery.Any(o => o.CustomerID == c.CustomerID)) .ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; } @@ -488,7 +488,7 @@ public override void Select_Where_Subquery_Deep_Single() WHERE ((c[""Discriminator""] = ""OrderDetail"") AND (c[""OrderID""] = 10344))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_Where_Subquery_Deep_First() { base.Select_Where_Subquery_Deep_First(); @@ -600,7 +600,7 @@ public override async Task OrderBy_ternary_conditions(bool isAsync) WHERE (c[""Discriminator""] = ""Product"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void OrderBy_any() { base.OrderBy_any(); @@ -990,7 +990,7 @@ public override async Task Any_nested3(bool isAsync) WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Any_with_multiple_conditions_still_uses_exists() { base.Any_with_multiple_conditions_still_uses_exists(); @@ -1876,7 +1876,7 @@ public override void Select_DTO_distinct_translated_to_server() WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] < 10300))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_DTO_constructor_distinct_translated_to_server() { base.Select_DTO_constructor_distinct_translated_to_server(); @@ -1887,7 +1887,7 @@ public override void Select_DTO_constructor_distinct_translated_to_server() WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] < 10300))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_DTO_with_member_init_distinct_translated_to_server() { base.Select_DTO_with_member_init_distinct_translated_to_server(); @@ -1898,7 +1898,7 @@ public override void Select_DTO_with_member_init_distinct_translated_to_server() WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] < 10300))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_nested_collection_count_using_DTO() { base.Select_nested_collection_count_using_DTO(); @@ -1920,7 +1920,7 @@ public override async Task Select_DTO_with_member_init_distinct_in_subquery_tran WHERE ((c[""Discriminator""] = ""Order"") AND (c[""OrderID""] < 10300))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_DTO_with_member_init_distinct_in_subquery_used_in_projection_translated_to_server() { base.Select_DTO_with_member_init_distinct_in_subquery_used_in_projection_translated_to_server(); @@ -2136,7 +2136,7 @@ public override async Task Select_take_skip_null_coalesce_operator3(bool isAsync WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Selected_column_can_coalesce() { base.Selected_column_can_coalesce(); @@ -2296,7 +2296,7 @@ public override async Task String_concat_with_navigation2(bool isAsync) WHERE (c[""Discriminator""] = ""Order"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_bitwise_or() { base.Select_bitwise_or(); @@ -2307,7 +2307,7 @@ public override void Select_bitwise_or() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_bitwise_or_multiple() { base.Select_bitwise_or_multiple(); @@ -2318,7 +2318,7 @@ public override void Select_bitwise_or_multiple() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_bitwise_and() { base.Select_bitwise_and(); @@ -2329,7 +2329,7 @@ public override void Select_bitwise_and() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_bitwise_and_or() { base.Select_bitwise_and_or(); @@ -2376,7 +2376,7 @@ public override async Task Where_bitwise_and_with_logical_or(bool isAsync) WHERE ((c[""Discriminator""] = ""Customer"") AND (((c[""CustomerID""] = ""ALFKI"") & (c[""CustomerID""] = ""ANATR"")) OR (c[""CustomerID""] = ""ANTON"")))"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_bitwise_or_with_logical_or() { base.Select_bitwise_or_with_logical_or(); @@ -2387,7 +2387,7 @@ public override void Select_bitwise_or_with_logical_or() WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_bitwise_and_with_logical_and() { base.Select_bitwise_and_with_logical_and(); @@ -3681,7 +3681,7 @@ public override async Task OrderBy_empty_list_does_not_contains(bool isAsync) WHERE (c[""Discriminator""] = ""Customer"")"); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Manual_expression_tree_typed_null_equality() { base.Manual_expression_tree_typed_null_equality(); @@ -3889,7 +3889,7 @@ public override Task Multiple_collection_navigation_with_FirstOrDefault_chained_ return base.Multiple_collection_navigation_with_FirstOrDefault_chained_projecting_scalar(isAsync); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Can_convert_manually_build_expression_with_default() { base.Can_convert_manually_build_expression_with_default(); @@ -3973,7 +3973,7 @@ public override Task SelectMany_primitive_select_subquery(bool isAsync) return base.SelectMany_primitive_select_subquery(isAsync); } - [ConditionalTheory(Skip = "Issue #17246")] + [ConditionalFact(Skip = "Issue #17246")] public override void Select_DTO_constructor_distinct_with_navigation_translated_to_server() { base.Select_DTO_constructor_distinct_with_navigation_translated_to_server(); @@ -4100,16 +4100,18 @@ public override Task FirstOrDefault_over_empty_collection_of_value_type_returns_ } [ConditionalTheory(Skip = "Issue #17246")] - public override Task All_client(bool isAsync) => null; + public override Task All_client(bool isAsync) => base.All_client(isAsync); [ConditionalTheory(Skip = "Issue #17246")] - public override Task Client_OrderBy_GroupBy_Group_ordering_works(bool isAsync) => null; + public override Task Client_OrderBy_GroupBy_Group_ordering_works(bool isAsync) + => base.Client_OrderBy_GroupBy_Group_ordering_works(isAsync); [ConditionalTheory(Skip = "Issue #17246")] - public override Task Subquery_member_pushdown_does_not_change_original_subquery_model2(bool isAsync) => null; + public override Task Subquery_member_pushdown_does_not_change_original_subquery_model2(bool isAsync) + => base.Subquery_member_pushdown_does_not_change_original_subquery_model2(isAsync); [ConditionalTheory(Skip = "Issue #17246")] - public override Task Where_query_composition3(bool isAsync) => null; + public override Task Where_query_composition3(bool isAsync) => base.Where_query_composition3(isAsync); public override async Task Member_binding_after_ctor_arguments_fails_with_client_eval(bool isAsync) { diff --git a/test/EFCore.CrossStore.FunctionalTests/ConfigurationPatternsTest.cs b/test/EFCore.CrossStore.FunctionalTests/ConfigurationPatternsTest.cs index c416e6c026b..e21a80736f3 100644 --- a/test/EFCore.CrossStore.FunctionalTests/ConfigurationPatternsTest.cs +++ b/test/EFCore.CrossStore.FunctionalTests/ConfigurationPatternsTest.cs @@ -214,7 +214,9 @@ private void Seed(CrossStoreContext context) context.SaveChanges(); } +#pragma warning disable xUnit1013 // Public method should be marked as test public void Dispose() => ExistingTestStore.Dispose(); +#pragma warning restore xUnit1013 // Public method should be marked as test [SqlServerConfiguredCondition] public class NestedContextDifferentStores : IClassFixture @@ -244,7 +246,7 @@ private async Task NestedContextTest(Func createBlogContext, Func e.Entity).Single()); await context0.SaveChangesAsync(); @@ -252,13 +254,13 @@ private async Task NestedContextTest(Func createBlogContext, Func e.Entity).Single()); using (var context2 = createBlogContext()) { - Assert.Equal(0, context2.ChangeTracker.Entries().Count()); + Assert.Empty(context2.ChangeTracker.Entries()); Assert.Same(blog0, context0.ChangeTracker.Entries().Select(e => e.Entity).Single()); var blog0Prime = (await context2.Blogs.ToArrayAsync()).Single(); @@ -282,7 +284,9 @@ private void Seed(CrossStoreContext context) context.SaveChanges(); } +#pragma warning disable xUnit1013 // Public method should be marked as test public void Dispose() => ExistingTestStore.Dispose(); +#pragma warning restore xUnit1013 // Public method should be marked as test private class BlogContext : DbContext { diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs index fe4435789cb..4470a1d352d 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationOperationGeneratorTest.cs @@ -883,7 +883,7 @@ public void CreateTableOperation_Columns_required_args() o => { Assert.Equal("Post", o.Name); - Assert.Equal(1, o.Columns.Count); + Assert.Single(o.Columns); Assert.Equal("Id", o.Columns[0].Name); Assert.Equal("Post", o.Columns[0].Table); @@ -932,7 +932,7 @@ public void CreateTableOperation_Columns_all_args() { Assert.Equal("Post", o.Name); Assert.Equal("dbo", o.Schema); - Assert.Equal(1, o.Columns.Count); + Assert.Single(o.Columns); Assert.Equal("Post Id", o.Columns[0].Name); Assert.Equal("dbo", o.Columns[0].Schema); @@ -966,7 +966,7 @@ public void CreateTableOperation_Columns_DefaultValueSql() " });", o => { - Assert.Equal(1, o.Columns.Count); + Assert.Single(o.Columns); Assert.Equal("Id", o.Columns[0].Name); Assert.Equal("Post", o.Columns[0].Table); @@ -995,7 +995,7 @@ public void CreateTableOperation_Columns_computedColumnSql() " });", o => { - Assert.Equal(1, o.Columns.Count); + Assert.Single(o.Columns); Assert.Equal("Id", o.Columns[0].Name); Assert.Equal("Post", o.Columns[0].Table); @@ -1040,7 +1040,7 @@ public void CreateTableOperation_ForeignKeys_required_args() " });", o => { - Assert.Equal(1, o.ForeignKeys.Count); + Assert.Single(o.ForeignKeys); var fk = o.ForeignKeys.First(); Assert.Equal("FK_Post_Blog_BlogId", fk.Name); @@ -1095,7 +1095,7 @@ public void CreateTableOperation_ForeignKeys_all_args() " });", o => { - Assert.Equal(1, o.ForeignKeys.Count); + Assert.Single(o.ForeignKeys); var fk = o.ForeignKeys.First(); Assert.Equal("Post", fk.Table); @@ -1151,7 +1151,7 @@ public void CreateTableOperation_ForeignKeys_composite() " });", o => { - Assert.Equal(1, o.ForeignKeys.Count); + Assert.Single(o.ForeignKeys); var fk = o.ForeignKeys.First(); Assert.Equal("Post", fk.Table); @@ -1287,7 +1287,7 @@ public void CreateTableOperation_UniqueConstraints_required_args() " });", o => { - Assert.Equal(1, o.UniqueConstraints.Count); + Assert.Single(o.UniqueConstraints); Assert.Equal("AK_Post_AltId", o.UniqueConstraints[0].Name); Assert.Equal("Post", o.UniqueConstraints[0].Table); @@ -1325,7 +1325,7 @@ public void CreateTableOperation_UniqueConstraints_all_args() " });", o => { - Assert.Equal(1, o.UniqueConstraints.Count); + Assert.Single(o.UniqueConstraints); Assert.Equal("AK_Post_AltId", o.UniqueConstraints[0].Name); Assert.Equal("dbo", o.UniqueConstraints[0].Schema); @@ -1367,7 +1367,7 @@ public void CreateTableOperation_UniqueConstraints_composite() " });", o => { - Assert.Equal(1, o.UniqueConstraints.Count); + Assert.Single(o.UniqueConstraints); Assert.Equal("AK_Post_AltId1_AltId2", o.UniqueConstraints[0].Name); Assert.Equal("Post", o.UniqueConstraints[0].Table); @@ -1408,7 +1408,7 @@ public void CreateTableOperation_CheckConstraints_required_args() " });", o => { - Assert.Equal(1, o.CheckConstraints.Count); + Assert.Single(o.CheckConstraints); Assert.Equal("CK_Post_AltId1_AltId2", o.CheckConstraints[0].Name); Assert.Equal("Post", o.CheckConstraints[0].Table); @@ -1451,7 +1451,7 @@ public void CreateTableOperation_ChecksConstraints_all_args() " });", o => { - Assert.Equal(1, o.CheckConstraints.Count); + Assert.Single(o.CheckConstraints); Assert.Equal("CK_Post_AltId1_AltId2", o.CheckConstraints[0].Name); Assert.Equal("dbo", o.CheckConstraints[0].Schema); @@ -2030,7 +2030,7 @@ public void InsertDataOperation_required_args() o => { Assert.Equal("People", o.Table); - Assert.Equal(1, o.Columns.Length); + Assert.Single(o.Columns); Assert.Equal(1, o.Values.GetLength(0)); Assert.Equal(1, o.Values.GetLength(1)); Assert.Equal(_point1, o.Values[0, 0]); @@ -2083,7 +2083,7 @@ public void InsertDataOperation_required_args_multiple_rows() o => { Assert.Equal("People", o.Table); - Assert.Equal(1, o.Columns.Length); + Assert.Single(o.Columns); Assert.Equal(2, o.Values.GetLength(0)); Assert.Equal(1, o.Values.GetLength(1)); Assert.Equal(_lineString1, o.Values[0, 0]); @@ -2118,7 +2118,7 @@ public void DeleteDataOperation_all_args() { Assert.Equal("dbo", o.Schema); Assert.Equal("People", o.Table); - Assert.Equal(1, o.KeyColumns.Length); + Assert.Single(o.KeyColumns); Assert.Equal(5, o.KeyValues.GetLength(0)); Assert.Equal(1, o.KeyValues.GetLength(1)); Assert.Equal("John", o.KeyValues[2, 0]); @@ -2175,7 +2175,7 @@ public void DeleteDataOperation_required_args() o => { Assert.Equal("People", o.Table); - Assert.Equal(1, o.KeyColumns.Length); + Assert.Single(o.KeyColumns); Assert.Equal(1, o.KeyValues.GetLength(0)); Assert.Equal(1, o.KeyValues.GetLength(1)); Assert.Equal("Snow", o.KeyValues[0, 0]); @@ -2236,7 +2236,7 @@ public void UpdateDataOperation_all_args() { Assert.Equal("dbo", o.Schema); Assert.Equal("People", o.Table); - Assert.Equal(1, o.KeyColumns.Length); + Assert.Single(o.KeyColumns); Assert.Equal(2, o.KeyValues.GetLength(0)); Assert.Equal(1, o.KeyValues.GetLength(1)); Assert.Equal("Daenerys", o.KeyValues[1, 0]); @@ -2280,7 +2280,7 @@ public void UpdateDataOperation_all_args_composite() Assert.Equal(2, o.KeyValues.GetLength(0)); Assert.Equal(2, o.KeyValues.GetLength(1)); Assert.Equal("Daenerys", o.KeyValues[1, 0]); - Assert.Equal(1, o.Columns.Length); + Assert.Single(o.Columns); Assert.Equal(2, o.Values.GetLength(0)); Assert.Equal(1, o.Values.GetLength(1)); Assert.Equal("Targaryen", o.Values[1, 0]); @@ -2351,7 +2351,7 @@ public void UpdateDataOperation_all_args_multi() { Assert.Equal("dbo", o.Schema); Assert.Equal("People", o.Table); - Assert.Equal(1, o.KeyColumns.Length); + Assert.Single(o.KeyColumns); Assert.Equal(1, o.KeyValues.GetLength(0)); Assert.Equal(1, o.KeyValues.GetLength(1)); Assert.Equal("Daenerys Targaryen", o.KeyValues[0, 0]); @@ -2383,11 +2383,11 @@ public void UpdateDataOperation_required_args() o => { Assert.Equal("People", o.Table); - Assert.Equal(1, o.KeyColumns.Length); + Assert.Single(o.KeyColumns); Assert.Equal(1, o.KeyValues.GetLength(0)); Assert.Equal(1, o.KeyValues.GetLength(1)); Assert.Equal("Daenerys", o.KeyValues[0, 0]); - Assert.Equal(1, o.Columns.Length); + Assert.Single(o.Columns); Assert.Equal(1, o.Values.GetLength(0)); Assert.Equal(1, o.Values.GetLength(1)); Assert.Equal("Targaryen", o.Values[0, 0]); @@ -2423,11 +2423,11 @@ public void UpdateDataOperation_required_args_multiple_rows() o => { Assert.Equal("People", o.Table); - Assert.Equal(1, o.KeyColumns.Length); + Assert.Single(o.KeyColumns); Assert.Equal(2, o.KeyValues.GetLength(0)); Assert.Equal(1, o.KeyValues.GetLength(1)); Assert.Equal("Daenerys", o.KeyValues[1, 0]); - Assert.Equal(1, o.Columns.Length); + Assert.Single(o.Columns); Assert.Equal(2, o.Values.GetLength(0)); Assert.Equal(1, o.Values.GetLength(1)); Assert.Equal("Targaryen", o.Values[1, 0]); @@ -2459,7 +2459,7 @@ public void UpdateDataOperation_required_args_composite() Assert.Equal(1, o.KeyValues.GetLength(0)); Assert.Equal(2, o.KeyValues.GetLength(1)); Assert.Equal("Daenerys", o.KeyValues[0, 0]); - Assert.Equal(1, o.Columns.Length); + Assert.Single(o.Columns); Assert.Equal(1, o.Values.GetLength(0)); Assert.Equal(1, o.Values.GetLength(1)); Assert.Equal("Targaryen", o.Values[0, 0]); @@ -2519,7 +2519,7 @@ public void UpdateDataOperation_required_args_multi() o => { Assert.Equal("People", o.Table); - Assert.Equal(1, o.KeyColumns.Length); + Assert.Single(o.KeyColumns); Assert.Equal(1, o.KeyValues.GetLength(0)); Assert.Equal(1, o.KeyValues.GetLength(1)); Assert.Equal("Daenerys Targaryen", o.KeyValues[0, 0]); diff --git a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs index 8feffe96006..b22ead77b1d 100644 --- a/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs +++ b/test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs @@ -777,7 +777,7 @@ public virtual void Indexes_are_stored_in_snapshot() });"), o => { - Assert.Equal(1, o.GetEntityTypes().First().GetIndexes().Count()); + Assert.Single(o.GetEntityTypes().First().GetIndexes()); Assert.Equal("AlternateId", o.GetEntityTypes().First().GetIndexes().First().Properties[0].Name); }); } @@ -812,7 +812,7 @@ public virtual void Indexes_are_stored_in_snapshot_including_composite_index() });"), o => { - Assert.Equal(1, o.GetEntityTypes().First().GetIndexes().Count()); + Assert.Single(o.GetEntityTypes().First().GetIndexes()); Assert.Collection( o.GetEntityTypes().First().GetIndexes().First().Properties, t => Assert.Equal("Id", t.Name), @@ -1250,7 +1250,7 @@ public virtual void Owned_types_are_stored_in_snapshot() Assert.True(ownership2.IsRequired); var ownedType2 = ownership2.DeclaringEntityType; Assert.Equal(nameof(EntityWithStringProperty.Id), ownedType2.FindPrimaryKey().Properties[0].Name); - Assert.Equal(1, ownedType2.GetKeys().Count()); + Assert.Single(ownedType2.GetKeys()); Assert.Equal(2, ownedType2.GetIndexes().Count()); var owned2index1 = ownedType2.GetIndexes().First(); Assert.Equal("EntityWithOnePropertyId", owned2index1.Properties[0].Name); diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs index b59e282bc39..d5869cab361 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs @@ -62,7 +62,7 @@ public void Creates_entity_types() vwtable => { Assert.Equal("noPrimaryKey", vwtable.GetTableName()); - Assert.Equal(0, vwtable.GetKeys().Count()); + Assert.Empty(vwtable.GetKeys()); }, table => { @@ -319,7 +319,9 @@ public void Unmappable_column_type(string StoreType) [ConditionalTheory] [InlineData(new[] { "Id" }, 1)] [InlineData(new[] { "Id", "AltId" }, 2)] +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters public void Primary_key(string[] keyProps, int length) +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters { var info = new DatabaseModel @@ -335,7 +337,7 @@ public void Primary_key(string[] keyProps, int length) var model = (EntityType)_factory.Create(info, false).GetEntityTypes().Single(); - Assert.Equal(model.FindPrimaryKey().GetName(), "MyPk"); + Assert.Equal("MyPk", model.FindPrimaryKey().GetName()); Assert.Equal(keyProps, model.FindPrimaryKey().Properties.Select(p => p.GetColumnName()).ToArray()); } @@ -1117,7 +1119,7 @@ public void Unmapped_column_is_ignored() var columns = model.FindEntityType("Table").GetProperties().ToList(); - Assert.Equal(1, columns.Count); + Assert.Single(columns); } [ConditionalFact] diff --git a/test/EFCore.InMemory.FunctionalTests/DatabaseInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/DatabaseInMemoryTest.cs index 8f330f63bfc..9dd99c297bb 100644 --- a/test/EFCore.InMemory.FunctionalTests/DatabaseInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/DatabaseInMemoryTest.cs @@ -121,7 +121,7 @@ public async Task Can_share_instance_between_contexts_with_sugar_experience() using (var db = new SimpleContext()) { var data = db.Artists.ToList(); - Assert.Equal(1, data.Count); + Assert.Single(data); Assert.Equal("JDId", data[0].ArtistId); Assert.Equal("John Doe", data[0].Name); } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/GearsOfWarQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/GearsOfWarQueryInMemoryTest.cs index f96a06f59e7..417930e261a 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/GearsOfWarQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/GearsOfWarQueryInMemoryTest.cs @@ -69,13 +69,13 @@ public override Task Include_collection_with_complex_OrderBy3(bool isAsync) return base.Include_collection_with_complex_OrderBy3(isAsync); } - [ConditionalTheory(Skip = "issue #17537")] + [ConditionalFact(Skip = "issue #17537")] public override void Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_coalesce_result1() { base.Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_coalesce_result1(); } - [ConditionalTheory(Skip = "issue #17537")] + [ConditionalFact(Skip = "issue #17537")] public override void Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_coalesce_result2() { base.Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_coalesce_result2(); diff --git a/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs index 3db6fc3db83..65274e4f395 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/QueryBugsInMemoryTest.cs @@ -667,7 +667,7 @@ public virtual void Entity_passed_to_DTO_constructor_works() { var query = context.Entity.Select(e => new EntityDto8282(e)).ToList(); - Assert.Equal(0, query.Count); + Assert.Empty(query); } } } diff --git a/test/EFCore.InMemory.FunctionalTests/Query/QueryNavigationsInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/QueryNavigationsInMemoryTest.cs index 972cd6aa1ca..b12a6ad58be 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/QueryNavigationsInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/QueryNavigationsInMemoryTest.cs @@ -20,7 +20,7 @@ public class QueryNavigationsInMemoryTest : QueryNavigationsTestBase t.Rows).Count()); + Assert.Single(inMemoryDatabase.Store.GetTables(entityEntry.EntityType).SelectMany(t => t.Rows)); Assert.Equal(new object[] { 42, "Unikorn" }, inMemoryDatabase.Store.GetTables(entityEntry.EntityType).Single().Rows.Single()); } @@ -105,7 +105,7 @@ public async Task Save_changes_updates_changed_objects_in_store() await inMemoryDatabase.SaveChangesAsync(new[] { entityEntry }); - Assert.Equal(1, inMemoryDatabase.Store.GetTables(entityEntry.EntityType).SelectMany(t => t.Rows).Count()); + Assert.Single(inMemoryDatabase.Store.GetTables(entityEntry.EntityType).SelectMany(t => t.Rows)); Assert.Equal( new object[] { 42, "Unikorn, The Return" }, inMemoryDatabase.Store.GetTables(entityEntry.EntityType).Single().Rows.Single()); @@ -132,7 +132,7 @@ public async Task Save_changes_removes_deleted_objects_from_store() await inMemoryDatabase.SaveChangesAsync(new[] { entityEntry }); - Assert.Equal(0, inMemoryDatabase.Store.GetTables(entityEntry.EntityType).SelectMany(t => t.Rows).Count()); + Assert.Empty(inMemoryDatabase.Store.GetTables(entityEntry.EntityType).SelectMany(t => t.Rows)); } [ConditionalFact] diff --git a/test/EFCore.InMemory.Tests/InMemoryOptionsExtensionTest.cs b/test/EFCore.InMemory.Tests/InMemoryOptionsExtensionTest.cs index 399a27237bf..24abdf18392 100644 --- a/test/EFCore.InMemory.Tests/InMemoryOptionsExtensionTest.cs +++ b/test/EFCore.InMemory.Tests/InMemoryOptionsExtensionTest.cs @@ -22,7 +22,7 @@ public void Adds_in_memory_services() _applyServices.Invoke(new InMemoryOptionsExtension(), new object[] { services }); - Assert.True(services.Any(sd => sd.ServiceType == typeof(IInMemoryDatabase))); + Assert.Contains(services, sd => sd.ServiceType == typeof(IInMemoryDatabase)); } } } diff --git a/test/EFCore.Relational.Specification.Tests/CommandInterceptionTestBase.cs b/test/EFCore.Relational.Specification.Tests/CommandInterceptionTestBase.cs index 6638fff312e..08959096a1f 100644 --- a/test/EFCore.Relational.Specification.Tests/CommandInterceptionTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/CommandInterceptionTestBase.cs @@ -1163,7 +1163,8 @@ public virtual async Task Intercept_non_query_that_throws(bool async, bool injec [InlineData(true, true)] public virtual async Task Intercept_query_to_throw(bool async, bool inject) { - using (var context = CreateContext(new ThrowingReaderCommandInterceptor())) + var (context, interceptor) = CreateContext(inject); + using (context) { var exception = async ? await Assert.ThrowsAsync(() => context.Set().ToListAsync()) @@ -1180,7 +1181,8 @@ public virtual async Task Intercept_query_to_throw(bool async, bool inject) [InlineData(true, true)] public virtual async Task Intercept_scalar_to_throw(bool async, bool inject) { - using (var context = CreateContext(new ThrowingReaderCommandInterceptor())) + var (context, interceptor) = CreateContext(inject); + using (context) { var command = context.GetService().Create().Append("SELECT 1").Build(); var connection = context.GetService(); @@ -1203,7 +1205,8 @@ public virtual async Task Intercept_scalar_to_throw(bool async, bool inject) [InlineData(true, true)] public virtual async Task Intercept_non_query_to_throw(bool async, bool inject) { - using (var context = CreateContext(new ThrowingReaderCommandInterceptor())) + var (context, interceptor) = CreateContext(inject); + using (context) { using (context.Database.BeginTransaction()) { diff --git a/test/EFCore.Relational.Specification.Tests/Query/AsyncFromSqlQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/AsyncFromSqlQueryTestBase.cs index a046f0872a0..e523e716dba 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/AsyncFromSqlQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/AsyncFromSqlQueryTestBase.cs @@ -229,7 +229,7 @@ public virtual async Task FromSqlRaw_queryable_simple_cache_key_includes_query_s .FromSqlRaw(NormalizeDelimetersInRawString("SELECT * FROM [Customers] WHERE [City] = 'Seattle'")) .ToArrayAsync(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); Assert.True(actual.All(c => c.City == "Seattle")); } } @@ -272,7 +272,7 @@ public virtual async Task FromSqlRaw_queryable_simple_as_no_tracking_not_compose .ToArrayAsync(); Assert.Equal(91, actual.Length); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -288,7 +288,7 @@ public virtual async Task FromSqlRaw_queryable_simple_projection_not_composed() .ToArrayAsync(); Assert.Equal(91, actual.Length); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -346,7 +346,7 @@ public virtual async Task FromSqlRaw_composed_with_nullable_predicate() .Where(c => c.ContactName == c.CompanyName) .ToArrayAsync(); - Assert.Equal(0, actual.Length); + Assert.Empty(actual); } } diff --git a/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs index d5ffcf5e626..b6113936719 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs @@ -282,7 +282,7 @@ public virtual void FromSqlRaw_queryable_composed_compiled_with_parameter() { var actual = query(context).ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); } } @@ -300,7 +300,7 @@ public virtual void FromSqlRaw_queryable_composed_compiled_with_DbParameter() { var actual = query(context).ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); } } @@ -318,7 +318,7 @@ public virtual void FromSqlRaw_queryable_composed_compiled_with_nameless_DbParam { var actual = query(context).ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); } } @@ -354,7 +354,7 @@ var actual select c) .ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); } } @@ -433,7 +433,7 @@ var actual select new { c, o }) .ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); } } @@ -576,7 +576,7 @@ var actual select new { c, o }) .ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); } } @@ -593,7 +593,7 @@ public virtual void FromSqlRaw_queryable_with_null_parameter() "SELECT * FROM [Employees] WHERE [ReportsTo] = {0} OR ([ReportsTo] IS NULL AND {0} IS NULL)"), reportsTo) .ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); } } @@ -632,7 +632,7 @@ public virtual void FromSqlRaw_queryable_simple_cache_key_includes_query_string( .FromSqlRaw(NormalizeDelimetersInRawString("SELECT * FROM [Customers] WHERE [City] = 'Seattle'")) .ToArray(); - Assert.Equal(1, actual.Length); + Assert.Single(actual); Assert.True(actual.All(c => c.City == "Seattle")); } } @@ -675,7 +675,7 @@ public virtual void FromSqlRaw_queryable_simple_as_no_tracking_not_composed() .ToArray(); Assert.Equal(91, actual.Length); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -752,7 +752,7 @@ public virtual void FromSqlRaw_composed_with_nullable_predicate() .Where(c => c.ContactName == c.CompanyName) .ToArray(); - Assert.Equal(0, actual.Length); + Assert.Empty(actual); } } @@ -863,12 +863,12 @@ public virtual void FromSqlRaw_with_db_parameters_called_multiple_times() // ReSharper disable PossibleMultipleEnumeration var result1 = query.ToList(); - Assert.Equal(1, result1.Count); + Assert.Single(result1); var result2 = query.ToList(); // ReSharper restore PossibleMultipleEnumeration - Assert.Equal(1, result2.Count); + Assert.Single(result2); } } @@ -885,7 +885,7 @@ public virtual void FromSqlRaw_with_SelectMany_and_include() select new { c1, c2 }; var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); var customers1 = result.Select(r => r.c1); var customers2 = result.Select(r => r.c2); @@ -958,7 +958,7 @@ public virtual void FromSqlInterpolated_with_inlined_db_parameter() NormalizeDelimetersInInterpolatedString($"SELECT * FROM [Customers] WHERE [CustomerID] = {parameter}")) .ToList(); - Assert.Equal(1, actual.Count); + Assert.Single(actual); Assert.True(actual.All(c => c.City == "Berlin")); } } @@ -975,7 +975,7 @@ public virtual void FromSqlInterpolated_with_inlined_db_parameter_without_name_p NormalizeDelimetersInInterpolatedString($"SELECT * FROM [Customers] WHERE [CustomerID] = {parameter}")) .ToList(); - Assert.Equal(1, actual.Count); + Assert.Single(actual); Assert.True(actual.All(c => c.City == "Berlin")); } } diff --git a/test/EFCore.Relational.Specification.Tests/Query/FromSqlSprocQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/FromSqlSprocQueryTestBase.cs index 7d3006438b1..d2134f4fda7 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/FromSqlSprocQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/FromSqlSprocQueryTestBase.cs @@ -35,11 +35,9 @@ public virtual async Task From_sql_queryable_stored_procedure(bool async) Assert.Equal(10, actual.Length); - Assert.True( - actual.Any( - mep => + Assert.Contains(actual, mep => mep.TenMostExpensiveProducts == "Côte de Blaye" - && mep.UnitPrice == 263.50m)); + && mep.UnitPrice == 263.50m); } } @@ -60,7 +58,7 @@ public virtual async Task From_sql_queryable_stored_procedure_projection(bool as : query.ToArray(); Assert.Equal(10, actual.Length); - Assert.True(actual.Any(r => r == "Côte de Blaye")); + Assert.Contains(actual, r => r == "Côte de Blaye"); } } @@ -131,11 +129,9 @@ public virtual async Task From_sql_queryable_stored_procedure_with_parameter(boo Assert.Equal(11, actual.Length); - Assert.True( - actual.Any( - coh => + Assert.Contains(actual, coh => coh.ProductName == "Aniseed Syrup" - && coh.Total == 6)); + && coh.Total == 6); } } diff --git a/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs index 52732972485..5a9720c171a 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/UdfDbFunctionTestBase.cs @@ -411,7 +411,7 @@ public virtual void Scalar_Function_Where_Correlated_Static() where UDFSqlContext.IsTopCustomerStatic(c.Id) select c.Id.ToString().ToLower()).ToList(); - Assert.Equal(1, cust.Count); + Assert.Single(cust); } } @@ -426,7 +426,7 @@ public virtual void Scalar_Function_Where_Not_Correlated_Static() where UDFSqlContext.GetCustomerWithMostOrdersAfterDateStatic(startDate) == c.Id select c.Id).SingleOrDefault(); - Assert.Equal(custId, 2); + Assert.Equal(2, custId); } } @@ -442,7 +442,7 @@ public virtual void Scalar_Function_Where_Parameter_Static() UDFSqlContext.GetReportingPeriodStartDateStatic(period)) select c.Id).SingleOrDefault(); - Assert.Equal(custId, 1); + Assert.Equal(1, custId); } } @@ -457,7 +457,7 @@ public virtual void Scalar_Function_Where_Nested_Static() UDFSqlContext.ReportingPeriod.Winter)) select c.Id).SingleOrDefault(); - Assert.Equal(custId, 1); + Assert.Equal(1, custId); } } @@ -770,7 +770,7 @@ select new Id = context.StarValueInstance(4, c.Id), LastName = context.DollarValueInstance(2, c.LastName) }).Single(); - Assert.Equal(custName.LastName, "$$One"); + Assert.Equal("$$One", custName.LastName); } } @@ -899,7 +899,7 @@ public virtual void Scalar_Function_Where_Correlated_Instance() where context.IsTopCustomerInstance(c.Id) select c.Id.ToString().ToLower()).ToList(); - Assert.Equal(1, cust.Count); + Assert.Single(cust); } } @@ -914,7 +914,7 @@ public virtual void Scalar_Function_Where_Not_Correlated_Instance() where context.GetCustomerWithMostOrdersAfterDateInstance(startDate) == c.Id select c.Id).SingleOrDefault(); - Assert.Equal(custId, 2); + Assert.Equal(2, custId); } } @@ -930,7 +930,7 @@ public virtual void Scalar_Function_Where_Parameter_Instance() context.GetReportingPeriodStartDateInstance(period)) select c.Id).SingleOrDefault(); - Assert.Equal(custId, 1); + Assert.Equal(1, custId); } } @@ -945,7 +945,7 @@ public virtual void Scalar_Function_Where_Nested_Instance() UDFSqlContext.ReportingPeriod.Winter)) select c.Id).SingleOrDefault(); - Assert.Equal(custId, 1); + Assert.Equal(1, custId); } } diff --git a/test/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs index 4c5bfc494af..4457021126b 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/WarningsTestBase.cs @@ -62,7 +62,7 @@ public virtual void FirstOrDefault_without_orderby_and_filter_issues_warning_sub using (var context = CreateContext()) { var query = context.Customers.Where(c => c.CustomerID == "ALFKI" && c.Orders.FirstOrDefault().OrderID > 1000).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); } } @@ -119,8 +119,6 @@ public virtual void Max_does_not_issue_client_eval_warning_when_at_top_level() using (var context = CreateContext()) { var query = context.Orders.Select(o => o.OrderID).Max(); - - Assert.NotNull(query); } } diff --git a/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs b/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs index dfa9ae4f2a8..893cd423220 100644 --- a/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs +++ b/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs @@ -35,7 +35,7 @@ public virtual void Ignores_bool_with_default_value_false() Validate(model); - Assert.False(LoggerFactory.Log.Any(l => l.Level == LogLevel.Warning)); + Assert.DoesNotContain(LoggerFactory.Log, l => l.Level == LogLevel.Warning); } [ConditionalFact] diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs index b4b012dbe27..751bc5e5d2f 100644 --- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs +++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs @@ -193,8 +193,8 @@ public void Model_differ_breaks_foreign_key_cycles_in_create_table_operations() Assert.IsType(result[3]); var addFkOperation = Assert.IsType(result[4]); - Assert.Equal(0, createFirstTableOperation.ForeignKeys.Count); - Assert.Equal(1, createSecondTableOperation.ForeignKeys.Count); + Assert.Empty(createFirstTableOperation.ForeignKeys); + Assert.Single(createSecondTableOperation.ForeignKeys); Assert.Equal(createFirstTableOperation.Name, addFkOperation.Table); }); } @@ -266,9 +266,9 @@ public void Create_table() Assert.Equal(3, createTableOperation.Columns.Count); Assert.Null(createTableOperation.Columns.First(o => o.Name == "AltId").DefaultValue); Assert.NotNull(createTableOperation.PrimaryKey); - Assert.Equal(1, createTableOperation.UniqueConstraints.Count); - Assert.Equal(1, createTableOperation.CheckConstraints.Count); - Assert.Equal(1, createTableOperation.ForeignKeys.Count); + Assert.Single(createTableOperation.UniqueConstraints); + Assert.Single(createTableOperation.CheckConstraints); + Assert.Single(createTableOperation.ForeignKeys); Assert.IsType(upOps[2]); }, @@ -809,9 +809,9 @@ public void Create_shared_table_with_two_types() Assert.Equal("Animal", createTableOperation.Name); Assert.Equal("Id", createTableOperation.PrimaryKey.Columns.Single()); Assert.Equal(new[] { "Id", "MouseId", "BoneId" }, createTableOperation.Columns.Select(c => c.Name)); - Assert.Equal(0, createTableOperation.ForeignKeys.Count); - Assert.Equal(0, createTableOperation.UniqueConstraints.Count); - Assert.Equal(0, createTableOperation.CheckConstraints.Count); + Assert.Empty(createTableOperation.ForeignKeys); + Assert.Empty(createTableOperation.UniqueConstraints); + Assert.Empty(createTableOperation.CheckConstraints); }, downOps => { @@ -4671,7 +4671,7 @@ public void Create_table_with_foreign_key_on_base_type() var createTableOperation = Assert.IsType(operations[1]); Assert.Equal("Animal", createTableOperation.Name); - Assert.Equal(1, createTableOperation.ForeignKeys.Count); + Assert.Single(createTableOperation.ForeignKeys); var addForeignKeyOperation = createTableOperation.ForeignKeys[0]; Assert.Equal("FK_Animal_Person_HandlerId", addForeignKeyOperation.Name); @@ -4712,7 +4712,7 @@ public void Create_table_with_foreign_key_on_subtype() var createTableOperation = Assert.IsType(operations[1]); Assert.Equal("Animal", createTableOperation.Name); - Assert.Equal(1, createTableOperation.ForeignKeys.Count); + Assert.Single(createTableOperation.ForeignKeys); var addForeignKeyOperation = createTableOperation.ForeignKeys[0]; Assert.Equal("FK_Animal_Person_HandlerId", addForeignKeyOperation.Name); @@ -4753,7 +4753,7 @@ public void Create_table_with_foreign_key_to_subtype() var createTableOperation = Assert.IsType(operations[1]); Assert.Equal("Person", createTableOperation.Name); - Assert.Equal(1, createTableOperation.ForeignKeys.Count); + Assert.Single(createTableOperation.ForeignKeys); var addForeignKeyOperation = createTableOperation.ForeignKeys[0]; Assert.Equal("FK_Person_Animal_PetId", addForeignKeyOperation.Name); @@ -4790,7 +4790,7 @@ public void Create_table_with_selfReferencing_foreign_key_in_hierarchy() Assert.Equal(2, operations.Count); var createTableOperation = Assert.IsType(operations[0]); - Assert.Equal(1, createTableOperation.ForeignKeys.Count); + Assert.Single(createTableOperation.ForeignKeys); var addForeignKeyOperation = createTableOperation.ForeignKeys[0]; Assert.Equal("FK_Animal_Animal_PreyId", addForeignKeyOperation.Name); @@ -5508,7 +5508,7 @@ public void Create_table_with_foreign_key_referencing_renamed_table() Assert.IsType(operations[1]); var createTableOperation = Assert.IsType(operations[2]); - Assert.Equal(1, createTableOperation.ForeignKeys.Count); + Assert.Single(createTableOperation.ForeignKeys); var addForeignKeyOperation = createTableOperation.ForeignKeys[0]; Assert.Equal("new", addForeignKeyOperation.PrincipalSchema); @@ -5541,7 +5541,7 @@ public void Create_table_with_foreign_key_referencing_renamed_column() Assert.IsType(operations[0]); var createTableOperation = Assert.IsType(operations[1]); - Assert.Equal(1, createTableOperation.ForeignKeys.Count); + Assert.Single(createTableOperation.ForeignKeys); var addForeignKeyOperation = createTableOperation.ForeignKeys[0]; Assert.Equal(new[] { "ReferencedTableId" }, addForeignKeyOperation.PrincipalColumns); @@ -6144,7 +6144,7 @@ public void Add_foreign_key_referencing_added_alternate_key_with_seed_data() { var operation = Assert.IsType(o); Assert.Equal("ReferencingTable", operation.Name); - Assert.Equal(1, operation.ForeignKeys.Count); + Assert.Single(operation.ForeignKeys); }, o => { diff --git a/test/EFCore.Relational.Tests/Storage/RelationalCommandTest.cs b/test/EFCore.Relational.Tests/Storage/RelationalCommandTest.cs index 82d004bb960..b1e8d03f42f 100644 --- a/test/EFCore.Relational.Tests/Storage/RelationalCommandTest.cs +++ b/test/EFCore.Relational.Tests/Storage/RelationalCommandTest.cs @@ -407,7 +407,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Throws_when_parameters_are_configured_and_parameter_values_is_null( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var fakeConnection = CreateConnection(); @@ -444,7 +446,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Throws_when_parameters_are_configured_and_value_is_missing( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var fakeConnection = CreateConnection(); @@ -483,7 +487,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Configures_DbCommand_with_type_mapped_parameters( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var fakeConnection = CreateConnection(); @@ -544,7 +550,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Configures_DbCommand_with_dynamic_parameters( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var fakeConnection = CreateConnection(); @@ -607,7 +615,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Configures_DbCommand_with_composite_parameters( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var fakeConnection = CreateConnection(); @@ -671,7 +681,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Throws_when_composite_parameters_are_configured_and_value_is_missing( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var fakeConnection = CreateConnection(); @@ -716,7 +728,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Throws_when_composite_parameters_are_configured_and_value_is_not_object_array( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var fakeConnection = CreateConnection(); @@ -758,7 +772,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Disposes_command_on_exception( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var exception = new InvalidOperationException(); @@ -801,7 +817,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Closes_managed_connections_on_exception( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var exception = new InvalidOperationException(); @@ -848,7 +866,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Does_not_close_unmanaged_connections_on_exception( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string telemetryName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var exception = new InvalidOperationException(); @@ -895,7 +915,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Logs_commands_without_parameter_values( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string diagnosticName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var options = CreateOptions(); @@ -949,7 +971,9 @@ public static TheoryData CommandActions [MemberData(nameof(CommandActions))] public async Task Logs_commands_parameter_values( Delegate commandDelegate, +#pragma warning disable xUnit1026 // Theory methods should use all of their parameters string diagnosticName, +#pragma warning restore xUnit1026 // Theory methods should use all of their parameters bool async) { var optionsExtension = new FakeRelationalOptionsExtension().WithConnectionString(ConnectionString); diff --git a/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs b/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs index 920dae958ff..dafc442e6d7 100644 --- a/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs +++ b/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs @@ -34,7 +34,7 @@ public void BatchCommands_creates_valid_batch_for_added_entities() var modelData = new UpdateAdapter(stateManager); var commandBatches = CreateCommandBatchPreparer().BatchCommands(new[] { entry }, modelData).ToArray(); - Assert.Equal(1, commandBatches.Length); + Assert.Single(commandBatches); Assert.Equal(1, commandBatches.First().ModificationCommands.Count); var command = commandBatches.First().ModificationCommands.Single(); @@ -75,7 +75,7 @@ public void BatchCommands_creates_valid_batch_for_modified_entities() var modelData = new UpdateAdapter(stateManager); var commandBatches = CreateCommandBatchPreparer().BatchCommands(new[] { entry }, modelData).ToArray(); - Assert.Equal(1, commandBatches.Length); + Assert.Single(commandBatches); Assert.Equal(1, commandBatches.First().ModificationCommands.Count); var command = commandBatches.First().ModificationCommands.Single(); @@ -116,7 +116,7 @@ public void BatchCommands_creates_valid_batch_for_deleted_entities() var modelData = new UpdateAdapter(stateManager); var commandBatches = CreateCommandBatchPreparer().BatchCommands(new[] { entry }, modelData).ToArray(); - Assert.Equal(1, commandBatches.Length); + Assert.Single(commandBatches); Assert.Equal(1, commandBatches.First().ModificationCommands.Count); var command = commandBatches.First().ModificationCommands.Single(); @@ -520,7 +520,7 @@ public void BatchCommands_creates_valid_batch_for_shared_table_added_entities() var commandBatches = CreateCommandBatchPreparer(updateAdapter: modelData) .BatchCommands(new[] { firstEntry, secondEntry }, modelData) .ToArray(); - Assert.Equal(1, commandBatches.Length); + Assert.Single(commandBatches); Assert.Equal(1, commandBatches.First().ModificationCommands.Count); var command = commandBatches.First().ModificationCommands.Single(); @@ -575,7 +575,7 @@ public void BatchCommands_creates_valid_batch_for_shared_table_modified_entities .BatchCommands(new[] { entry }, modelData) .ToArray(); - Assert.Equal(1, commandBatches.Length); + Assert.Single(commandBatches); Assert.Equal(1, commandBatches.First().ModificationCommands.Count); var command = commandBatches.First().ModificationCommands.Single(); @@ -631,7 +631,7 @@ public void BatchCommands_creates_valid_batch_for_shared_table_deleted_entities( var commandBatches = CreateCommandBatchPreparer(updateAdapter: modelData) .BatchCommands(new[] { firstEntry, secondEntry }, modelData).ToArray(); - Assert.Equal(1, commandBatches.Length); + Assert.Single(commandBatches); Assert.Equal(1, commandBatches.First().ModificationCommands.Count); var command = commandBatches.First().ModificationCommands.Single(); @@ -837,7 +837,7 @@ public void BatchCommands_works_with_incomplete_updates_for_shared_table_no_leaf var batches = CreateCommandBatchPreparer(updateAdapter: modelData, sensitiveLogging: false) .BatchCommands(new[] { firstEntry, secondEntry }, modelData).ToArray(); - Assert.Equal(1, batches.Length); + Assert.Single(batches); } [InlineData(EntityState.Added, true)] diff --git a/test/EFCore.Specification.Tests/BuiltInDataTypesTestBase.cs b/test/EFCore.Specification.Tests/BuiltInDataTypesTestBase.cs index 8aee2d3e120..cf451aa8f2d 100644 --- a/test/EFCore.Specification.Tests/BuiltInDataTypesTestBase.cs +++ b/test/EFCore.Specification.Tests/BuiltInDataTypesTestBase.cs @@ -45,7 +45,7 @@ public virtual async Task Can_filter_projection_with_captured_enum_variable(bool ? await query.ToListAsync() : query.ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); Assert.Equal(EmailTemplateTypeDto.PasswordResetRequest, results.Single().TemplateType); } } @@ -67,7 +67,7 @@ public virtual async Task Can_filter_projection_with_inline_enum_variable(bool a ? await query.ToListAsync() : query.ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); Assert.Equal(EmailTemplateTypeDto.PasswordResetRequest, results.Single().TemplateType); } } diff --git a/test/EFCore.Specification.Tests/DataAnnotationTestBase.cs b/test/EFCore.Specification.Tests/DataAnnotationTestBase.cs index 2af74b734f9..18be1118c85 100644 --- a/test/EFCore.Specification.Tests/DataAnnotationTestBase.cs +++ b/test/EFCore.Specification.Tests/DataAnnotationTestBase.cs @@ -710,8 +710,7 @@ public virtual ModelBuilder Key_property_is_not_used_for_FK_when_set_by_annotati modelBuilder.Entity(); var toy = modelBuilder.Entity(); - Assert.False( - toy.Metadata.GetForeignKeys().Any(fk => fk.IsUnique == false && fk.Properties.Any(p => p.Name == nameof(Toy.IdRow)))); + Assert.DoesNotContain(toy.Metadata.GetForeignKeys(), fk => fk.IsUnique == false && fk.Properties.Any(p => p.Name == nameof(Toy.IdRow))); Validate(modelBuilder); @@ -1605,7 +1604,7 @@ public virtual void InversePropertyAttribute_from_ignored_base_causes_ambiguity( Assert.Null(model.FindEntityType(typeof(AnotherBookLabel)).FindNavigation(nameof(AnotherBookLabel.Book))); Assert.Null(model.FindEntityType(typeof(SpecialBookLabel)).FindNavigation(nameof(SpecialBookLabel.Book))); - Assert.Equal(0, model.FindEntityType(typeof(Book)).GetNavigations().Count()); + Assert.Empty(model.FindEntityType(typeof(Book)).GetNavigations()); } [ConditionalFact] diff --git a/test/EFCore.Specification.Tests/DatabindingTestBase.cs b/test/EFCore.Specification.Tests/DatabindingTestBase.cs index e85674b6495..925e3f9d81a 100644 --- a/test/EFCore.Specification.Tests/DatabindingTestBase.cs +++ b/test/EFCore.Specification.Tests/DatabindingTestBase.cs @@ -328,7 +328,7 @@ protected void SetupContext(F1Context context) Assert.Same(larry, context.Drivers.Find(-1)); Assert.Equal(EntityState.Added, context.Entry(larry).State); Assert.Equal(1, local.Count); - Assert.Equal(1, localView.Count); + Assert.Single(localView); Assert.Contains(larry, local); Assert.Contains(larry, localView); } @@ -551,7 +551,7 @@ public virtual void Load_executes_query_on_DbQuery() Assert.All(context.ChangeTracker.Entries().Select(e => e.Entity), e => Assert.True(teamsLocal.Contains(e))); Assert.All( - context.ChangeTracker.Entries().Select(e => e.Entity), e => Assert.False(teamsLocal.Contains((object)e))); + context.ChangeTracker.Entries().Select(e => e.Entity), e => Assert.DoesNotContain((object)e, teamsLocal)); } } @@ -578,13 +578,13 @@ public virtual void Adding_entity_to_context_is_reflected_in_local_binding_list( { var bindingList = context.Drivers.Local.ToBindingList(); - Assert.Equal(0, bindingList.Count); + Assert.Empty(bindingList); var larry = new Driver { Name = "Larry David", TeamId = Team.Ferrari, CarNumber = 13 }; context.Drivers.Add(larry); - Assert.True(bindingList.Contains(larry)); - Assert.Equal(1, bindingList.Count); + Assert.Contains(larry, bindingList); + Assert.Single(bindingList); } } @@ -595,7 +595,7 @@ public virtual void Entities_materialized_into_context_are_reflected_in_local_bi { var bindingList = context.Drivers.Local.ToBindingList(); - Assert.Equal(0, bindingList.Count); + Assert.Empty(bindingList); context.Drivers.Where(d => d.TeamId == UnchangedTeam).Load(); @@ -652,7 +652,7 @@ public virtual void Entities_added_to_local_binding_list_are_added_to_state_mana var observable = local.ToObservableCollection(); var bindingList = local.ToBindingList(); - Assert.Equal(0, bindingList.Count); + Assert.Empty(bindingList); var larry = new Driver { Id = -1, Name = "Larry David", TeamId = Team.Ferrari, CarNumber = 13 }; @@ -660,9 +660,9 @@ public virtual void Entities_added_to_local_binding_list_are_added_to_state_mana Assert.Same(larry, context.Drivers.Find(-1)); Assert.Equal(EntityState.Added, context.Entry(larry).State); - Assert.Equal(1, bindingList.Count); - Assert.Equal(1, local.Count); - Assert.Equal(1, observable.Count); + Assert.Single(bindingList); + Assert.Single(local); + Assert.Single(observable); Assert.Contains(larry, bindingList); Assert.Contains(larry, local); Assert.Contains(larry, observable); @@ -757,7 +757,7 @@ public virtual void Adding_entity_to_state_manager_of_subtype_still_shows_up_in_ var testDriver = new TestDriver(); context.Drivers.Add(testDriver); - Assert.True(bindingList.Contains(testDriver)); + Assert.Contains(testDriver, bindingList); } } @@ -848,11 +848,11 @@ public virtual void Entity_added_to_navigation_property_binding_list_is_added_to var larry = new Driver { Id = -1, Name = "Larry David", TeamId = Team.Ferrari, CarNumber = 13 }; navBindingList.Add(larry); - Assert.False(localDrivers.Contains(larry)); + Assert.DoesNotContain(larry, localDrivers); context.ChangeTracker.DetectChanges(); - Assert.True(localDrivers.Contains(larry)); + Assert.Contains(larry, localDrivers); Assert.Same(larry, context.Drivers.Find(-1)); } } @@ -876,17 +876,17 @@ public virtual void Entity_added_to_navigation_property_binding_list_is_added_to var alonso = localDrivers.Single(d => d.Name == "Fernando Alonso"); navBindingList.Remove(alonso); - Assert.True(localDrivers.Contains(alonso)); + Assert.Contains(alonso, localDrivers); context.ChangeTracker.DetectChanges(); if (deleteOrphansTiming == CascadeTiming.Immediate) { - Assert.False(localDrivers.Contains(alonso)); + Assert.DoesNotContain(alonso, localDrivers); } else { - Assert.True(localDrivers.Contains(alonso)); // Because it is not marked as Deleted + Assert.Contains(alonso, localDrivers); // Because it is not marked as Deleted } Assert.False(ferrari.Drivers.Contains(alonso)); // But has been removed from nav prop diff --git a/test/EFCore.Specification.Tests/EFCore.Specification.Tests.csproj b/test/EFCore.Specification.Tests/EFCore.Specification.Tests.csproj index 907865611e8..1eb7470b62e 100644 --- a/test/EFCore.Specification.Tests/EFCore.Specification.Tests.csproj +++ b/test/EFCore.Specification.Tests/EFCore.Specification.Tests.csproj @@ -19,6 +19,7 @@ + diff --git a/test/EFCore.Specification.Tests/EntityFrameworkServiceCollectionExtensionsTestBase.cs b/test/EFCore.Specification.Tests/EntityFrameworkServiceCollectionExtensionsTestBase.cs index 9e627a3b9a9..84bc82851d7 100644 --- a/test/EFCore.Specification.Tests/EntityFrameworkServiceCollectionExtensionsTestBase.cs +++ b/test/EFCore.Specification.Tests/EntityFrameworkServiceCollectionExtensionsTestBase.cs @@ -59,7 +59,7 @@ public virtual void Required_services_are_registered_with_expected_lifetimes() } else { - Assert.Equal(1, registered.Count); + Assert.Single(registered); Assert.Equal(coreService.Value.Lifetime, registered[0].Lifetime); } } diff --git a/test/EFCore.Specification.Tests/FieldMappingTestBase.cs b/test/EFCore.Specification.Tests/FieldMappingTestBase.cs index 98e3d0d269b..0cb105d7a7f 100644 --- a/test/EFCore.Specification.Tests/FieldMappingTestBase.cs +++ b/test/EFCore.Specification.Tests/FieldMappingTestBase.cs @@ -796,7 +796,7 @@ protected virtual void Query_with_conditional_param(string property, bool { var posts = context.Set().Where(p => EF.Property(p, property) == postTitle).AsTracking(tracking).ToList(); - Assert.Equal(1, posts.Count); + Assert.Single(posts); var post = posts.Single(e => e.AccessId == 11); Assert.Equal("Post11", post.AccessTitle); @@ -924,8 +924,8 @@ private static void AssertBlogs(IEnumerable posts, bool tracking, Assert.NotSame(blog1a, blog1b); Assert.Equal(blogName, blog1a.AccessTitle); Assert.Equal(blogName, blog1b.AccessTitle); - Assert.Equal(1, blog1a.AccessPosts.Count()); - Assert.Equal(1, blog1b.AccessPosts.Count()); + Assert.Single(blog1a.AccessPosts); + Assert.Single(blog1b.AccessPosts); } AssertPost(posts.Single(e => e.AccessId == post1Id), post1Id, blog1a); diff --git a/test/EFCore.Specification.Tests/GraphUpdatesTestBase.cs b/test/EFCore.Specification.Tests/GraphUpdatesTestBase.cs index 1af72e3102f..80504aeb9bc 100644 --- a/test/EFCore.Specification.Tests/GraphUpdatesTestBase.cs +++ b/test/EFCore.Specification.Tests/GraphUpdatesTestBase.cs @@ -215,7 +215,7 @@ public abstract partial class GraphUpdatesTestBase : IClassFixture : IClassFixture e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removed1Id)); @@ -1436,6 +1436,7 @@ public virtual void Detaching_dependent_entity_will_remove_references_to_it() }); } + [ConditionalTheory] [InlineData((int)ChangeMechanism.Principal, false, CascadeTiming.OnSaveChanges)] [InlineData((int)ChangeMechanism.Principal, true, CascadeTiming.OnSaveChanges)] [InlineData((int)ChangeMechanism.Dependent, false, CascadeTiming.OnSaveChanges)] @@ -3230,8 +3231,8 @@ public virtual void Detaching_dependent_entity_will_remove_references_to_it() AssertKeys(root, loadedRoot); AssertNavigations(loadedRoot); - Assert.Equal(1, loadedRoot.OptionalChildrenAk.Count()); - Assert.Equal(1, loadedRoot.OptionalChildrenAk.OrderBy(c => c.Id).First().Children.Count()); + Assert.Single(loadedRoot.OptionalChildrenAk); + Assert.Single(loadedRoot.OptionalChildrenAk.OrderBy(c => c.Id).First().Children); } }); } @@ -3345,9 +3346,9 @@ public virtual void Detaching_dependent_entity_will_remove_references_to_it() Assert.False(context.Set().Any(e => e.Id == removed2.Id)); Assert.False(context.Set().Any(e => e.Id == removed2c.Id)); - Assert.Equal(1, loadedRoot.RequiredChildrenAk.Count()); - Assert.Equal(1, loadedRoot.RequiredChildrenAk.OrderBy(c => c.Id).First().Children.Count()); - Assert.Equal(1, loadedRoot.RequiredChildrenAk.OrderBy(c => c.Id).First().CompositeChildren.Count()); + Assert.Single(loadedRoot.RequiredChildrenAk); + Assert.Single(loadedRoot.RequiredChildrenAk.OrderBy(c => c.Id).First().Children); + Assert.Single(loadedRoot.RequiredChildrenAk.OrderBy(c => c.Id).First().CompositeChildren); } }); } @@ -3873,6 +3874,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store }); } + [ConditionalTheory] [InlineData((int)ChangeMechanism.Principal, false, CascadeTiming.OnSaveChanges)] [InlineData((int)ChangeMechanism.Principal, true, CascadeTiming.OnSaveChanges)] [InlineData((int)ChangeMechanism.Dependent, false, CascadeTiming.OnSaveChanges)] @@ -4896,7 +4898,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); Assert.True(cascadeRemoved.All(e => context.Entry(e).State == EntityState.Detached)); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4913,7 +4915,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadRequiredGraph(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4967,7 +4969,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.False(context.ChangeTracker.HasChanges()); Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, parent.Children.Count()); + Assert.Single(parent.Children); Assert.DoesNotContain(removedId, parent.Children.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4979,7 +4981,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store var root = LoadRequiredGraph(context); var parent = root.RequiredChildren.First(); - Assert.Equal(1, parent.Children.Count()); + Assert.Single(parent.Children); Assert.DoesNotContain(removedId, parent.Children.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5051,7 +5053,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); Assert.True(orphaned.All(e => context.Entry(e).State == EntityState.Unchanged)); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5067,7 +5069,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadOptionalGraph(context); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5121,7 +5123,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, parent.Children.Count()); + Assert.Single(parent.Children); Assert.DoesNotContain(removedId, parent.Children.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5133,7 +5135,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store var root = LoadOptionalGraph(context); var parent = root.OptionalChildren.First(); - Assert.Equal(1, parent.Children.Count()); + Assert.Single(parent.Children); Assert.DoesNotContain(removedId, parent.Children.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5638,7 +5640,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); Assert.True(orphaned.All(e => context.Entry(e).State == EntityState.Unchanged)); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5654,7 +5656,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadOptionalAkGraph(context); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5744,7 +5746,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.True(cascadeRemoved.All(e => context.Entry(e).State == EntityState.Detached)); Assert.True(cascadeRemovedC.All(e => context.Entry(e).State == EntityState.Detached)); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5761,7 +5763,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadRequiredAkGraph(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -6119,14 +6121,14 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); Assert.Empty(context.Set().Where(e => orphanedIds.Contains(e.Id))); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); + Assert.Empty(removed.Children); } }, context => @@ -6136,7 +6138,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadRequiredGraph(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -6372,7 +6374,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -6380,7 +6382,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Empty(context.Set().Where(e => orphanedIdCs.Contains(e.Id))); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); // Never loaded + Assert.Empty(removed.Children); // Never loaded } }, context => @@ -6390,7 +6392,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadRequiredAkGraph(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -6629,7 +6631,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -6639,7 +6641,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.True(orphaned.All(e => e.ParentId == null)); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); // Never loaded + Assert.Empty(removed.Children); // Never loaded } }, context => @@ -6648,7 +6650,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadOptionalGraph(context); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -6807,7 +6809,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -6821,7 +6823,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store Assert.True(orphanedC.All(e => e.ParentId == null)); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); // Never loaded + Assert.Empty(removed.Children); // Never loaded } }, context => @@ -6830,7 +6832,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadOptionalAkGraph(context); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -7022,7 +7024,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { root = LoadRequiredGraph(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -7113,7 +7115,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { root = LoadOptionalGraph(context); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -7473,7 +7475,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { root = LoadOptionalAkGraph(context); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -7577,7 +7579,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { root = LoadRequiredAkGraph(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -7967,7 +7969,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadRequiredGraph(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -8299,7 +8301,7 @@ public virtual void Save_changed_optional_one_to_one_with_alternate_key_in_store { var root = LoadRequiredAkGraph(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); diff --git a/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs b/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs index 301a89f175d..795cd6d7b5d 100644 --- a/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs +++ b/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs @@ -445,7 +445,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK(EntityS RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -484,7 +484,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK(EntitySt RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -629,8 +629,8 @@ public virtual void Lazy_load_collection_not_found(EntityState state) RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(0, parent.Children.Count()); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Empty(parent.Children); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -669,7 +669,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_not_found(Entit RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -709,7 +709,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_not_found(Entity RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -750,7 +750,7 @@ public virtual void Lazy_load_one_to_one_reference_to_dependent_not_found(Entity RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(parent.Single); } @@ -1169,7 +1169,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK_alterna RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -1202,7 +1202,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK_alternat RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -1370,7 +1370,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK_shadow_ RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -1403,7 +1403,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK_shadow_f RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -1572,7 +1572,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK_composi RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -1606,7 +1606,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK_composit RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } diff --git a/test/EFCore.Specification.Tests/LoadTestBase.cs b/test/EFCore.Specification.Tests/LoadTestBase.cs index c63c7124bed..9c0eace1ad1 100644 --- a/test/EFCore.Specification.Tests/LoadTestBase.cs +++ b/test/EFCore.Specification.Tests/LoadTestBase.cs @@ -296,7 +296,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK(EntityS RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -333,7 +333,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK(EntitySt RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -371,8 +371,8 @@ public virtual void Lazy_load_collection_not_found(EntityState state) RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(0, parent.Children.Count()); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Empty(parent.Children); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -408,7 +408,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_not_found(Entit RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -445,7 +445,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_not_found(Entity RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -483,7 +483,7 @@ public virtual void Lazy_load_one_to_one_reference_to_dependent_not_found(Entity RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(parent.Single); } @@ -883,7 +883,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK_alterna RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -914,7 +914,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK_alternat RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -1080,7 +1080,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK_shadow_ RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -1111,7 +1111,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK_shadow_f RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -1277,7 +1277,7 @@ public virtual void Lazy_load_many_to_one_reference_to_principal_null_FK_composi RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -1308,7 +1308,7 @@ public virtual void Lazy_load_one_to_one_reference_to_principal_null_FK_composit RecordLog(); context.ChangeTracker.LazyLoadingEnabled = false; - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -2006,7 +2006,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_null_FK(Entity RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -2046,7 +2046,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_null_FK(EntityS RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -2085,7 +2085,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_using_Query_nu Assert.Null(parent); Assert.Null(child.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -2122,7 +2122,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_using_Query_nul Assert.Null(parent); Assert.Null(single.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -2161,8 +2161,8 @@ public virtual async Task Load_collection_not_found(EntityState state, bool asyn RecordLog(); - Assert.Equal(0, parent.Children.Count()); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Empty(parent.Children); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -2201,7 +2201,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_not_found(Enti RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -2241,7 +2241,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_not_found(Entit RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -2282,7 +2282,7 @@ public virtual async Task Load_one_to_one_reference_to_dependent_not_found(Entit RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(parent.Single); } @@ -2318,10 +2318,10 @@ public virtual async Task Load_collection_using_Query_not_found(EntityState stat RecordLog(); - Assert.Equal(0, children.Count); - Assert.Equal(0, parent.Children.Count()); + Assert.Empty(children); + Assert.Empty(parent.Children); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -2358,7 +2358,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_using_Query_no Assert.Null(parent); Assert.Null(child.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -2395,7 +2395,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_using_Query_not Assert.Null(parent); Assert.Null(single.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -2432,7 +2432,7 @@ public virtual async Task Load_one_to_one_reference_to_dependent_using_Query_not Assert.Null(single); Assert.Null(parent.Single); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -3335,8 +3335,8 @@ public virtual async Task Load_collection_not_found_untyped(EntityState state, b RecordLog(); - Assert.Equal(0, parent.Children.Count()); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Empty(parent.Children); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -3375,7 +3375,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_not_found_unty RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -3415,7 +3415,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_not_found_untyp RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -3456,7 +3456,7 @@ public virtual async Task Load_one_to_one_reference_to_dependent_not_found_untyp RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(parent.Single); } @@ -3493,10 +3493,10 @@ public virtual async Task Load_collection_using_Query_not_found_untyped(EntitySt RecordLog(); - Assert.Equal(0, children.Count); - Assert.Equal(0, parent.Children.Count()); + Assert.Empty(children); + Assert.Empty(parent.Children); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -3534,7 +3534,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_using_Query_no Assert.Null(parent); Assert.Null(child.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -3572,7 +3572,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_using_Query_not Assert.Null(parent); Assert.Null(single.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -3610,7 +3610,7 @@ public virtual async Task Load_one_to_one_reference_to_dependent_using_Query_not Assert.Null(single); Assert.Null(parent.Single); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -4346,7 +4346,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_null_FK_altern RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -4386,7 +4386,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_null_FK_alterna RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -4425,7 +4425,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_using_Query_nu Assert.Null(parent); Assert.Null(child.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -4462,7 +4462,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_using_Query_nul Assert.Null(parent); Assert.Null(single.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -4820,7 +4820,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_null_FK_shadow RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -4860,7 +4860,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_null_FK_shadow_ RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -4899,7 +4899,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_using_Query_nu Assert.Null(parent); Assert.Null(child.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -4936,7 +4936,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_using_Query_nul Assert.Null(parent); Assert.Null(single.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -5294,7 +5294,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_null_FK_compos RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(child.Parent); } } @@ -5334,7 +5334,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_null_FK_composi RecordLog(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Null(single.Parent); } @@ -5373,7 +5373,7 @@ public virtual async Task Load_many_to_one_reference_to_principal_using_Query_nu Assert.Null(parent); Assert.Null(child.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -5410,7 +5410,7 @@ public virtual async Task Load_one_to_one_reference_to_principal_using_Query_nul Assert.Null(parent); Assert.Null(single.Parent); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -5431,8 +5431,8 @@ public virtual void Can_change_IsLoaded_flag_for_collection() collectionEntry.Load(); - Assert.Equal(0, parent.Children.Count()); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Empty(parent.Children); + Assert.Single(context.ChangeTracker.Entries()); Assert.True(collectionEntry.IsLoaded); @@ -5469,7 +5469,7 @@ public virtual void Can_change_IsLoaded_flag_for_reference_only_if_null() Assert.True(referenceEntry.IsLoaded); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); referenceEntry.IsLoaded = true; diff --git a/test/EFCore.Specification.Tests/ProxyGraphUpdatesTestBase.cs b/test/EFCore.Specification.Tests/ProxyGraphUpdatesTestBase.cs index 8e0ecb8d943..7239f3be749 100644 --- a/test/EFCore.Specification.Tests/ProxyGraphUpdatesTestBase.cs +++ b/test/EFCore.Specification.Tests/ProxyGraphUpdatesTestBase.cs @@ -96,7 +96,7 @@ public virtual void No_fixup_to_Deleted_entities() Assert.Null(existing.Parent); Assert.Null(existing.ParentId); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(existing, root.OptionalChildren); Assert.Equal(2, queried.Count); @@ -405,8 +405,8 @@ public virtual void Save_removed_optional_many_to_one_dependents(ChangeMechanism { var loadedRoot = LoadRoot(context); - Assert.Equal(1, loadedRoot.OptionalChildren.Count()); - Assert.Equal(1, loadedRoot.OptionalChildren.First().Children.Count()); + Assert.Single(loadedRoot.OptionalChildren); + Assert.Single(loadedRoot.OptionalChildren.First().Children); } }); } @@ -466,7 +466,7 @@ public virtual void Save_removed_required_many_to_one_dependents(ChangeMechanism { var root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removed1Id, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removed1Id)); @@ -1836,8 +1836,8 @@ public virtual void Save_removed_optional_many_to_one_dependents_with_alternate_ { var loadedRoot = LoadRoot(context); - Assert.Equal(1, loadedRoot.OptionalChildrenAk.Count()); - Assert.Equal(1, loadedRoot.OptionalChildrenAk.First().Children.Count()); + Assert.Single(loadedRoot.OptionalChildrenAk); + Assert.Single(loadedRoot.OptionalChildrenAk.First().Children); } }); } @@ -1905,9 +1905,9 @@ public virtual void Save_removed_required_many_to_one_dependents_with_alternate_ Assert.False(context.Set().Any(e => e.Id == removed2.Id)); Assert.False(context.Set().Any(e => e.Id == removed2c.Id)); - Assert.Equal(1, loadedRoot.RequiredChildrenAk.Count()); - Assert.Equal(1, loadedRoot.RequiredChildrenAk.First().Children.Count()); - Assert.Equal(1, loadedRoot.RequiredChildrenAk.First().CompositeChildren.Count()); + Assert.Single(loadedRoot.RequiredChildrenAk); + Assert.Single(loadedRoot.RequiredChildrenAk.First().Children); + Assert.Single(loadedRoot.RequiredChildrenAk.First().CompositeChildren); }); } @@ -2971,7 +2971,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Equal(EntityState.Detached, context.Entry(removed).State); Assert.True(cascadeRemoved.All(e => context.Entry(e).State == EntityState.Detached)); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -2987,7 +2987,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { var root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3042,7 +3042,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Equal(EntityState.Detached, context.Entry(removed).State); Assert.True(orphaned.All(e => context.Entry(e).State == EntityState.Unchanged)); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3055,7 +3055,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { var root = LoadRoot(context); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3313,7 +3313,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Equal(EntityState.Detached, context.Entry(removed).State); Assert.True(orphaned.All(e => context.Entry(e).State == EntityState.Unchanged)); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3326,7 +3326,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { var root = LoadRoot(context); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3391,7 +3391,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.True(cascadeRemoved.All(e => context.Entry(e).State == EntityState.Detached)); Assert.True(cascadeRemovedC.All(e => context.Entry(e).State == EntityState.Detached)); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3407,7 +3407,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { var root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3680,20 +3680,20 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); Assert.Empty(context.Set().Where(e => orphanedIds.Contains(e.Id))); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); + Assert.Empty(removed.Children); }, context => { var root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3898,7 +3898,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -3906,13 +3906,13 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Empty(context.Set().Where(e => orphanedIdCs.Contains(e.Id))); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); // Never loaded + Assert.Empty(removed.Children); // Never loaded }, context => { var root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4121,7 +4121,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4131,13 +4131,13 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.True(orphaned.All(e => e.ParentId == null)); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); // Never loaded + Assert.Empty(removed.Children); // Never loaded }, context => { var root = LoadRoot(context); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4266,7 +4266,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.Equal(EntityState.Detached, context.Entry(removed).State); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4280,13 +4280,13 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang Assert.True(orphanedC.All(e => e.ParentId == null)); Assert.Same(root, removed.Parent); - Assert.Equal(0, removed.Children.Count()); // Never loaded + Assert.Empty(removed.Children); // Never loaded }, context => { var root = LoadRoot(context); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4447,7 +4447,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4521,7 +4521,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { root = LoadRoot(context); - Assert.Equal(1, root.OptionalChildren.Count()); + Assert.Single(root.OptionalChildren); Assert.DoesNotContain(removedId, root.OptionalChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4824,7 +4824,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { root = LoadRoot(context); - Assert.Equal(1, root.OptionalChildrenAk.Count()); + Assert.Single(root.OptionalChildrenAk); Assert.DoesNotContain(removedId, root.OptionalChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -4913,7 +4913,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5250,7 +5250,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { var root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildren.Count()); + Assert.Single(root.RequiredChildren); Assert.DoesNotContain(removedId, root.RequiredChildren.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); @@ -5519,7 +5519,7 @@ public virtual void Reparent_required_non_PK_one_to_one_with_alternate_key(Chang { var root = LoadRoot(context); - Assert.Equal(1, root.RequiredChildrenAk.Count()); + Assert.Single(root.RequiredChildrenAk); Assert.DoesNotContain(removedId, root.RequiredChildrenAk.Select(e => e.Id)); Assert.Empty(context.Set().Where(e => e.Id == removedId)); diff --git a/test/EFCore.Specification.Tests/Query/AsNoTrackingTestBase.cs b/test/EFCore.Specification.Tests/Query/AsNoTrackingTestBase.cs index f83bff803d9..a8aec6804c6 100644 --- a/test/EFCore.Specification.Tests/Query/AsNoTrackingTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/AsNoTrackingTestBase.cs @@ -30,7 +30,7 @@ public virtual void Entity_not_added_to_state_manager(bool useParam) : context.Set().AsNoTracking().ToList(); Assert.Equal(91, customers.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -48,7 +48,7 @@ var customers .ToList(); Assert.Equal(6, customers.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -65,7 +65,7 @@ var customers .ToList(); Assert.Equal(830, customers.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -83,7 +83,7 @@ var customers .ToList(); Assert.Equal(6, customers.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -102,7 +102,7 @@ var customers .ToList(); Assert.Equal(6, customers.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } diff --git a/test/EFCore.Specification.Tests/Query/AsyncGearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/AsyncGearsOfWarQueryTestBase.cs index cd8df4bc7da..75945476567 100644 --- a/test/EFCore.Specification.Tests/Query/AsyncGearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/AsyncGearsOfWarQueryTestBase.cs @@ -82,7 +82,7 @@ public virtual async Task Include_groupby_constant() var query = ctx.Squads.Include(s => s.Members).GroupBy(s => 1); var result = await query.ToListAsync(); - Assert.Equal(1, result.Count); + Assert.Single(result); var bucket = result[0].ToList(); Assert.Equal(2, bucket.Count); Assert.NotNull(bucket[0].Members); diff --git a/test/EFCore.Specification.Tests/Query/ChangeTrackingTestBase.cs b/test/EFCore.Specification.Tests/Query/ChangeTrackingTestBase.cs index c2cca231699..6aa14d28a5f 100644 --- a/test/EFCore.Specification.Tests/Query/ChangeTrackingTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ChangeTrackingTestBase.cs @@ -220,15 +220,15 @@ public virtual void Can_disable_and_reenable_query_result_tracking() var results = query.Take(1).ToList(); - Assert.Equal(1, results.Count); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(results); + Assert.Single(context.ChangeTracker.Entries()); context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; results = query.Skip(1).Take(1).ToList(); - Assert.Equal(1, results.Count); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(results); + Assert.Single(context.ChangeTracker.Entries()); context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; @@ -250,15 +250,15 @@ public virtual void Can_disable_and_reenable_query_result_tracking_starting_with var results = query.Take(1).ToList(); - Assert.Equal(1, results.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Single(results); + Assert.Empty(context.ChangeTracker.Entries()); context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; results = query.Skip(1).Take(1).ToList(); - Assert.Equal(1, results.Count); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(results); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -282,7 +282,7 @@ public virtual void Can_disable_and_reenable_query_result_tracking_query_caching var results = context.Employees.ToList(); Assert.Equal(9, results.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; } @@ -308,7 +308,7 @@ public virtual void Can_disable_and_reenable_query_result_tracking_query_caching var results = context.Employees.ToList(); Assert.Equal(9, results.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -324,7 +324,7 @@ public virtual void Can_disable_and_reenable_query_result_tracking_query_caching var results = context.Employees.ToList(); Assert.Equal(9, results.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; @@ -367,7 +367,7 @@ public virtual void Precedence_of_tracking_modifiers2() var results = context.Employees.AsTracking().AsNoTracking().ToList(); Assert.Equal(9, results.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -403,7 +403,7 @@ var customers .ToList(); Assert.Equal(6, customers.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -422,7 +422,7 @@ var customers .ToList(); Assert.Equal(6, customers.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs index f52ece77130..f1d6342c6fc 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs @@ -274,7 +274,7 @@ public virtual void Multi_level_include_with_short_circuiting() Assert.Equal("Language8", globalizations_1_label[2].Language.Name); var globalizations_1_placeholder = result[1].Placeholder.Globalizations.OrderBy(g => g.Text).ToList(); - Assert.Equal(1, globalizations_1_placeholder.Count); + Assert.Single(globalizations_1_placeholder); Assert.Equal("Globalization9", globalizations_1_placeholder[0].Text); Assert.Equal("Language9", globalizations_1_placeholder[0].Language.Name); } @@ -5181,7 +5181,7 @@ public virtual void SelectMany_navigation_property_with_include_and_followed_by_ var result = query.ToList(); Assert.True(result.All(r => r.l2.OneToMany_Required2 != null)); - Assert.True(result.Any(r => r.OneToMany_Optional2.Count > 0)); + Assert.Contains(result, r => r.OneToMany_Optional2.Count > 0); } } diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs index 87357a9b2af..ab47cc741af 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs @@ -112,7 +112,7 @@ public override Task Multiple_SelectMany_with_nested_navigations_and_explicit_De return base.SelectMany_with_nested_navigations_explicit_DefaultIfEmpty_and_additional_joins_outside_of_SelectMany2(isAsync); } - [ConditionalTheory(Skip = "issue #13560")] + [ConditionalFact(Skip = "issue #13560")] public override void SelectMany_with_nested_navigations_and_additional_joins_outside_of_SelectMany() { base.SelectMany_with_nested_navigations_and_additional_joins_outside_of_SelectMany(); diff --git a/test/EFCore.Specification.Tests/Query/FiltersInheritanceTestBase.cs b/test/EFCore.Specification.Tests/Query/FiltersInheritanceTestBase.cs index 0bd389c5619..1913097481d 100644 --- a/test/EFCore.Specification.Tests/Query/FiltersInheritanceTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/FiltersInheritanceTestBase.cs @@ -25,9 +25,9 @@ public virtual void Can_use_of_type_animal() { var animals = context.Set().OfType().OrderBy(a => a.Species).ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -38,7 +38,7 @@ public virtual void Can_use_is_kiwi() { var kiwis = context.Set().Where(a => a is Kiwi).ToList(); - Assert.Equal(1, kiwis.Count); + Assert.Single(kiwis); } } @@ -49,7 +49,7 @@ public virtual void Can_use_is_kiwi_with_other_predicate() { var animals = context.Set().Where(a => a is Kiwi && a.CountryId == 1).ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); } } @@ -60,7 +60,7 @@ public virtual void Can_use_is_kiwi_in_projection() { var animals = context.Set().Select(a => a is Kiwi).ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.Equal(1, animals.Count(a => a)); Assert.Equal(0, animals.Count(a => !a)); } @@ -73,9 +73,9 @@ public virtual void Can_use_of_type_bird() { var animals = context.Set().OfType().OrderBy(a => a.Species).ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -91,9 +91,9 @@ var animals .OrderBy(a => a.Species) .ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -109,8 +109,8 @@ var animals b => new { b.EagleId }) .ToList(); - Assert.Equal(1, animals.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Single(animals); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -123,7 +123,7 @@ public virtual void Can_use_of_type_bird_first() Assert.NotNull(bird); Assert.IsType(bird); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -134,9 +134,9 @@ public virtual void Can_use_of_type_kiwi() { var animals = context.Set().OfType().ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -147,8 +147,8 @@ public virtual void Can_use_derived_set() { var eagles = context.Set().ToList(); - Assert.Equal(0, eagles.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(eagles); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -159,7 +159,7 @@ public virtual void Can_use_IgnoreQueryFilters_and_GetDatabaseValues() { var eagle = context.Set().IgnoreQueryFilters().Single(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.NotNull(context.Entry(eagle).GetDatabaseValues()); } } diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index 59c7b3ee10d..513acdce4aa 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -352,7 +352,7 @@ public virtual Task Include_with_join_collection2(bool isAsync) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual void Include_where_list_contains_navigation(bool isAsync) + public virtual async Task Include_where_list_contains_navigation(bool isAsync) { using (var context = CreateContext()) { @@ -360,10 +360,13 @@ public virtual void Include_where_list_contains_navigation(bool isAsync) var tags = context.Tags.Select(t => (Guid?)t.Id).ToList(); - var gears = context.Gears + var query = context.Gears .Include(g => g.Tag) - .Where(g => g.Tag != null && tags.Contains(g.Tag.Id)) - .ToList(); + .Where(g => g.Tag != null && tags.Contains(g.Tag.Id)); + + var gears = isAsync + ? (await query.ToListAsync()) + : query.ToList(); Assert.Equal(5, gears.Count); @@ -373,7 +376,7 @@ public virtual void Include_where_list_contains_navigation(bool isAsync) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual void Include_where_list_contains_navigation2(bool isAsync) + public virtual async Task Include_where_list_contains_navigation2(bool isAsync) { using (var context = CreateContext()) { @@ -381,10 +384,13 @@ public virtual void Include_where_list_contains_navigation2(bool isAsync) var tags = context.Tags.Select(t => (Guid?)t.Id).ToList(); - var gears = context.Gears + var query = context.Gears .Include(g => g.Tag) - .Where(g => g.CityOfBirth.Location != null && tags.Contains(g.Tag.Id)) - .ToList(); + .Where(g => g.CityOfBirth.Location != null && tags.Contains(g.Tag.Id)); + + var gears = isAsync + ? (await query.ToListAsync()) + : query.ToList(); Assert.Equal(5, gears.Count); @@ -394,7 +400,7 @@ public virtual void Include_where_list_contains_navigation2(bool isAsync) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual void Navigation_accessed_twice_outside_and_inside_subquery(bool isAsync) + public virtual async Task Navigation_accessed_twice_outside_and_inside_subquery(bool isAsync) { using (var context = CreateContext()) { @@ -402,9 +408,12 @@ public virtual void Navigation_accessed_twice_outside_and_inside_subquery(bool i var tags = context.Tags.Select(t => (Guid?)t.Id).ToList(); - var gears = context.Gears - .Where(g => g.Tag != null && tags.Contains(g.Tag.Id)) - .ToList(); + var query = context.Gears + .Where(g => g.Tag != null && tags.Contains(g.Tag.Id)); + + var gears = isAsync + ? (await query.ToListAsync()) + : query.ToList(); Assert.Equal(5, gears.Count); @@ -1630,7 +1639,7 @@ public virtual void Where_subquery_distinct_last_boolean() var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.Equal("Cole Train", result[0].Nickname); } } @@ -3915,7 +3924,7 @@ select new }; var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.Equal("Locust", result[0].Name); Assert.Equal("Marcus", result[0].Nickname); } @@ -3965,7 +3974,7 @@ public virtual void Optional_navigation_with_collection_composite_key() var query = context.Tags.Where(t => t.Gear is Officer && ((Officer)t.Gear).Reports.Count(r => r.Nickname == "Dom") > 0); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.Equal("Marcus' Tag", result[0].Note); } } @@ -3981,8 +3990,8 @@ public virtual void Select_null_conditional_with_inheritance() var result = query.ToList(); Assert.Equal(2, result.Count); - Assert.True(result.Contains("Queen Myrrah")); - Assert.True(result.Contains("Unknown")); + Assert.Contains("Queen Myrrah", result); + Assert.Contains("Unknown", result); } } @@ -3997,8 +4006,8 @@ public virtual void Select_null_conditional_with_inheritance_negative() var result = query.ToList(); Assert.Equal(2, result.Count); - Assert.True(result.Contains(true)); - Assert.True(result.Contains(false)); + Assert.Contains(true, result); + Assert.Contains(false, result); } } @@ -6384,7 +6393,7 @@ public virtual void Include_groupby_constant() var query = ctx.Squads.Include(s => s.Members).GroupBy(s => 1); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); var bucket = result[0].ToList(); Assert.Equal(2, bucket.Count); Assert.NotNull(bucket[0].Members); @@ -6468,7 +6477,7 @@ public virtual void Include_groupby_constant_null_of_non_mapped_type() var query = ctx.Squads.Include(s => s.Members).GroupBy(s => (MyDTO)null); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); var bucket = result[0].ToList(); Assert.Equal(2, bucket.Count); Assert.NotNull(bucket[0].Members); @@ -7172,7 +7181,7 @@ public virtual Task Multiple_includes_with_client_method_around_entity_and_also_ var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); var topLevel = result[0]; diff --git a/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs b/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs index 5e29c72834b..8d3434201da 100644 --- a/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/IncludeAsyncTestBase.cs @@ -112,7 +112,7 @@ var customers Assert.Equal(91, customers.Count); Assert.Equal(830, customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).Count()); Assert.True(customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -132,7 +132,7 @@ var customers Assert.Equal(5, customers.Count); Assert.Equal(48, customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).Count()); Assert.True(customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -217,7 +217,7 @@ var customers Assert.Equal(455, customers.Count); Assert.Equal(4150, customers.SelectMany(c => c.Orders).Count()); Assert.True(customers.SelectMany(c => c.Orders).All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -309,7 +309,7 @@ var customers select new { c, g }) .ToListAsync(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.c.Orders).Count()); Assert.True(customers.SelectMany(c => c.c.Orders).All(o => o.Customer != null)); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); @@ -329,7 +329,7 @@ var customers select new { c, g }) .ToListAsync(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.g).Count()); Assert.True(customers.SelectMany(c => c.g).SelectMany(o => o.OrderDetails).All(od => od.Order != null)); Assert.Equal(1 + 6 + 12, context.ChangeTracker.Entries().Count()); @@ -347,7 +347,7 @@ var customers group c by c.City) .ToListAsync(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.Single().Orders).Count()); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); } @@ -398,7 +398,7 @@ var customer1 = await context.Set() .SingleAsync(c => c.CustomerID == "ALFKI"); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); var customer2 = await context.Set() @@ -421,7 +421,7 @@ var customer1 = await context.Set() .SingleAsync(c => c.CustomerID == "ALFKI"); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); var customer2 = await context.Set() @@ -432,7 +432,7 @@ var customer2 Assert.Null(customer1.Orders); Assert.Equal(6, customer2.Orders.Count); Assert.True(customer2.Orders.All(o => o.Customer != null)); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -462,7 +462,7 @@ var productIds .ToListAsync(); Assert.Equal(91, productIds.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -477,7 +477,7 @@ var customers .Where(c => c.CustomerID == "ALFKI") .ToListAsync(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.Orders).Count()); Assert.True(customers.SelectMany(c => c.Orders).All(o => o.Customer != null)); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); @@ -495,7 +495,7 @@ var customers .Include(c => c.Orders) .ToListAsync(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.Orders).Count()); Assert.True(customers.SelectMany(c => c.Orders).All(o => o.Customer != null)); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); @@ -548,7 +548,7 @@ var customers .Take(1) .ToListAsync(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.c1.Orders).Count()); Assert.True(customers.SelectMany(c => c.c1.Orders).All(o => o.Customer != null)); Assert.Equal(7, customers.SelectMany(c => c.c2.Orders).Count()); @@ -575,7 +575,7 @@ var customers .Take(1) .ToListAsync(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.c1.Orders).Count()); Assert.True(customers.SelectMany(c => c.c1.Orders).All(o => o.Customer != null)); Assert.True(customers.All(c => c.c2.Orders == null)); @@ -606,8 +606,8 @@ var orders Assert.Equal(4, orders.Count); Assert.True(orders.All(o => o.o1.Customer != null)); Assert.True(orders.All(o => o.o2.Customer != null)); - Assert.Equal(1, orders.Select(o => o.o1.Customer).Distinct().Count()); - Assert.Equal(1, orders.Select(o => o.o2.Customer).Distinct().Count()); + Assert.Single(orders.Select(o => o.o1.Customer).Distinct()); + Assert.Single(orders.Select(o => o.o2.Customer).Distinct()); Assert.Equal(5, context.ChangeTracker.Entries().Count()); } } @@ -852,7 +852,7 @@ var orders Assert.Equal(830, orders.Count); Assert.True(orders.All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -905,7 +905,7 @@ var orders .ToListAsync(); Assert.Equal(830, orders.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -922,7 +922,7 @@ var orders Assert.Equal(6, orders.Count); Assert.True(orders.All(o => o.Customer != null)); - Assert.Equal(1, orders.Select(o => o.Customer).Distinct().Count()); + Assert.Single(orders.Select(o => o.Customer).Distinct()); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); } } @@ -940,7 +940,7 @@ var orders Assert.Equal(6, orders.Count); Assert.True(orders.All(o => o.Customer != null)); - Assert.Equal(1, orders.Select(o => o.Customer).Distinct().Count()); + Assert.Single(orders.Select(o => o.Customer).Distinct()); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); } } diff --git a/test/EFCore.Specification.Tests/Query/IncludeOneToOneTestBase.cs b/test/EFCore.Specification.Tests/Query/IncludeOneToOneTestBase.cs index 56fb7fb5e98..a04e301e102 100644 --- a/test/EFCore.Specification.Tests/Query/IncludeOneToOneTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/IncludeOneToOneTestBase.cs @@ -61,7 +61,7 @@ var people Assert.Equal(4, people.Count); Assert.Equal(3, people.Count(p => p.Address != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -110,7 +110,7 @@ var addresses Assert.Equal(3, addresses.Count); Assert.True(addresses.All(p => p.Resident != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -129,7 +129,7 @@ var people .ToList(); Assert.Equal(4, people.Count); - Assert.True(people.Contains(person)); + Assert.Contains(person, people); Assert.Equal(3, people.Count(p => p.Address != null)); Assert.Equal(4 + 3, context.ChangeTracker.Entries().Count()); } @@ -150,7 +150,7 @@ var addresses .ToList(); Assert.Equal(3, addresses.Count); - Assert.True(addresses.Contains(address)); + Assert.Contains(address, addresses); Assert.True(addresses.All(p => p.Resident != null)); Assert.Equal(3 + 3, context.ChangeTracker.Entries().Count()); } diff --git a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs index 82c009938ef..bdb2103251d 100644 --- a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs @@ -413,10 +413,15 @@ public virtual void Include_collection_take_no_order_by(bool useString) using (var context = CreateContext()) { var customers - = context.Set() - .Take(10) - .Include(c => c.Orders) - .ToList(); + = useString + ? context.Set() + .Take(10) + .Include("Orders") + .ToList() + : context.Set() + .Take(10) + .Include(c => c.Orders) + .ToList(); Assert.Equal(10, customers.Count); Assert.True(customers.All(c => c.Orders != null)); @@ -572,7 +577,7 @@ var customers Assert.Equal(91, customers.Count); Assert.Equal(830, customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).Count()); Assert.True(customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); foreach (var customer in customers) { @@ -611,7 +616,7 @@ var customers Assert.Equal(5, customers.Count); Assert.Equal(48, customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).Count()); Assert.True(customers.Where(c => c.Orders != null).SelectMany(c => c.Orders).All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); foreach (var customer in customers) { @@ -757,7 +762,7 @@ var customers Assert.Equal(455, customers.Count); Assert.Equal(4150, customers.SelectMany(c => c.Orders).Count()); Assert.True(customers.SelectMany(c => c.Orders).All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); foreach (var customer in customers) { @@ -974,7 +979,7 @@ var customers select new { c, g }) .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.c.Orders).Count()); Assert.True(customers.SelectMany(c => c.c.Orders).All(o => o.Customer != null)); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); @@ -1013,7 +1018,7 @@ var customers select new { c, g }) .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.g).Count()); Assert.True(customers.SelectMany(c => c.g).SelectMany(o => o.OrderDetails).All(od => od.Order != null)); Assert.Equal(1 + 6 + 12, context.ChangeTracker.Entries().Count()); @@ -1049,7 +1054,7 @@ var customers group c by c.City) .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.Single().Orders).Count()); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); @@ -1350,7 +1355,7 @@ var customer1 = context.Set() .Single(c => c.CustomerID == "ALFKI"); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); var customer2 = useString @@ -1386,7 +1391,7 @@ var customer1 = context.Set() .Single(c => c.CustomerID == "ALFKI"); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); var customer2 = useString @@ -1403,7 +1408,7 @@ var customer2 Assert.Null(customer1.Orders); Assert.Equal(6, customer2.Orders.Count); Assert.True(customer2.Orders.All(o => o.Customer != null)); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); CheckIsLoaded( context, @@ -1453,7 +1458,7 @@ var productIds .ToList(); Assert.Equal(91, productIds.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -1475,7 +1480,7 @@ var customers .Where(c => c.CustomerID == "ALFKI") .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.Orders).Count()); Assert.True(customers.SelectMany(c => c.Orders).All(o => o.Customer != null)); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); @@ -1510,7 +1515,7 @@ var customers .Include(c => c.Orders) .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.Orders).Count()); Assert.True(customers.SelectMany(c => c.Orders).All(o => o.Customer != null)); Assert.Equal(1 + 6, context.ChangeTracker.Entries().Count()); @@ -1622,7 +1627,7 @@ var customers .Take(1) .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.c1.Orders).Count()); Assert.True(customers.SelectMany(c => c.c1.Orders).All(o => o.Customer != null)); Assert.Equal(7, customers.SelectMany(c => c.c2.Orders).Count()); @@ -1683,7 +1688,7 @@ var customers .Take(1) .ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); Assert.Equal(6, customers.SelectMany(c => c.c1.Orders).Count()); Assert.True(customers.SelectMany(c => c.c1.Orders).All(o => o.Customer != null)); Assert.True(customers.All(c => c.c2.Orders == null)); @@ -1750,8 +1755,8 @@ var orders Assert.Equal(4, orders.Count); Assert.True(orders.All(o => o.o1.Customer != null)); Assert.True(orders.All(o => o.o2.Customer != null)); - Assert.Equal(1, orders.Select(o => o.o1.Customer).Distinct().Count()); - Assert.Equal(1, orders.Select(o => o.o2.Customer).Distinct().Count()); + Assert.Single(orders.Select(o => o.o1.Customer).Distinct()); + Assert.Single(orders.Select(o => o.o2.Customer).Distinct()); Assert.Equal(5, context.ChangeTracker.Entries().Count()); foreach (var order in orders.Select(e => e.o1)) @@ -2306,7 +2311,7 @@ var orders Assert.Equal(830, orders.Count); Assert.True(orders.All(o => o.Customer != null)); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); foreach (var order in orders) { @@ -2400,7 +2405,7 @@ var orders .ToList(); Assert.Equal(830, orders.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -2460,7 +2465,7 @@ var orders Assert.Equal(6, orders.Count); Assert.True(orders.All(o => o.Customer != null)); - Assert.Equal(1, orders.Select(o => o.Customer).Distinct().Count()); + Assert.Single(orders.Select(o => o.Customer).Distinct()); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); foreach (var order in orders) @@ -2496,7 +2501,7 @@ var orders Assert.Equal(6, orders.Count); Assert.True(orders.All(o => o.Customer != null)); - Assert.Equal(1, orders.Select(o => o.Customer).Distinct().Count()); + Assert.Single(orders.Select(o => o.Customer).Distinct()); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); diff --git a/test/EFCore.Specification.Tests/Query/InheritanceTestBase.cs b/test/EFCore.Specification.Tests/Query/InheritanceTestBase.cs index 75dfbd0d8e4..df576d77f92 100644 --- a/test/EFCore.Specification.Tests/Query/InheritanceTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/InheritanceTestBase.cs @@ -84,7 +84,7 @@ public virtual void Can_use_is_kiwi() { var kiwis = context.Set().Where(a => a is Kiwi).ToList(); - Assert.Equal(1, kiwis.Count); + Assert.Single(kiwis); } } @@ -96,7 +96,7 @@ public virtual void Can_use_backwards_is_animal() // ReSharper disable once IsExpressionAlwaysTrue var kiwis = context.Set().Where(a => a is Animal).ToList(); - Assert.Equal(1, kiwis.Count); + Assert.Single(kiwis); } } @@ -107,7 +107,7 @@ public virtual void Can_use_is_kiwi_with_other_predicate() { var animals = context.Set().Where(a => a is Kiwi && a.CountryId == 1).ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); } } @@ -150,9 +150,9 @@ var animals .OrderBy(a => a.Species) .ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -169,7 +169,7 @@ var animals .ToList(); Assert.Equal(2, animals.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -182,7 +182,7 @@ public virtual void Can_use_of_type_bird_first() Assert.NotNull(bird); Assert.IsType(bird); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -193,9 +193,9 @@ public virtual void Can_use_of_type_kiwi() { var animals = context.Set().OfType().ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -206,9 +206,9 @@ public virtual void Can_use_backwards_of_type_animal() { var animals = context.Set().OfType().ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -219,9 +219,9 @@ public virtual void Can_use_of_type_rose() { var plants = context.Set().OfType().ToList(); - Assert.Equal(1, plants.Count); + Assert.Single(plants); Assert.IsType(plants[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -275,7 +275,7 @@ var animals .Where(a => a.Name == "Great spotted kiwi") .ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); } } @@ -358,9 +358,9 @@ var animals .Where(x => x.FoundOn == Island.South) .ToList(); - Assert.Equal(1, animals.Count); + Assert.Single(animals); Assert.IsType(animals[0]); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); } } @@ -375,8 +375,8 @@ var animals .Where(x => x.FoundOn == Island.North) .ToList(); - Assert.Equal(0, animals.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(animals); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -390,7 +390,7 @@ var kiwis .Select(k => k.FoundOn) .ToArray(); - Assert.Equal(1, kiwis.Length); + Assert.Single(kiwis); } } @@ -421,7 +421,7 @@ var predators k => new { Predator = EF.Property((Bird)k, "EagleId") }) .ToArray(); - Assert.Equal(1, predators.Length); + Assert.Single(predators); } } @@ -436,7 +436,7 @@ var birds .Select(k => k.FoundOn) .ToArray(); - Assert.Equal(1, birds.Length); + Assert.Single(birds); } } @@ -597,7 +597,7 @@ public virtual void Byte_enum_value_constant_used_in_projection() var query = context.Set().Select(k => k.IsFlightless ? Island.North : Island.South); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.Equal(Island.North, result[0]); } } diff --git a/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs index be24da3a2e6..a236a0fcd99 100644 --- a/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs @@ -33,7 +33,7 @@ var query where a.LeafAAddress == b.LeafBAddress select a).ToList(); - Assert.Equal(0, query.Count); + Assert.Empty(query); } } @@ -48,7 +48,7 @@ var query where a.LeafAAddress.Equals(b.LeafBAddress) select a).ToList(); - Assert.Equal(0, query.Count); + Assert.Empty(query); } } @@ -63,7 +63,7 @@ var query where Equals(a.LeafAAddress, b.LeafBAddress) select a).ToList(); - Assert.Equal(0, query.Count); + Assert.Empty(query); } } @@ -117,7 +117,7 @@ public virtual void Query_for_leaf_type_loads_all_owned_navs() { var people = context.Set().ToList(); - Assert.Equal(1, people.Count); + Assert.Single(people); Assert.True(people.All(p => p.PersonAddress != null)); Assert.True(people.All(b => b.BranchAddress != null)); Assert.True(people.All(a => a.LeafAAddress != null)); @@ -429,7 +429,7 @@ public virtual void Query_with_OfType_eagerly_loads_correct_owned_navigations() var query = ctx.Set().OfType(); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.NotNull(result[0].BranchAddress); Assert.NotNull(result[0].LeafAAddress); Assert.NotNull(result[0].PersonAddress); @@ -459,11 +459,11 @@ public virtual void Throw_for_owned_entities_without_owner_in_tracking_query() var result = query.AsNoTracking().ToList(); Assert.Equal(4, result.Count); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); Assert.Throws(() => query.AsTracking().ToList()); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } diff --git a/test/EFCore.Specification.Tests/Query/QueryFilterFuncletizationTestBase.cs b/test/EFCore.Specification.Tests/Query/QueryFilterFuncletizationTestBase.cs index bd94ce44a1f..ca4fb86d36f 100644 --- a/test/EFCore.Specification.Tests/Query/QueryFilterFuncletizationTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/QueryFilterFuncletizationTestBase.cs @@ -386,7 +386,7 @@ public virtual void Using_multiple_context_in_filter_parametrize_only_current_co using (var context = CreateContext()) { var query = context.Set().ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); context.Property = true; diff --git a/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs b/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs index 1f0472bb48d..e3be9f95ea2 100644 --- a/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/QueryNavigationsTestBase.cs @@ -1387,7 +1387,7 @@ public virtual void Include_on_inner_projecting_groupjoin() select grouping.ToList(); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); foreach (var order in result[0]) { Assert.True(order.OrderDetails.Count > 0); @@ -1407,7 +1407,7 @@ public virtual void Include_on_inner_projecting_groupjoin_complex() select grouping.ToList(); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); foreach (var order in result[0]) { Assert.True(order.OrderDetails.Count > 0); diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs index a9dc0265307..592dcd26a1f 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs @@ -397,7 +397,9 @@ public virtual Task GroupBy_Select_Union(bool isAsync) .Select(g => new { CustomerID = g.Key, Count = g.Count() }))); [ConditionalTheory(Skip = "Issue#17339")] +#pragma warning disable xUnit1016 // MemberData must reference a public member [MemberData(nameof(GetSetOperandTestCases))] +#pragma warning restore xUnit1016 // MemberData must reference a public member public virtual Task Union_over_different_projection_types(bool isAsync, string leftType, string rightType) { var (left, right) = (ExpressionGenerator(leftType), ExpressionGenerator(rightType)); diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs index 01c12595e6d..25d1a7ec807 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.Where.cs @@ -488,7 +488,7 @@ public virtual void Where_subquery_closure_via_query_cache() var customers = context.Customers.Where(c => orders.Any(o => o.CustomerID == c.CustomerID)).ToList(); - Assert.Equal(1, customers.Count); + Assert.Single(customers); customerID = "ANATR"; diff --git a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs index 56510ad41f8..82310908642 100644 --- a/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs @@ -263,7 +263,7 @@ var results .GroupBy(x => x.ShipName) .ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); } } @@ -3533,7 +3533,7 @@ orderby c.CustomerID orderby o.OrderID select o).ToList(); - Assert.Equal(1, orders.Count); + Assert.Single(orders); } } diff --git a/test/EFCore.Specification.Tests/StoreGeneratedFixupTestBase.cs b/test/EFCore.Specification.Tests/StoreGeneratedFixupTestBase.cs index 5889448764d..e73c67f9b8a 100644 --- a/test/EFCore.Specification.Tests/StoreGeneratedFixupTestBase.cs +++ b/test/EFCore.Specification.Tests/StoreGeneratedFixupTestBase.cs @@ -4109,7 +4109,7 @@ public virtual void Multi_level_add_replace_and_save() context.ChangeTracker.DetectChanges(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Equal(2, context.ChangeTracker.Entries().Count()); Assert.Equal(4, context.ChangeTracker.Entries().Count()); @@ -4119,7 +4119,7 @@ public virtual void Multi_level_add_replace_and_save() context.ChangeTracker.DetectChanges(); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Equal(2, context.ChangeTracker.Entries().Count()); Assert.Equal(4, context.ChangeTracker.Entries().Count()); diff --git a/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs b/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs index 3063b0e83b0..323ad114f08 100644 --- a/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs +++ b/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs @@ -1665,7 +1665,7 @@ private void OrderingSettingsVerifier(bool assertOrder, Type type, Func()).Count(); Assert.Equal(expected, actual); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -1683,7 +1683,7 @@ private void OrderingSettingsVerifier(bool assertOrder, Type type, Func()).Count(); Assert.Equal(expected, actual); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -1703,7 +1703,7 @@ private void OrderingSettingsVerifier(bool assertOrder, Type type, Func()).Count(expectedPredicate); Assert.Equal(expected, actual); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -1742,7 +1742,7 @@ private void OrderingSettingsVerifier(bool assertOrder, Type type, Func()).LongCount(); Assert.Equal(expected, actual); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -1760,7 +1760,7 @@ private void OrderingSettingsVerifier(bool assertOrder, Type type, Func()).LongCount(); Assert.Equal(expected, actual); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -1780,7 +1780,7 @@ private void OrderingSettingsVerifier(bool assertOrder, Type type, Func()).LongCount(expectedPredicate); Assert.Equal(expected, actual); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } @@ -2049,7 +2049,7 @@ private void OrderingSettingsVerifier(bool assertOrder, Type type, Func e.Title).ToList(); - Assert.Equal(1, posts.Count); + Assert.Single(posts); Assert.StartsWith("Baxter", posts[0].Title); Assert.StartsWith("With dog", posts[0].Content); @@ -103,7 +103,7 @@ public virtual void Query_with_keyless_type() var blogs = context.Query().ToList(); #pragma warning restore CS0618 // Type or member is obsolete - Assert.Equal(1, blogs.Count); + Assert.Single(blogs); Assert.Equal("Puppies", blogs[0].Title); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/BuiltInDataTypesSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/BuiltInDataTypesSqlServerTest.cs index acb27010c4b..3f4176345d0 100644 --- a/test/EFCore.SqlServer.FunctionalTests/BuiltInDataTypesSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/BuiltInDataTypesSqlServerTest.cs @@ -45,7 +45,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"SELECT [m].[Int] @@ -84,7 +84,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"@__timeSpan_0='02:01:00' (Nullable = true) @@ -107,7 +107,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"@__timeSpan_1='02:01:00' (Nullable = true) @@ -130,7 +130,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"@__timeSpan_1='02:01:00' (Nullable = true) @@ -153,7 +153,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"@__timeSpan_1='02:01:00' (Nullable = true) @@ -176,7 +176,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"@__timeSpan_1='02:01:00' (Nullable = true) @@ -199,7 +199,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"@__timeSpan_1='02:01:00' (Nullable = true) @@ -222,7 +222,7 @@ var results .Select(e => e.Int) .ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"@__timeSpan_1='02:01:00' (Nullable = true) diff --git a/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs b/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs index a5084a60c06..6f45dfd2eea 100644 --- a/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/DbContextPoolingTest.cs @@ -465,7 +465,7 @@ public void State_manager_is_reset(bool useInterface) var entity = context1.Customers.First(c => c.CustomerId == "ALFKI"); - Assert.Equal(expected: 1, actual: context1.ChangeTracker.Entries().Count()); + Assert.Single(context1.ChangeTracker.Entries()); serviceScope.Dispose(); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/DbFunctionsSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/DbFunctionsSqlServerTest.cs index 6cbcf52db1f..efe53308db2 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/DbFunctionsSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/DbFunctionsSqlServerTest.cs @@ -63,7 +63,7 @@ public async Task FreeText_literal() .Where(c => EF.Functions.FreeText(c.Title, "Representative")) .ToListAsync(); - Assert.Equal(result.First().EmployeeID, 1u); + Assert.Equal(1u, result.First().EmployeeID); AssertSql( @"SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -89,7 +89,7 @@ public void FreeText_multiple_words() .Where(c => EF.Functions.FreeText(c.Title, "Representative Sales")) .Count(); - Assert.Equal(result, 9); + Assert.Equal(9, result); AssertSql( @"SELECT COUNT(*) @@ -106,7 +106,7 @@ public void FreeText_with_language_term() { var result = context.Employees.SingleOrDefault(c => EF.Functions.FreeText(c.Title, "President", 1033)); - Assert.Equal(result.EmployeeID, 2u); + Assert.Equal(2u, result.EmployeeID); AssertSql( @"SELECT TOP(2) [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -125,7 +125,7 @@ public void FreeText_with_multiple_words_and_language_term() .Where(c => EF.Functions.FreeText(c.Title, "Representative President", 1033)) .ToList(); - Assert.Equal(result.First().EmployeeID, 1u); + Assert.Equal(1u, result.First().EmployeeID); AssertSql( @"SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -146,7 +146,7 @@ public void FreeText_multiple_predicates() && EF.Functions.FreeText(c.Title, "Manager", 1033)) .FirstOrDefault(); - Assert.Equal(result.EmployeeID, 5u); + Assert.Equal(5u, result.EmployeeID); AssertSql( @"SELECT TOP(1) [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -179,7 +179,7 @@ public void FreeText_through_navigation() && c.FirstName.Contains("Lau")) .LastOrDefault(); - Assert.Equal(result.EmployeeID, 8u); + Assert.Equal(8u, result.EmployeeID); AssertSql( @"SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -202,7 +202,7 @@ public void FreeText_through_navigation_with_language_terms() && c.FirstName.Contains("Lau")) .LastOrDefault(); - Assert.Equal(result.EmployeeID, 8u); + Assert.Equal(8u, result.EmployeeID); AssertSql( @"SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -310,7 +310,7 @@ public async Task Contains_literal() .Where(c => EF.Functions.Contains(c.Title, "Representative")) .ToListAsync(); - Assert.Equal(result.First().EmployeeID, 1u); + Assert.Equal(1u, result.First().EmployeeID); AssertSql( @"SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -327,7 +327,7 @@ public void Contains_with_language_term() { var result = context.Employees.SingleOrDefault(c => EF.Functions.Contains(c.Title, "President", 1033)); - Assert.Equal(result.EmployeeID, 2u); + Assert.Equal(2u, result.EmployeeID); AssertSql( @"SELECT TOP(2) [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -405,7 +405,7 @@ public void Contains_through_navigation() .LastOrDefault(); Assert.NotNull(result); - Assert.Equal(result.EmployeeID, 8u); + Assert.Equal(8u, result.EmployeeID); AssertSql( @"SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] @@ -571,7 +571,7 @@ public virtual void IsDate_not_valid() .Select(c => EF.Functions.IsDate(c.CustomerID)) .FirstOrDefault(); - Assert.Equal(actual, false); + Assert.False(actual); AssertSql( @"SELECT TOP(1) CAST(ISDATE([o].[CustomerID]) AS bit) @@ -591,7 +591,7 @@ public virtual void IsDate_valid() .Select(c => EF.Functions.IsDate(c.OrderDate.Value.ToString())) .FirstOrDefault(); - Assert.Equal(actual, true); + Assert.True(actual); AssertSql( @"SELECT TOP(1) CAST(ISDATE(CONVERT(VARCHAR(100), [o].[OrderDate])) AS bit) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index d78567e7bd1..9d329fddd43 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -211,9 +211,9 @@ public override async Task Include_with_join_collection2(bool isAsync) ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [w].[Id]"); } - public override void Include_where_list_contains_navigation(bool isAsync) + public override async Task Include_where_list_contains_navigation(bool isAsync) { - base.Include_where_list_contains_navigation(isAsync); + await base.Include_where_list_contains_navigation(isAsync); AssertSql( @"SELECT [t].[Id] @@ -225,9 +225,9 @@ public override void Include_where_list_contains_navigation(bool isAsync) WHERE [g].[Discriminator] IN (N'Gear', N'Officer') AND ([t].[Id] IS NOT NULL AND [t].[Id] IN ('34c8d86e-a4ac-4be5-827f-584dda348a07', 'df36f493-463f-4123-83f9-6b135deeb7ba', 'a8ad98f9-e023-4e2a-9a70-c2728455bd34', '70534e05-782c-4052-8720-c2c54481ce5f', 'a7be028a-0cf2-448f-ab55-ce8bc5d8cf69', 'b39a6fba-9026-4d69-828e-fd7068673e57'))"); } - public override void Include_where_list_contains_navigation2(bool isAsync) + public override async Task Include_where_list_contains_navigation2(bool isAsync) { - base.Include_where_list_contains_navigation2(isAsync); + await base.Include_where_list_contains_navigation2(isAsync); AssertSql( @"SELECT [t].[Id] @@ -240,9 +240,9 @@ public override void Include_where_list_contains_navigation2(bool isAsync) WHERE [g].[Discriminator] IN (N'Gear', N'Officer') AND ([c].[Location] IS NOT NULL AND [t].[Id] IN ('34c8d86e-a4ac-4be5-827f-584dda348a07', 'df36f493-463f-4123-83f9-6b135deeb7ba', 'a8ad98f9-e023-4e2a-9a70-c2728455bd34', '70534e05-782c-4052-8720-c2c54481ce5f', 'a7be028a-0cf2-448f-ab55-ce8bc5d8cf69', 'b39a6fba-9026-4d69-828e-fd7068673e57'))"); } - public override void Navigation_accessed_twice_outside_and_inside_subquery(bool isAsync) + public override async Task Navigation_accessed_twice_outside_and_inside_subquery(bool isAsync) { - base.Navigation_accessed_twice_outside_and_inside_subquery(isAsync); + await base.Navigation_accessed_twice_outside_and_inside_subquery(isAsync); AssertSql( @"SELECT [t].[Id] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs index 413755c2b8b..9e690ac484f 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs @@ -66,7 +66,7 @@ public async Task Where_equals_DateTime_Now(bool async) ? await query.ToListAsync() : query.ToList(); - Assert.Equal(0, results.Count); + Assert.Empty(results); AssertSql( @"SELECT [d].[Id], [d].[DateTime], [d].[DateTime2], [d].[DateTime2_0], [d].[DateTime2_1], [d].[DateTime2_2], [d].[DateTime2_3], [d].[DateTime2_4], [d].[DateTime2_5], [d].[DateTime2_6], [d].[DateTime2_7], [d].[SmallDateTime] @@ -97,7 +97,7 @@ public async Task Where_not_equals_DateTime_Now(bool async) ? await query.ToListAsync() : query.ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); AssertSql( @"SELECT [d].[Id], [d].[DateTime], [d].[DateTime2], [d].[DateTime2_0], [d].[DateTime2_1], [d].[DateTime2_2], [d].[DateTime2_3], [d].[DateTime2_4], [d].[DateTime2_5], [d].[DateTime2_6], [d].[DateTime2_7], [d].[SmallDateTime] @@ -135,7 +135,7 @@ public async Task Where_equals_new_DateTime(bool async) ? await query.ToListAsync() : query.ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); AssertSql( @"SELECT [d].[Id], [d].[DateTime], [d].[DateTime2], [d].[DateTime2_0], [d].[DateTime2_1], [d].[DateTime2_2], [d].[DateTime2_3], [d].[DateTime2_4], [d].[DateTime2_5], [d].[DateTime2_6], [d].[DateTime2_7], [d].[SmallDateTime] @@ -188,7 +188,7 @@ public async Task Where_contains_DateTime_literals(bool async) ? await query.ToListAsync() : query.ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); AssertSql( @"SELECT [d].[Id], [d].[DateTime], [d].[DateTime2], [d].[DateTime2_0], [d].[DateTime2_1], [d].[DateTime2_2], [d].[DateTime2_3], [d].[DateTime2_4], [d].[DateTime2_5], [d].[DateTime2_6], [d].[DateTime2_7], [d].[SmallDateTime] @@ -964,7 +964,7 @@ public void Compiler_generated_local_closure_produces_valid_parameter_name_1742( new CustomerDetails_1742 { FirstName = "Foo", LastName = "Bar" }); } - public void Execute1742(CustomerDetails_1742 details) + private void Execute1742(CustomerDetails_1742 details) { using (CreateDatabase925()) { @@ -1172,7 +1172,7 @@ public void ThenInclude_with_interface_navigations_3409() .ThenInclude(c => c.SelfReferenceCollection) .ToList(); - Assert.Equal(1, results.Count); + Assert.Single(results); Assert.Equal(1, results[0].ChildCollection.Count); Assert.Equal(2, results[0].ChildCollection.Single().SelfReferenceCollection.Count); } @@ -1575,7 +1575,7 @@ public virtual void Repro6986_can_query_base_type_when_derived_types_contain_sha Assert.Equal(4, query.Count); Assert.Equal(2, query.OfType().Count()); - Assert.Equal(1, query.OfType().Count()); + Assert.Single(query.OfType()); } } } @@ -1589,7 +1589,7 @@ public virtual void Repro6986_can_include_dependent_to_principal_navigation_of_d { var query = context.Contacts.OfType().Include(e => e.ServiceOperator6986).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); Assert.NotNull(query[0].ServiceOperator6986); } } @@ -1605,7 +1605,7 @@ public virtual void Repro6986_can_project_shadow_property_using_ef_property() var query = context.Contacts.OfType().Select( c => new { c, Prop = EF.Property(c, "ServiceOperator6986Id") }).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); Assert.Equal(1, query[0].Prop); } } @@ -1887,7 +1887,7 @@ public virtual void Discriminator_type_is_handled_correctly_in_materialization_b { var query = ctx.Products.OfType().ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); } } } @@ -1901,7 +1901,7 @@ public virtual void Discriminator_type_is_handled_correctly_with_is_operator_bug { var query = ctx.Products.Where(p => p is SpecialProduct).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); } } } @@ -1956,7 +1956,7 @@ public virtual void Reference_include_on_derived_type_with_sibling_works_bug_731 { var query = context.Proposal.OfType().Include(l => l.LeaveType).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); } } } @@ -2023,7 +2023,7 @@ public virtual void Entity_passed_to_DTO_constructor_works() { var query = context.Entity.Select(e => new EntityDto8282(e)).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); } } } @@ -2079,7 +2079,7 @@ public virtual void Enum_has_flag_applies_explicit_cast_for_long_constant() { var query = context.Entity.Where(e => e.Permission.HasFlag(Permission.READ_WRITE)).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); AssertSql( @"SELECT [e].[Id], [e].[Permission], [e].[PermissionByte], [e].[PermissionShort] @@ -2136,7 +2136,7 @@ public virtual void Enum_has_flag_applies_explicit_cast_for_short_constant() { var query = context.Entity.Where(e => e.PermissionShort.HasFlag(PermissionShort.READ_WRITE)).ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); AssertSql( @"SELECT [e].[Id], [e].[Permission], [e].[PermissionByte], [e].[PermissionShort] @@ -2424,7 +2424,7 @@ public void Include_collection_for_entity_with_owned_type_works() var query = context.Movies.Include(m => m.Cast); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.Equal(3, result[0].Cast.Count); Assert.NotNull(result[0].Details); Assert.True(result[0].Cast.All(a => a.Details != null)); @@ -2463,7 +2463,7 @@ public void Include_collection_for_entity_with_owned_type_works_string() var query = context.Movies.Include("Cast"); var result = query.ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.Equal(3, result[0].Cast.Count); Assert.NotNull(result[0].Details); Assert.True(result[0].Cast.All(a => a.Details != null)); @@ -2697,7 +2697,7 @@ public virtual void From_sql_gets_value_of_out_parameter_in_stored_procedure() valueParam) .ToList(); - Assert.Equal(1, blogs.Count); + Assert.Single(blogs); Assert.Equal(1, valueParam.Value); } } @@ -2771,7 +2771,7 @@ public virtual async Task Include_collection_optional_reference_collection_9038( .ToListAsync(); Assert.Equal(2, result.Count); - Assert.Equal(true, result.All(r => r.Students.Count > 0)); + Assert.True(result.All(r => r.Students.Count > 0)); } } } @@ -2909,7 +2909,7 @@ public virtual void Repro9735() .Take(2) .ToList(); - Assert.Equal(1, result.Count); + Assert.Single(result); AssertSql( @"@__p_0='2' @@ -3448,7 +3448,7 @@ public virtual void QueryBuffer_requirement_is_computed_when_querying_base_type_ var query = context.Bases.ToList(); var derived1 = Assert.Single(query); - Assert.Equal(derived1.GetType(), typeof(Derived1)); + Assert.Equal(typeof(Derived1), derived1.GetType()); AssertSql( @"SELECT [b].[Id], [b].[IsTwo], [b].[MoreStuffId] @@ -4134,7 +4134,7 @@ public virtual void Include_collection_with_OfType_base() .OfType() .ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); var employee = (Employee12582)query[0]; Assert.Equal(2, employee.Devices.Count); @@ -4153,7 +4153,7 @@ public virtual void Correlated_collection_with_OfType_base() .Select(e => e.Devices.Where(d => d.Device != "foo").Cast()) .ToList(); - Assert.Equal(1, query.Count); + Assert.Single(query); var result = query[0]; Assert.Equal(2, result.Count()); } @@ -4233,7 +4233,7 @@ select new u => new { u.Id }).ToArray() }; var result = query.ToList(); - Assert.Equal(1, result[0].Comments.Count()); + Assert.Single(result[0].Comments); } } } @@ -4464,7 +4464,7 @@ public virtual void Correlated_collection_works_when_defined_on_intermediate_typ var result = query.ToList(); Assert.Equal(2, result.Count); - Assert.True(result.Any(r => r.Count() == 2)); + Assert.Contains(result, r => r.Count() == 2); } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs index c6f782e7d95..df5aef0cc74 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs @@ -666,7 +666,7 @@ public void Create_columns() Assert.Single(table.Columns.Where(c => c.Name == "Id")); Assert.Single(table.Columns.Where(c => c.Name == "Name")); Assert.Single(table.Columns.Where(c => c.Comment == "Blog.Id column comment.")); - Assert.Equal(1, table.Columns.Where(c => c.Comment != null).Count()); + Assert.Single(table.Columns.Where(c => c.Comment != null)); }, "DROP TABLE [dbo].[Blogs]"); } @@ -688,7 +688,7 @@ public void Create_view_columns() var table = Assert.IsType(dbModel.Tables.Single()); Assert.Equal(2, table.Columns.Count); - Assert.Equal(null, table.PrimaryKey); + Assert.Null(table.PrimaryKey); Assert.All( table.Columns, c => { @@ -1348,12 +1348,12 @@ public void Default_and_computed_values_are_stored() var columns = dbModel.Tables.Single().Columns; Assert.Equal("('October 20, 2015 11am')", columns.Single(c => c.Name == "FixedDefaultValue").DefaultValueSql); - Assert.Equal(null, columns.Single(c => c.Name == "FixedDefaultValue").ComputedColumnSql); + Assert.Null(columns.Single(c => c.Name == "FixedDefaultValue").ComputedColumnSql); - Assert.Equal(null, columns.Single(c => c.Name == "ComputedValue").DefaultValueSql); + Assert.Null(columns.Single(c => c.Name == "ComputedValue").DefaultValueSql); Assert.Equal("(getdate())", columns.Single(c => c.Name == "ComputedValue").ComputedColumnSql); - Assert.Equal(null, columns.Single(c => c.Name == "SumOfAAndB").DefaultValueSql); + Assert.Null(columns.Single(c => c.Name == "SumOfAAndB").DefaultValueSql); Assert.Equal("([A]+[B])", columns.Single(c => c.Name == "SumOfAAndB").ComputedColumnSql); }, "DROP TABLE DefaultComputedValues;"); diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlServerConfigPatternsTest.cs b/test/EFCore.SqlServer.FunctionalTests/SqlServerConfigPatternsTest.cs index 8cd6e3cb1d1..8d5a6d9b1b9 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlServerConfigPatternsTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlServerConfigPatternsTest.cs @@ -450,7 +450,7 @@ public async Task Can_use_one_context_nested_inside_another_of_the_same_type() using (var context2 = new NorthwindContext(serviceProvider)) { - Assert.Equal(0, context2.ChangeTracker.Entries().Count()); + Assert.Empty(context2.ChangeTracker.Entries()); var customers2 = await context2.Customers.ToListAsync(); Assert.Equal(91, customers2.Count); diff --git a/test/EFCore.SqlServer.FunctionalTests/SqlServerDatabaseCreatorTest.cs b/test/EFCore.SqlServer.FunctionalTests/SqlServerDatabaseCreatorTest.cs index 2bdfa9b0df8..0fea4d1dcbb 100644 --- a/test/EFCore.SqlServer.FunctionalTests/SqlServerDatabaseCreatorTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/SqlServerDatabaseCreatorTest.cs @@ -331,7 +331,7 @@ private static Task Creates_new_physical_database_and_schema_test(bool async, bo var tables = testDatabase.Query( "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'").ToList(); - Assert.Equal(1, tables.Count); + Assert.Single(tables); Assert.Equal("Blogs", tables.Single()); var columns = testDatabase.Query( @@ -570,26 +570,26 @@ public async Task Creates_schema_in_existing_database_test(bool async, bool ambi var tables = (await testDatabase.QueryAsync( "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'")).ToList(); - Assert.Equal(1, tables.Count); + Assert.Single(tables); Assert.Equal("Blogs", tables.Single()); var columns = (await testDatabase.QueryAsync( "SELECT TABLE_NAME + '.' + COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Blogs'")).ToList(); Assert.Equal(14, columns.Count); - Assert.True(columns.Any(c => c == "Blogs.Key1")); - Assert.True(columns.Any(c => c == "Blogs.Key2")); - Assert.True(columns.Any(c => c == "Blogs.Cheese")); - Assert.True(columns.Any(c => c == "Blogs.ErMilan")); - Assert.True(columns.Any(c => c == "Blogs.George")); - Assert.True(columns.Any(c => c == "Blogs.TheGu")); - Assert.True(columns.Any(c => c == "Blogs.NotFigTime")); - Assert.True(columns.Any(c => c == "Blogs.ToEat")); - Assert.True(columns.Any(c => c == "Blogs.OrNothing")); - Assert.True(columns.Any(c => c == "Blogs.Fuse")); - Assert.True(columns.Any(c => c == "Blogs.WayRound")); - Assert.True(columns.Any(c => c == "Blogs.On")); - Assert.True(columns.Any(c => c == "Blogs.AndChew")); - Assert.True(columns.Any(c => c == "Blogs.AndRow")); + Assert.Contains(columns, c => c == "Blogs.Key1"); + Assert.Contains(columns, c => c == "Blogs.Key2"); + Assert.Contains(columns, c => c == "Blogs.Cheese"); + Assert.Contains(columns, c => c == "Blogs.ErMilan"); + Assert.Contains(columns, c => c == "Blogs.George"); + Assert.Contains(columns, c => c == "Blogs.TheGu"); + Assert.Contains(columns, c => c == "Blogs.NotFigTime"); + Assert.Contains(columns, c => c == "Blogs.ToEat"); + Assert.Contains(columns, c => c == "Blogs.OrNothing"); + Assert.Contains(columns, c => c == "Blogs.Fuse"); + Assert.Contains(columns, c => c == "Blogs.WayRound"); + Assert.Contains(columns, c => c == "Blogs.On"); + Assert.Contains(columns, c => c == "Blogs.AndChew"); + Assert.Contains(columns, c => c == "Blogs.AndRow"); } } } @@ -685,9 +685,9 @@ public async Task Creates_physical_database_but_not_tables(bool async, bool ambi await testDatabase.OpenConnectionAsync(); } - Assert.Equal( - 0, (await testDatabase.QueryAsync( - "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'")).Count()); + Assert.Empty( +(await testDatabase.QueryAsync( + "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'"))); Assert.True( await testDatabase.ExecuteScalarAsync( diff --git a/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs b/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs index ab4cd74b786..55528384adb 100644 --- a/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs +++ b/test/EFCore.SqlServer.Tests/Migrations/SqlServerModelDifferTest.cs @@ -684,7 +684,7 @@ public void Rebuild_index_with_different_include() Assert.NotNull(annotation); var annotationValue = Assert.IsType(annotation.Value); - Assert.Equal(1, annotationValue.Length); + Assert.Single(annotationValue); Assert.Equal("Street", annotationValue[0]); }); } diff --git a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs index 8654c052d7b..1920151a33c 100644 --- a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs +++ b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs @@ -248,15 +248,15 @@ public virtual void Owned_types_use_table_splitting_by_default() Assert.Equal(book.GetTableName(), bookLabel2Ownership2.DeclaringEntityType.GetTableName()); Assert.NotSame(bookOwnership1.DeclaringEntityType, bookOwnership2.DeclaringEntityType); - Assert.Equal(1, bookOwnership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookOwnership1.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(bookOwnership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookOwnership1.DeclaringEntityType.GetForeignKeys()); Assert.NotSame(bookLabel1Ownership1.DeclaringEntityType, bookLabel2Ownership1.DeclaringEntityType); Assert.NotSame(bookLabel1Ownership2.DeclaringEntityType, bookLabel2Ownership2.DeclaringEntityType); - Assert.Equal(1, bookLabel1Ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel1Ownership2.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership2.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(bookLabel1Ownership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel1Ownership2.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership2.DeclaringEntityType.GetForeignKeys()); Assert.Equal(2, model.GetEntityTypes().Count(e => e.ClrType == typeof(BookLabel))); Assert.Equal(4, model.GetEntityTypes().Count(e => e.ClrType == typeof(AnotherBookLabel))); @@ -398,22 +398,22 @@ public virtual void Owned_types_can_be_mapped_to_different_tables() Assert.Equal("Bar", bookLabel2Ownership11.PrincipalToDependent["Foo"]); Assert.NotSame(bookOwnership1.DeclaringEntityType, bookOwnership2.DeclaringEntityType); - Assert.Equal(1, bookOwnership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookOwnership2.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(bookOwnership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookOwnership2.DeclaringEntityType.GetForeignKeys()); Assert.NotSame(bookLabel1Ownership1.DeclaringEntityType, bookLabel2Ownership1.DeclaringEntityType); Assert.NotSame(bookLabel1Ownership2.DeclaringEntityType, bookLabel2Ownership2.DeclaringEntityType); - Assert.Equal(1, bookLabel1Ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel1Ownership2.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership2.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(bookLabel1Ownership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel1Ownership2.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership2.DeclaringEntityType.GetForeignKeys()); Assert.NotSame(bookLabel1Ownership11.DeclaringEntityType, bookLabel2Ownership11.DeclaringEntityType); Assert.NotSame(bookLabel1Ownership21.DeclaringEntityType, bookLabel2Ownership21.DeclaringEntityType); - Assert.Equal(1, bookLabel1Ownership11.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel1Ownership21.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership11.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership21.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(bookLabel1Ownership11.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel1Ownership21.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership11.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership21.DeclaringEntityType.GetForeignKeys()); Assert.Equal(2, model.GetEntityTypes().Count(e => e.ClrType == typeof(BookLabel))); Assert.Equal(4, model.GetEntityTypes().Count(e => e.ClrType == typeof(AnotherBookLabel))); @@ -455,8 +455,8 @@ public virtual void Owned_type_collections_can_be_mapped_to_different_tables() Assert.Equal(nameof(Order.Customer), ownership.DependentToPrincipal.Name); Assert.Equal("FK_Order_Customer_CustomerId", ownership.GetConstraintName()); - Assert.Equal(1, owned.GetForeignKeys().Count()); - Assert.Equal(1, owned.GetIndexes().Count()); + Assert.Single(owned.GetForeignKeys()); + Assert.Single(owned.GetIndexes()); Assert.Equal( new[] { nameof(Order.OrderId), nameof(Order.AnotherCustomerId), nameof(Order.CustomerId) }, owned.GetProperties().Select(p => p.GetColumnName())); @@ -510,7 +510,7 @@ public override void Can_configure_owned_type() Assert.Equal(nameof(Customer.AlternateKey), ownership.PrincipalKey.Properties.Single().Name); var owned = ownership.DeclaringEntityType; Assert.Same(entityBuilder.OwnedEntityType, owned); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); Assert.Equal(nameof(CustomerDetails.CustomerId), owned.GetIndexes().Single().Properties.Single().Name); Assert.Equal( new[] { "CustomerAlternateKey", nameof(CustomerDetails.CustomerId), nameof(CustomerDetails.Id) }, diff --git a/test/EFCore.SqlServer.Tests/SqlServerOptionsExtensionTest.cs b/test/EFCore.SqlServer.Tests/SqlServerOptionsExtensionTest.cs index 60fbaa1a74a..694c2c6aaed 100644 --- a/test/EFCore.SqlServer.Tests/SqlServerOptionsExtensionTest.cs +++ b/test/EFCore.SqlServer.Tests/SqlServerOptionsExtensionTest.cs @@ -21,7 +21,7 @@ public void ApplyServices_adds_SQL_server_services() new SqlServerOptionsExtension().ApplyServices(services); - Assert.True(services.Any(sd => sd.ServiceType == typeof(ISqlServerConnection))); + Assert.Contains(services, sd => sd.ServiceType == typeof(ISqlServerConnection)); } [ConditionalFact] diff --git a/test/EFCore.SqlServer.Tests/SqlServerSequenceValueGeneratorTest.cs b/test/EFCore.SqlServer.Tests/SqlServerSequenceValueGeneratorTest.cs index 3dc27096935..b38451dea63 100644 --- a/test/EFCore.SqlServer.Tests/SqlServerSequenceValueGeneratorTest.cs +++ b/test/EFCore.SqlServer.Tests/SqlServerSequenceValueGeneratorTest.cs @@ -63,7 +63,7 @@ public class SqlServerSequenceValueGeneratorTest [InlineData(true)] public async Task Generates_sequential_sbyte_values(bool async) => await Generates_sequential_values(async); - public async Task Generates_sequential_values(bool async) + private async Task Generates_sequential_values(bool async) { const int blockSize = 4; diff --git a/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs b/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs index 4b0d24c1477..b7582d7e80a 100644 --- a/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs +++ b/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs @@ -91,6 +91,7 @@ protected override DbCommand CreateTestCommand() protected override DbType DefaultParameterType => DbType.Int32; + [ConditionalTheory] [InlineData(typeof(SqlServerDateTimeOffsetTypeMapping), typeof(DateTimeOffset))] [InlineData(typeof(SqlServerDateTimeTypeMapping), typeof(DateTime))] [InlineData(typeof(SqlServerDoubleTypeMapping), typeof(double))] diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs index c4bbc12549c..9492e8977cc 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/BadDataSqliteTest.cs @@ -21,7 +21,9 @@ namespace Microsoft.EntityFrameworkCore.Query { // Issue #15751 +#pragma warning disable xUnit1000 // Test classes must be public internal class BadDataSqliteTest : IClassFixture +#pragma warning restore xUnit1000 // Test classes must be public { public BadDataSqliteTest(BadDataSqliteFixture fixture) => Fixture = fixture; diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs index aabc40ebaf2..18565beff2b 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs @@ -16,7 +16,7 @@ public ComplexNavigationsQuerySqliteTest(ComplexNavigationsQuerySqliteFixture fi [ConditionalTheory(Skip = "Issue #17230")] public override Task SelectMany_with_navigation_filter_paging_and_explicit_DefaultIfEmpty(bool isAsync) { - return Task.CompletedTask; + return base.SelectMany_with_navigation_filter_paging_and_explicit_DefaultIfEmpty(isAsync); } } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs index eb8ec7ed5d5..a66fea32a0d 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsWeakQuerySqliteTest.cs @@ -17,7 +17,7 @@ public ComplexNavigationsWeakQuerySqliteTest(ComplexNavigationsWeakQuerySqliteFi [ConditionalTheory(Skip = "Issue #17230")] public override Task SelectMany_with_navigation_filter_paging_and_explicit_DefaultIfEmpty(bool isAsync) { - return Task.CompletedTask; + return base.SelectMany_with_navigation_filter_paging_and_explicit_DefaultIfEmpty(isAsync); } } } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/SimpleQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/SimpleQuerySqliteTest.cs index b32087bfa61..87ec7b298f2 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/SimpleQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/SimpleQuerySqliteTest.cs @@ -43,10 +43,10 @@ public override async Task Sum_with_division_on_decimal_no_significant_digits(bo } [ConditionalTheory(Skip = "Issue = #17238")] - public override Task SelectMany_Joined_Take(bool isAsync) => null; + public override Task SelectMany_Joined_Take(bool isAsync) => base.SelectMany_Joined_Take(isAsync); [ConditionalTheory(Skip = "Issue = #17239")] - public override Task Union_Take_Union_Take(bool isAsync) => null; + public override Task Union_Take_Union_Take(bool isAsync) => base.Union_Take_Union_Take(isAsync); // SQLite client-eval public override async Task Average_with_division_on_decimal(bool isAsync) diff --git a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs index d808dd07fc7..1e64115707d 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Scaffolding/SqliteDatabaseModelFactoryTest.cs @@ -181,7 +181,7 @@ public void Create_view_columns() var table = Assert.IsType(dbModel.Tables.Single()); Assert.Equal(2, table.Columns.Count); - Assert.Equal(null, table.PrimaryKey); + Assert.Null(table.PrimaryKey); Assert.All( table.Columns, c => Assert.Equal("MountainsColumnsView", c.Table.Name)); diff --git a/test/EFCore.Sqlite.Tests/Storage/SqliteTypeMappingTest.cs b/test/EFCore.Sqlite.Tests/Storage/SqliteTypeMappingTest.cs index 16fbdf85e3f..5f5d12f65c1 100644 --- a/test/EFCore.Sqlite.Tests/Storage/SqliteTypeMappingTest.cs +++ b/test/EFCore.Sqlite.Tests/Storage/SqliteTypeMappingTest.cs @@ -79,6 +79,7 @@ protected override DbCommand CreateTestCommand() protected override DbType DefaultParameterType => DbType.String; + [ConditionalTheory] [InlineData(typeof(SqliteDateTimeOffsetTypeMapping), typeof(DateTimeOffset))] [InlineData(typeof(SqliteDateTimeTypeMapping), typeof(DateTime))] [InlineData(typeof(SqliteDecimalTypeMapping), typeof(decimal))] diff --git a/test/EFCore.Tests/ChangeTracking/ChangeTrackerTest.cs b/test/EFCore.Tests/ChangeTracking/ChangeTrackerTest.cs index 75bb31e5c02..f1ec704d1c5 100644 --- a/test/EFCore.Tests/ChangeTracking/ChangeTrackerTest.cs +++ b/test/EFCore.Tests/ChangeTracking/ChangeTrackerTest.cs @@ -695,7 +695,7 @@ public void State_change_events_fire_from_query() Assert.Equal(2, context.Cats.OrderBy(e => e.Id).ToList().Count); Assert.Equal(2, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Empty(changed); AssertTrackedEvent(context, 1, EntityState.Unchanged, tracked[0], fromQuery: true); AssertTrackedEvent(context, 2, EntityState.Unchanged, tracked[1], fromQuery: true); @@ -708,7 +708,7 @@ public void State_change_events_fire_from_query() Assert.Equal(2, context.Cats.OrderBy(e => e.Id).ToList().Count); Assert.Equal(2, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Empty(changed); } } @@ -726,15 +726,15 @@ public void State_change_events_fire_from_Attach() context.Attach(new Cat(1)); - Assert.Equal(1, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Single(tracked); + Assert.Empty(changed); AssertTrackedEvent(context, 1, EntityState.Unchanged, tracked[0], fromQuery: false); context.Entry(new Cat(2)).State = EntityState.Unchanged; Assert.Equal(2, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Empty(changed); AssertTrackedEvent(context, 2, EntityState.Unchanged, tracked[1], fromQuery: false); } @@ -754,15 +754,15 @@ public void State_change_events_fire_from_Add() context.Add(new Cat(1)); - Assert.Equal(1, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Single(tracked); + Assert.Empty(changed); AssertTrackedEvent(context, 1, EntityState.Added, tracked[0], fromQuery: false); context.Entry(new Cat(2)).State = EntityState.Added; Assert.Equal(2, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Empty(changed); AssertTrackedEvent(context, 2, EntityState.Added, tracked[1], fromQuery: false); } @@ -782,15 +782,15 @@ public void State_change_events_fire_from_Update() context.Update(new Cat(1)); - Assert.Equal(1, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Single(tracked); + Assert.Empty(changed); AssertTrackedEvent(context, 1, EntityState.Modified, tracked[0], fromQuery: false); context.Entry(new Cat(2)).State = EntityState.Modified; Assert.Equal(2, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Empty(changed); AssertTrackedEvent(context, 2, EntityState.Modified, tracked[1], fromQuery: false); } @@ -811,7 +811,7 @@ public void State_change_events_fire_for_tracked_state_changes() context.AddRange(new Cat(1), new Cat(2)); Assert.Equal(2, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Empty(changed); AssertTrackedEvent(context, 1, EntityState.Added, tracked[0], fromQuery: false); AssertTrackedEvent(context, 2, EntityState.Added, tracked[1], fromQuery: false); @@ -880,8 +880,8 @@ public void State_change_events_fire_when_saving_changes() var cat1 = context.Cats.Find(1); - Assert.Equal(1, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Single(tracked); + Assert.Empty(changed); AssertTrackedEvent(context, 1, EntityState.Unchanged, tracked[0], fromQuery: true); @@ -891,7 +891,7 @@ public void State_change_events_fire_when_saving_changes() context.ChangeTracker.DetectChanges(); Assert.Equal(2, tracked.Count); - Assert.Equal(1, changed.Count); + Assert.Single(changed); AssertTrackedEvent(context, 3, EntityState.Added, tracked[1], fromQuery: false); AssertChangedEvent(context, 1, EntityState.Unchanged, EntityState.Modified, changed[0]); @@ -923,21 +923,21 @@ public void State_change_events_fire_when_property_modified_flags_cause_state_ch var cat = context.Attach( new Cat(3) { Name = "Achilles" }).Entity; - Assert.Equal(1, tracked.Count); - Assert.Equal(0, changed.Count); + Assert.Single(tracked); + Assert.Empty(changed); AssertTrackedEvent(context, 3, EntityState.Unchanged, tracked[0], fromQuery: false); context.Entry(cat).Property(e => e.Name).IsModified = true; - Assert.Equal(1, tracked.Count); - Assert.Equal(1, changed.Count); + Assert.Single(tracked); + Assert.Single(changed); AssertChangedEvent(context, 3, EntityState.Unchanged, EntityState.Modified, changed[0]); context.Entry(cat).Property(e => e.Name).IsModified = false; - Assert.Equal(1, tracked.Count); + Assert.Single(tracked); Assert.Equal(2, changed.Count); AssertChangedEvent(context, 3, EntityState.Modified, EntityState.Unchanged, changed[1]); @@ -969,29 +969,29 @@ public void State_change_events_are_limited_to_the_current_context() Assert.Equal(2, context2.Cats.OrderBy(e => e.Id).ToList().Count); Assert.Equal(2, tracked2.Count); - Assert.Equal(0, changed2.Count); + Assert.Empty(changed2); context2.Entry(context2.Cats.Find(1)).State = EntityState.Modified; Assert.Equal(2, tracked2.Count); - Assert.Equal(1, changed2.Count); + Assert.Single(changed2); - Assert.Equal(0, tracked1.Count); - Assert.Equal(0, changed1.Count); + Assert.Empty(tracked1); + Assert.Empty(changed1); } Assert.Equal(2, context.Cats.OrderBy(e => e.Id).ToList().Count); Assert.Equal(2, tracked1.Count); - Assert.Equal(0, changed1.Count); + Assert.Empty(changed1); context.Entry(context.Cats.Find(1)).State = EntityState.Modified; Assert.Equal(2, tracked1.Count); - Assert.Equal(1, changed1.Count); + Assert.Single(changed1); Assert.Equal(2, tracked2.Count); - Assert.Equal(1, changed2.Count); + Assert.Single(changed2); context.Database.EnsureDeleted(); } diff --git a/test/EFCore.Tests/ChangeTracking/EntityEntryTest.cs b/test/EFCore.Tests/ChangeTracking/EntityEntryTest.cs index 184233863e2..929359a8262 100644 --- a/test/EFCore.Tests/ChangeTracking/EntityEntryTest.cs +++ b/test/EFCore.Tests/ChangeTracking/EntityEntryTest.cs @@ -159,19 +159,19 @@ public void Detached_entities_are_not_returned_from_the_change_tracker() var entity = new Chunky { Id = 808 }; context.Attach(entity); - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); context.Entry(entity).State = EntityState.Detached; - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); context.ChangeTracker.DetectChanges(); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); context.Entry(entity); - Assert.Equal(0, context.ChangeTracker.Entries().Count()); + Assert.Empty(context.ChangeTracker.Entries()); } } diff --git a/test/EFCore.Tests/ChangeTracking/Internal/ObservableBackedBindingListTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/ObservableBackedBindingListTest.cs index 793d75586ad..0bdc2531b1a 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/ObservableBackedBindingListTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/ObservableBackedBindingListTest.cs @@ -20,7 +20,7 @@ public void Items_added_to_ObservableCollection_are_added_to_binding_list() var item = new ListElement(1); oc.Add(item); - Assert.True(obbl.Contains(item)); + Assert.Contains(item, obbl); } [ConditionalFact] @@ -40,7 +40,7 @@ public void Items_removed_from_ObservableCollection_are_removed_from_binding_lis oc.Remove(item); - Assert.False(obbl.Contains(item)); + Assert.DoesNotContain(item, obbl); Assert.Equal(5, obbl.Count); } @@ -62,8 +62,8 @@ public void Items_replaced_in_the_ObservableCollection_are_replaced_in_the_bindi var newItem = new ListElement(-4); oc[2] = newItem; - Assert.False(obbl.Contains(item)); - Assert.True(obbl.Contains(newItem)); + Assert.DoesNotContain(item, obbl); + Assert.Contains(newItem, obbl); Assert.Equal(6, obbl.Count); } @@ -83,7 +83,7 @@ public void Items_cleared_in_the_ObservableCollection_are_cleared_in_the_binding oc.Clear(); - Assert.Equal(0, obbl.Count); + Assert.Empty(obbl); } [ConditionalFact] @@ -116,7 +116,7 @@ public void Items_added_to_the_binding_list_are_added_to_the_ObservableCollectio var item = new ListElement(7); obbl.Add(item); - Assert.True(oc.Contains(item)); + Assert.Contains(item, oc); } [ConditionalFact] @@ -128,7 +128,7 @@ public void Items_added_to_the_binding_list_with_AddNew_are_added_to_the_Observa var item = obbl.AddNew(); obbl.EndNew(0); - Assert.True(oc.Contains(item)); + Assert.Contains(item, oc); } [ConditionalFact] @@ -140,7 +140,7 @@ public void Items_canceled_during_AddNew_are_not_added_to_the_ObservableCollecti var item = obbl.AddNew(); obbl.CancelNew(0); - Assert.False(oc.Contains(item)); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -152,7 +152,7 @@ public void Items_inserted_into_the_binding_list_are_added_to_the_ObservableColl var item = new ListElement(7); obbl.Insert(0, item); - Assert.True(oc.Contains(item)); + Assert.Contains(item, oc); } [ConditionalFact] @@ -173,8 +173,8 @@ public void Items_set_in_the_binding_list_are_replaced_in_the_ObservableCollecti var newItem = new ListElement(7); obbl[2] = newItem; - Assert.True(oc.Contains(newItem)); - Assert.False(oc.Contains(item)); + Assert.Contains(newItem, oc); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -194,7 +194,7 @@ public void Items_removed_from_the_binding_list_are_removed_from_the_ObservableC obbl.Remove(item); - Assert.False(oc.Contains(item)); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -214,7 +214,7 @@ public void Items_removed_by_index_from_the_binding_list_are_removed_from_the_Ob obbl.RemoveAt(2); - Assert.False(oc.Contains(item)); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -233,7 +233,7 @@ public void Items_cleared_from_the_binding_list_are_cleared_from_the_ObservableC obbl.Clear(); - Assert.Equal(0, oc.Count); + Assert.Empty(oc); } [ConditionalFact] @@ -265,7 +265,7 @@ public void Attempt_to_AddNew_for_abstract_type_works_if_AddingNew_event_is_used obbl.AddNew(); obbl.EndNew(0); - Assert.True(obbl.Contains(item)); + Assert.Contains(item, obbl); } [ConditionalFact] @@ -278,7 +278,7 @@ public void Attempt_to_AddNew_for_type_without_parameterless_constructor_works_i obbl.AddNew(); obbl.EndNew(0); - Assert.True(obbl.Contains(item)); + Assert.Contains(item, obbl); } [ConditionalFact] @@ -290,7 +290,7 @@ public void Items_added_to_ObservableHashSet_are_added_to_binding_list() var item = new ListElement(1); oc.Add(item); - Assert.True(obbl.Contains(item)); + Assert.Contains(item, obbl); } [ConditionalFact] @@ -310,7 +310,7 @@ public void Items_removed_from_ObservableHashSet_are_removed_from_binding_list() oc.Remove(item); - Assert.False(obbl.Contains(item)); + Assert.DoesNotContain(item, obbl); Assert.Equal(5, obbl.Count); } @@ -330,7 +330,7 @@ public void Items_cleared_in_the_ObservableHashSet_are_cleared_in_the_binding_li oc.Clear(); - Assert.Equal(0, obbl.Count); + Assert.Empty(obbl); } [ConditionalFact] @@ -363,7 +363,7 @@ public void Items_added_to_the_binding_list_are_added_to_the_ObservableHashSet() var item = new ListElement(7); obbl.Add(item); - Assert.True(oc.Contains(item)); + Assert.Contains(item, oc); } [ConditionalFact] @@ -375,7 +375,7 @@ public void Items_added_to_the_binding_list_with_AddNew_are_added_to_the_Observa var item = obbl.AddNew(); obbl.EndNew(0); - Assert.True(oc.Contains(item)); + Assert.Contains(item, oc); } [ConditionalFact] @@ -387,7 +387,7 @@ public void Items_canceled_during_AddNew_are_not_added_to_the_ObservableHashSet( var item = obbl.AddNew(); obbl.CancelNew(0); - Assert.False(oc.Contains(item)); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -399,7 +399,7 @@ public void Items_inserted_into_the_binding_list_are_added_to_the_ObservableHash var item = new ListElement(7); obbl.Insert(0, item); - Assert.True(oc.Contains(item)); + Assert.Contains(item, oc); } [ConditionalFact] @@ -420,8 +420,8 @@ public void Items_set_in_the_binding_list_are_replaced_in_the_ObservableHashSet( var newItem = new ListElement(7); obbl[2] = newItem; - Assert.True(oc.Contains(newItem)); - Assert.False(oc.Contains(item)); + Assert.Contains(newItem, oc); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -441,7 +441,7 @@ public void Items_removed_from_the_binding_list_are_removed_from_the_ObservableH obbl.Remove(item); - Assert.False(oc.Contains(item)); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -461,7 +461,7 @@ public void Items_removed_by_index_from_the_binding_list_are_removed_from_the_Ob obbl.RemoveAt(2); - Assert.False(oc.Contains(item)); + Assert.DoesNotContain(item, oc); } [ConditionalFact] @@ -480,7 +480,7 @@ public void Items_cleared_from_the_binding_list_are_cleared_from_the_ObservableH obbl.Clear(); - Assert.Equal(0, oc.Count); + Assert.Empty(oc); } [ConditionalFact] @@ -512,7 +512,7 @@ public void Attempt_to_AddNew_on_set_for_abstract_type_works_if_AddingNew_event_ obbl.AddNew(); obbl.EndNew(0); - Assert.True(obbl.Contains(item)); + Assert.Contains(item, obbl); } [ConditionalFact] @@ -526,7 +526,7 @@ public void obbl.AddNew(); obbl.EndNew(0); - Assert.True(obbl.Contains(item)); + Assert.Contains(item, obbl); } private class ListElement diff --git a/test/EFCore.Tests/ChangeTracking/Internal/ObservableCollectionListSourceTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/ObservableCollectionListSourceTest.cs index be147b13007..b587d8b8606 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/ObservableCollectionListSourceTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/ObservableCollectionListSourceTest.cs @@ -13,7 +13,7 @@ public class ObservableCollectionListSourceTest public void ObservableCollectionListSource_exposes_ObservableCollection_parameterless_constructor() { var ols = new ObservableCollectionListSource(); - Assert.Equal(0, ols.Count); + Assert.Empty(ols); } [ConditionalFact] diff --git a/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs index 10675eb4480..5a9a02c5fe1 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs @@ -3340,7 +3340,7 @@ public void Fixup_works_when_changing_state_from_Detached_to_Modified(bool detac } else { - Assert.Equal(1, context.ChangeTracker.Entries().Count()); + Assert.Single(context.ChangeTracker.Entries()); Assert.Equal(EntityState.Deleted, context.Entry(details).State); } diff --git a/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs b/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs index 1b9f747e89e..95ae634bfd7 100644 --- a/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs +++ b/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs @@ -132,12 +132,12 @@ public void Contains_works() foreach (var item in testData) { - Assert.True(hashSet.Contains(item)); + Assert.Contains(item, hashSet); } foreach (var item in CreateTestData(1000, 10000).Except(testData)) { - Assert.False(hashSet.Contains(item)); + Assert.DoesNotContain(item, hashSet); } } diff --git a/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs b/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs index 9d7893da02d..576109779cd 100644 --- a/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs +++ b/test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs @@ -170,13 +170,13 @@ public void Setting_IsModified_is_not_reset_by_OriginalValues() [ConditionalFact] public void Can_get_name() - => Can_get_name(); + => Can_get_name_helper(); [ConditionalFact] public void Can_get_name_with_object_field() - => Can_get_name(); + => Can_get_name_helper(); - private void Can_get_name() + private void Can_get_name_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -194,13 +194,13 @@ private void Can_get_name() [ConditionalFact] public void Can_get_current_value() - => Can_get_current_value(); + => Can_get_current_value_helper(); [ConditionalFact] public void Can_get_current_value_with_object_field() - => Can_get_current_value(); + => Can_get_current_value_helper(); - private void Can_get_current_value() + private void Can_get_current_value_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -219,13 +219,13 @@ private void Can_get_current_value() [ConditionalFact] public void Can_set_current_value() - => Can_set_current_value(); + => Can_set_current_value_helper(); [ConditionalFact] public void Can_set_current_value_with_object_field() - => Can_set_current_value(); + => Can_set_current_value_helper(); - private void Can_set_current_value() + private void Can_set_current_value_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -249,13 +249,13 @@ private void Can_set_current_value() [ConditionalFact] public void Can_set_current_value_to_null() - => Can_set_current_value_to_null(); + => Can_set_current_value_to_null_helper(); [ConditionalFact] public void Can_set_current_value_to_null_with_object_field() - => Can_set_current_value_to_null(); + => Can_set_current_value_to_null_helper(); - private void Can_set_current_value_to_null() + private void Can_set_current_value_to_null_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -279,13 +279,13 @@ private void Can_set_current_value_to_null() [ConditionalFact] public void Can_set_and_get_original_value() - => Can_set_and_get_original_value(); + => Can_set_and_get_original_value_helper(); [ConditionalFact] public void Can_set_and_get_original_value_with_object_field() - => Can_set_and_get_original_value(); + => Can_set_and_get_original_value_helper(); - private void Can_set_and_get_original_value() + private void Can_set_and_get_original_value_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -318,13 +318,13 @@ private void Can_set_and_get_original_value() [ConditionalFact] public void Can_set_and_get_original_value_starting_null() - => Can_set_and_get_original_value_starting_null(); + => Can_set_and_get_original_value_starting_null_helper(); [ConditionalFact] public void Can_set_and_get_original_value_starting_null_with_object_field() - => Can_set_and_get_original_value_starting_null(); + => Can_set_and_get_original_value_starting_null_helper(); - private void Can_set_and_get_original_value_starting_null() + private void Can_set_and_get_original_value_starting_null_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -357,13 +357,13 @@ private void Can_set_and_get_original_value_starting_null() [ConditionalFact] public void Can_set_original_value_to_null() - => Can_set_original_value_to_null(); + => Can_set_original_value_to_null_helper(); [ConditionalFact] public void Can_set_original_value_to_null_with_object_field() - => Can_set_original_value_to_null(); + => Can_set_original_value_to_null_helper(); - private void Can_set_original_value_to_null() + private void Can_set_original_value_to_null_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -387,13 +387,13 @@ private void Can_set_original_value_to_null() [ConditionalFact] public void Can_set_and_clear_modified_on_Modified_entity() - => Can_set_and_clear_modified_on_Modified_entity(); + => Can_set_and_clear_modified_on_Modified_entity_helper(); [ConditionalFact] public void Can_set_and_clear_modified_on_Modified_entity_with_object_field() - => Can_set_and_clear_modified_on_Modified_entity(); + => Can_set_and_clear_modified_on_Modified_entity_helper(); - private void Can_set_and_clear_modified_on_Modified_entity() + private void Can_set_and_clear_modified_on_Modified_entity_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -438,15 +438,15 @@ private void Can_set_and_clear_modified_on_Modified_entity() [InlineData(EntityState.Added)] [InlineData(EntityState.Deleted)] public void Can_set_and_clear_modified_on_Added_or_Deleted_entity(EntityState initialState) - => Can_set_and_clear_modified_on_Added_or_Deleted_entity(initialState); + => Can_set_and_clear_modified_on_Added_or_Deleted_entity_helper(initialState); [ConditionalTheory] [InlineData(EntityState.Added)] [InlineData(EntityState.Deleted)] public void Can_set_and_clear_modified_on_Added_or_Deleted_entity_with_object_field(EntityState initialState) - => Can_set_and_clear_modified_on_Added_or_Deleted_entity(initialState); + => Can_set_and_clear_modified_on_Added_or_Deleted_entity_helper(initialState); - private void Can_set_and_clear_modified_on_Added_or_Deleted_entity(EntityState initialState) + private void Can_set_and_clear_modified_on_Added_or_Deleted_entity_helper(EntityState initialState) where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -482,15 +482,15 @@ private void Can_set_and_clear_modified_on_Added_or_Deleted_entity(Entit [InlineData(EntityState.Detached)] [InlineData(EntityState.Unchanged)] public void Can_set_and_clear_modified_on_Unchanged_or_Detached_entity(EntityState initialState) - => Can_set_and_clear_modified_on_Unchanged_or_Detached_entity(initialState); + => Can_set_and_clear_modified_on_Unchanged_or_Detached_entity_helper(initialState); [ConditionalTheory] [InlineData(EntityState.Detached)] [InlineData(EntityState.Unchanged)] public void Can_set_and_clear_modified_on_Unchanged_or_Detached_entity_with_object_field(EntityState initialState) - => Can_set_and_clear_modified_on_Unchanged_or_Detached_entity(initialState); + => Can_set_and_clear_modified_on_Unchanged_or_Detached_entity_helper(initialState); - private void Can_set_and_clear_modified_on_Unchanged_or_Detached_entity(EntityState initialState) + private void Can_set_and_clear_modified_on_Unchanged_or_Detached_entity_helper(EntityState initialState) where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -524,13 +524,13 @@ private void Can_set_and_clear_modified_on_Unchanged_or_Detached_entity( [ConditionalFact] public void Can_reject_changes_when_clearing_modified_flag() - => Can_reject_changes_when_clearing_modified_flag(); + => Can_reject_changes_when_clearing_modified_flag_helper(); [ConditionalFact] public void Can_reject_changes_when_clearing_modified_flag_with_object_field() - => Can_reject_changes_when_clearing_modified_flag(); + => Can_reject_changes_when_clearing_modified_flag_helper(); - private void Can_reject_changes_when_clearing_modified_flag() + private void Can_reject_changes_when_clearing_modified_flag_helper() where TWotty : IWotty, new() { using (var context = new PrimateContext()) @@ -599,13 +599,13 @@ private void Can_reject_changes_when_clearing_modified_flag() [ConditionalFact] public void Can_get_name_generic() - => Can_get_name_generic(); + => Can_get_name_generic_helper(); [ConditionalFact] public void Can_get_name_generic_with_object_field() - => Can_get_name_generic(); + => Can_get_name_generic_helper(); - private void Can_get_name_generic() + private void Can_get_name_generic_helper() where TWotty : class, IWotty, new() { var entry = InMemoryTestHelpers.Instance.CreateInternalEntry( @@ -618,13 +618,13 @@ private void Can_get_name_generic() [ConditionalFact] public void Can_get_current_value_generic() - => Can_get_current_value_generic(); + => Can_get_current_value_generic_helper(); [ConditionalFact] public void Can_get_current_value_generic_with_object_field() - => Can_get_current_value_generic(); + => Can_get_current_value_generic_helper(); - private void Can_get_current_value_generic() + private void Can_get_current_value_generic_helper() where TWotty : class, IWotty, new() { var entry = InMemoryTestHelpers.Instance.CreateInternalEntry( @@ -637,13 +637,13 @@ private void Can_get_current_value_generic() [ConditionalFact] public void Can_set_current_value_generic() - => Can_set_current_value_generic(); + => Can_set_current_value_generic_helper(); [ConditionalFact] public void Can_set_current_value_generic_with_object_field() - => Can_set_current_value_generic(); + => Can_set_current_value_generic_helper(); - private void Can_set_current_value_generic() + private void Can_set_current_value_generic_helper() where TWotty : class, IWotty, new() { var entity = new TWotty { Id = 1, Primate = "Monkey" }; @@ -660,13 +660,13 @@ private void Can_set_current_value_generic() [ConditionalFact] public void Can_set_current_value_to_null_generic() - => Can_set_current_value_to_null_generic(); + => Can_set_current_value_to_null_generic_helper(); [ConditionalFact] public void Can_set_current_value_to_null_generic_with_object_field() - => Can_set_current_value_to_null_generic(); + => Can_set_current_value_to_null_generic_helper(); - private void Can_set_current_value_to_null_generic() + private void Can_set_current_value_to_null_generic_helper() where TWotty : class, IWotty, new() { var entity = new TWotty { Id = 1, Primate = "Monkey" }; @@ -683,13 +683,13 @@ private void Can_set_current_value_to_null_generic() [ConditionalFact] public void Can_set_and_get_original_value_generic() - => Can_set_and_get_original_value_generic(); + => Can_set_and_get_original_value_generic_helper(); [ConditionalFact] public void Can_set_and_get_original_value_generic_with_object_field() - => Can_set_and_get_original_value_generic(); + => Can_set_and_get_original_value_generic_helper(); - private void Can_set_and_get_original_value_generic() + private void Can_set_and_get_original_value_generic_helper() where TWotty : class, IWotty, new() { var entity = new TWotty { Id = 1, Primate = "Monkey" }; @@ -709,13 +709,13 @@ private void Can_set_and_get_original_value_generic() [ConditionalFact] public void Can_set_original_value_to_null_generic() - => Can_set_original_value_to_null_generic(); + => Can_set_original_value_to_null_generic_helper(); [ConditionalFact] public void Can_set_original_value_to_null_generic_with_object_field() - => Can_set_original_value_to_null_generic(); + => Can_set_original_value_to_null_generic_helper(); - private void Can_set_original_value_to_null_generic() + private void Can_set_original_value_to_null_generic_helper() where TWotty : class, IWotty, new() { var entry = InMemoryTestHelpers.Instance.CreateInternalEntry( @@ -730,13 +730,13 @@ private void Can_set_original_value_to_null_generic() [ConditionalFact] public void Can_set_and_clear_modified_generic() - => Can_set_and_clear_modified_generic(); + => Can_set_and_clear_modified_generic_helper(); [ConditionalFact] public void Can_set_and_clear_modified_generic_with_object_field() - => Can_set_and_clear_modified_generic(); + => Can_set_and_clear_modified_generic_helper(); - private void Can_set_and_clear_modified_generic() + private void Can_set_and_clear_modified_generic_helper() where TWotty : class, IWotty, new() { var entity = new TWotty { Id = 1, Primate = "Monkey" }; diff --git a/test/EFCore.Tests/DbContextOptionsTest.cs b/test/EFCore.Tests/DbContextOptionsTest.cs index a13fb56d979..ee216903577 100644 --- a/test/EFCore.Tests/DbContextOptionsTest.cs +++ b/test/EFCore.Tests/DbContextOptionsTest.cs @@ -81,7 +81,7 @@ public void Can_update_an_existing_extension() ((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension1); ((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension2); - Assert.Equal(1, optionsBuilder.Options.Extensions.Count()); + Assert.Single(optionsBuilder.Options.Extensions); Assert.DoesNotContain(extension1, optionsBuilder.Options.Extensions); Assert.Contains(extension2, optionsBuilder.Options.Extensions); diff --git a/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs b/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs index e76430cb0fc..a59830cbadf 100644 --- a/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs +++ b/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs @@ -27,7 +27,7 @@ public void Include_on_non_ef_queryable_is_no_op() var q = new List().AsQueryable(); var q2 = q.Include(c => c.Orders).ThenInclude(o => o.OrderDetails).ToList(); - Assert.Equal(0, q2.Count); + Assert.Empty(q2); } [ConditionalFact] @@ -36,7 +36,7 @@ public void AsTracking_on_non_ef_queryable_is_no_op() var q = new List().AsQueryable(); var q2 = q.AsTracking().ToList(); - Assert.Equal(0, q2.Count); + Assert.Empty(q2); } [ConditionalFact] @@ -45,7 +45,7 @@ public void AsNoTracking_on_non_ef_queryable_is_no_op() var q = new List().AsQueryable(); var q2 = q.AsNoTracking().ToList(); - Assert.Equal(0, q2.Count); + Assert.Empty(q2); } // ReSharper disable MethodSupportsCancellation diff --git a/test/EFCore.Tests/Metadata/Conventions/ConstructorBindingConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/ConstructorBindingConventionTest.cs index 0156f8d93a4..cd5eda42329 100644 --- a/test/EFCore.Tests/Metadata/Conventions/ConstructorBindingConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/ConstructorBindingConventionTest.cs @@ -50,7 +50,7 @@ public void Binds_to_parameterless_constructor_if_no_services() var parameters = constructorBinding.Constructor.GetParameters(); var bindings = constructorBinding.ParameterBindings; - Assert.Equal(0, parameters.Length); + Assert.Empty(parameters); Assert.Equal(0, bindings.Count); } @@ -118,7 +118,7 @@ public void Binds_to_zero_scalars_one_service() var parameters = constructorBinding.Constructor.GetParameters(); var bindings = constructorBinding.ParameterBindings; - Assert.Equal(1, parameters.Length); + Assert.Single(parameters); Assert.Equal(1, bindings.Count); Assert.Equal("loader", parameters[0].Name); @@ -549,7 +549,7 @@ public void Binds_to_context_typed() var parameters = constructorBinding.Constructor.GetParameters(); var bindings = constructorBinding.ParameterBindings; - Assert.Equal(1, parameters.Length); + Assert.Single(parameters); Assert.Equal(1, bindings.Count); Assert.Equal("context", parameters[0].Name); @@ -576,7 +576,7 @@ public void Binds_to_ILazyLoader() var parameters = constructorBinding.Constructor.GetParameters(); var bindings = constructorBinding.ParameterBindings; - Assert.Equal(1, parameters.Length); + Assert.Single(parameters); Assert.Equal(1, bindings.Count); Assert.Equal("loader", parameters[0].Name); @@ -603,7 +603,7 @@ public void Binds_to_delegate_parameter_called_lazyLoader() var parameters = constructorBinding.Constructor.GetParameters(); var bindings = constructorBinding.ParameterBindings; - Assert.Equal(1, parameters.Length); + Assert.Single(parameters); Assert.Equal(1, bindings.Count); Assert.Equal("lazyLoader", parameters[0].Name); @@ -630,7 +630,7 @@ public void Binds_to_IEntityType() var parameters = constructorBinding.Constructor.GetParameters(); var bindings = constructorBinding.ParameterBindings; - Assert.Equal(1, parameters.Length); + Assert.Single(parameters); Assert.Equal(1, bindings.Count); Assert.Equal("entityType", parameters[0].Name); @@ -656,7 +656,7 @@ public void Does_not_bind_to_delegate_parameter_not_called_lazyLoader() var parameters = constructorBinding.Constructor.GetParameters(); var bindings = constructorBinding.ParameterBindings; - Assert.Equal(0, parameters.Length); + Assert.Empty(parameters); Assert.Equal(0, bindings.Count); } diff --git a/test/EFCore.Tests/Metadata/Conventions/EntityTypeAttributeConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/EntityTypeAttributeConventionTest.cs index 98de850e7b8..4435871c1de 100644 --- a/test/EFCore.Tests/Metadata/Conventions/EntityTypeAttributeConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/EntityTypeAttributeConventionTest.cs @@ -28,7 +28,7 @@ public void NotMappedAttribute_overrides_configuration_from_convention_source() RunConvention(entityBuilder); - Assert.Equal(0, modelBuilder.Metadata.GetEntityTypes().Count()); + Assert.Empty(modelBuilder.Metadata.GetEntityTypes()); } [ConditionalFact] @@ -40,7 +40,7 @@ public void NotMappedAttribute_does_not_override_configuration_from_explicit_sou RunConvention(entityBuilder); - Assert.Equal(1, modelBuilder.Metadata.GetEntityTypes().Count()); + Assert.Single(modelBuilder.Metadata.GetEntityTypes()); } [ConditionalFact] @@ -50,7 +50,7 @@ public void NotMappedAttribute_ignores_entityTypes_with_conventional_builder() modelBuilder.Entity(); - Assert.Equal(1, modelBuilder.Model.GetEntityTypes().Count()); + Assert.Single(modelBuilder.Model.GetEntityTypes()); } #endregion diff --git a/test/EFCore.Tests/Metadata/Conventions/PropertyAttributeConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/PropertyAttributeConventionTest.cs index 5b135cc3602..2e6c696c35c 100644 --- a/test/EFCore.Tests/Metadata/Conventions/PropertyAttributeConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/PropertyAttributeConventionTest.cs @@ -308,7 +308,7 @@ public void NotMappedAttribute_overrides_configuration_from_convention_source() RunConvention(entityTypeBuilder); - Assert.False(entityTypeBuilder.Metadata.GetProperties().Any(p => p.Name == "IgnoredProperty")); + Assert.DoesNotContain(entityTypeBuilder.Metadata.GetProperties(), p => p.Name == "IgnoredProperty"); } [ConditionalFact] @@ -319,7 +319,7 @@ public void NotMappedAttribute_does_not_override_configuration_from_explicit_sou RunConvention(entityTypeBuilder); - Assert.True(entityTypeBuilder.Metadata.GetProperties().Any(p => p.Name == "IgnoredProperty")); + Assert.Contains(entityTypeBuilder.Metadata.GetProperties(), p => p.Name == "IgnoredProperty"); } [ConditionalFact] @@ -328,7 +328,7 @@ public void NotMappedAttribute_ignores_property_with_conventional_builder() var modelBuilder = CreateModelBuilder(); var entityTypeBuilder = modelBuilder.Entity(); - Assert.False(entityTypeBuilder.Metadata.GetProperties().Any(p => p.Name == "IgnoredProperty")); + Assert.DoesNotContain(entityTypeBuilder.Metadata.GetProperties(), p => p.Name == "IgnoredProperty"); } [ConditionalFact] @@ -339,7 +339,7 @@ public void NotMappedAttribute_on_field_does_not_ignore_property_with_convention entityTypeBuilder.Property(nameof(F.IgnoredProperty)); // Because bringing the property in by the fluent API overrides the annotation it has no effect - Assert.True(entityTypeBuilder.Metadata.GetProperties().Any(p => p.Name == "IgnoredProperty")); + Assert.Contains(entityTypeBuilder.Metadata.GetProperties(), p => p.Name == "IgnoredProperty"); } [ConditionalFact] @@ -350,7 +350,7 @@ public void NotMappedAttribute_on_field_overrides_configuration_from_convention_ RunConvention(entityTypeBuilder); - Assert.False(entityTypeBuilder.Metadata.GetProperties().Any(p => p.Name == "IgnoredProperty")); + Assert.DoesNotContain(entityTypeBuilder.Metadata.GetProperties(), p => p.Name == "IgnoredProperty"); } #endregion diff --git a/test/EFCore.Tests/Metadata/Conventions/PropertyDiscoveryConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/PropertyDiscoveryConventionTest.cs index de32de49cfd..1a505de5740 100644 --- a/test/EFCore.Tests/Metadata/Conventions/PropertyDiscoveryConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/PropertyDiscoveryConventionTest.cs @@ -63,7 +63,7 @@ public void Properties_with_private_setters_on_unmapped_base_types_are_discovere { var model = context.Model; - Assert.Equal(1, model.GetEntityTypes().Count()); + Assert.Single(model.GetEntityTypes()); var entityType = model.FindEntityType(typeof(DerivedWithoutPrivates)); diff --git a/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs b/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs index 1063a24bea9..8b844d51faf 100644 --- a/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs +++ b/test/EFCore.Tests/Metadata/Conventions/RelationshipDiscoveryConventionTest.cs @@ -248,7 +248,7 @@ public void Many_to_many_bidirectional_is_not_discovered() Assert.Empty(entityBuilder.Metadata.GetForeignKeys()); Assert.Empty(entityBuilder.Metadata.GetNavigations()); - Assert.Equal(1, entityBuilder.Metadata.Model.GetEntityTypes().Count()); + Assert.Single(entityBuilder.Metadata.Model.GetEntityTypes()); } [ConditionalFact] @@ -387,7 +387,7 @@ public void Multiple_navigations_to_same_entity_type_are_discovered() var secondEntityType = model.GetEntityTypes().Single(e => e.ClrType == typeof(MultipleNavigationsSecond)); Assert.Equal(2, firstEntityType.GetProperties().Count()); - Assert.Equal(1, firstEntityType.GetKeys().Count()); + Assert.Single(firstEntityType.GetKeys()); var firstFK = firstEntityType.GetForeignKeys().Single(); Assert.False(firstFK.IsRequired); Assert.False(firstFK.IsUnique); @@ -400,7 +400,7 @@ public void Multiple_navigations_to_same_entity_type_are_discovered() firstEntityType.GetNavigations().Select(n => n.Name)); Assert.Equal(2, secondEntityType.GetProperties().Count()); - Assert.Equal(1, secondEntityType.GetKeys().Count()); + Assert.Single(secondEntityType.GetKeys()); var secondFK = firstEntityType.GetForeignKeys().Single(); Assert.False(secondFK.IsRequired); Assert.False(secondFK.IsUnique); @@ -692,7 +692,7 @@ public void Navigation_to_derived_is_discovered() var derivedFk = entityBuilder.Metadata.GetNavigations() .Single(n => n.Name == nameof(NavigationsToBaseAndDerived.DerivedOne)).ForeignKey; Assert.Equal(nameof(DerivedOne.DerivedNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name); - Assert.Equal(1, entityBuilder.Metadata.GetNavigations().Count()); + Assert.Single(entityBuilder.Metadata.GetNavigations()); Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count()); } @@ -713,7 +713,7 @@ public void Navigation_to_derived_is_discovered_if_inverse_inherited() var derivedFk = entityBuilder.Metadata.GetNavigations() .Single(n => n.Name == nameof(NavigationsToBaseAndDerived.DerivedOne)).ForeignKey; Assert.Equal(nameof(Base.BaseNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name); - Assert.Equal(1, entityBuilder.Metadata.GetNavigations().Count()); + Assert.Single(entityBuilder.Metadata.GetNavigations()); Assert.Equal(3, entityBuilder.Metadata.Model.GetEntityTypes().Count()); } @@ -749,7 +749,7 @@ public void Navigation_to_derived_is_discovered_if_base_ignored() var derivedFk = entityBuilder.Metadata.FindNavigation(nameof(NavigationsToBaseAndDerived.DerivedOne)).ForeignKey; Assert.Equal(nameof(DerivedOne.BaseNavigation), derivedFk.FindNavigationsTo(entityBuilder.Metadata).Single().Name); - Assert.Equal(1, entityBuilder.Metadata.GetNavigations().Count()); + Assert.Single(entityBuilder.Metadata.GetNavigations()); Assert.Equal(2, entityBuilder.Metadata.Model.GetEntityTypes().Count()); } @@ -941,12 +941,12 @@ public void Navigation_to_abstract_is_discovered() var entityType = model.GetEntityTypes().Single(); Assert.Equal(2, entityType.GetProperties().Count()); - Assert.Equal(1, entityType.GetKeys().Count()); + Assert.Single(entityType.GetKeys()); var fk = entityType.GetForeignKeys().Single(); Assert.False(fk.IsUnique); Assert.True(fk.PrincipalEntityType.ClrType.GetTypeInfo().IsAbstract); - Assert.Equal(1, entityType.GetNavigations().Count()); + Assert.Single(entityType.GetNavigations()); } [ConditionalFact] @@ -1059,8 +1059,8 @@ private class ReadOnlyCollectionNavigationEntity if (singleRelationship) { var principalEntityType = fk.PrincipalEntityType; - Assert.Equal(1, principalEntityType.GetDeclaredProperties().Count()); - Assert.Equal(1, principalEntityType.GetKeys().Count()); + Assert.Single(principalEntityType.GetDeclaredProperties()); + Assert.Single(principalEntityType.GetKeys()); Assert.Empty(principalEntityType.GetDeclaredForeignKeys()); if ((expectedInverseName == null) && navigation.IsDependentToPrincipal()) @@ -1069,7 +1069,7 @@ private class ReadOnlyCollectionNavigationEntity } var dependentEntityType = fk.DeclaringEntityType; - Assert.Equal(1, dependentEntityType.GetDeclaredProperties().Count()); + Assert.Single(dependentEntityType.GetDeclaredProperties()); Assert.Equal(principalEntityType.IsAssignableFrom(dependentEntityType) ? 1 : 0, dependentEntityType.GetKeys().Count()); if ((expectedInverseName == null) && !navigation.IsDependentToPrincipal()) @@ -1083,7 +1083,7 @@ private class ReadOnlyCollectionNavigationEntity Navigation navigation, string expectedInverseName, bool unique, bool singleRelationship = true) { IForeignKey fk = navigation.ForeignKey; - Assert.Equal(1, fk.DeclaringEntityType.Model.GetEntityTypes().Count()); + Assert.Single(fk.DeclaringEntityType.Model.GetEntityTypes()); Assert.Equal(expectedInverseName, navigation.FindInverse()?.Name); Assert.Equal(unique, fk.IsUnique); Assert.NotSame(fk.Properties.Single(), fk.PrincipalKey.Properties.Single()); @@ -1092,8 +1092,8 @@ private class ReadOnlyCollectionNavigationEntity var entityType = fk.DeclaringEntityType; if (singleRelationship) { - Assert.Equal(1, entityType.GetKeys().Count()); - Assert.Equal(1, entityType.GetForeignKeys().Count()); + Assert.Single(entityType.GetKeys()); + Assert.Single(entityType.GetForeignKeys()); Assert.Equal(2, entityType.GetProperties().Count()); Assert.Equal(expectedInverseName == null ? 1 : 2, entityType.GetNavigations().Count()); } diff --git a/test/EFCore.Tests/Metadata/Internal/ClrCollectionAccessorFactoryTest.cs b/test/EFCore.Tests/Metadata/Internal/ClrCollectionAccessorFactoryTest.cs index 2bd25aeb035..53c0820e4a4 100644 --- a/test/EFCore.Tests/Metadata/Internal/ClrCollectionAccessorFactoryTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/ClrCollectionAccessorFactoryTest.cs @@ -228,12 +228,12 @@ public void Delegate_accessor_handles_uninitialized_collections_prop_no_field_fo accessor.Add(entity, value, forMaterialization: false); Assert.True(accessor.Contains(entity, value)); - Assert.Equal(1, reader(entity).Count()); + Assert.Single(reader(entity)); accessor.Remove(entity, value); Assert.False(accessor.Contains(entity, value)); - Assert.Equal(0, reader(entity).Count()); + Assert.Empty(reader(entity)); } [ConditionalFact] diff --git a/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs b/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs index 5bedcf3cc0a..808ba4c2b11 100644 --- a/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/EntityTypeTest.cs @@ -214,7 +214,7 @@ public void Can_clear_the_primary_key_if_it_is_referenced_from_a_foreign_key() entityType.SetPrimaryKey(null); - Assert.Equal(1, entityType.GetKeys().Count()); + Assert.Single(entityType.GetKeys()); Assert.Same(customerPk, entityType.FindKey(idProperty)); Assert.Null(entityType.FindPrimaryKey()); Assert.Same(customerPk, fk.PrincipalKey); @@ -1157,7 +1157,7 @@ public void Can_add_retrieve_and_remove_indexes() var property1 = entityType.AddProperty(Order.IdProperty); var property2 = entityType.AddProperty(Order.CustomerIdProperty); - Assert.Equal(0, entityType.GetIndexes().Count()); + Assert.Empty(entityType.GetIndexes()); Assert.Null(entityType.RemoveIndex(new[] { property1 })); Assert.False(property1.IsIndex()); Assert.Empty(property1.GetContainingIndexes()); @@ -1187,14 +1187,14 @@ public void Can_add_retrieve_and_remove_indexes() Assert.Same(index1, entityType.RemoveIndex(index1.Properties)); Assert.Null(entityType.RemoveIndex(index1.Properties)); - Assert.Equal(1, entityType.GetIndexes().Count()); + Assert.Single(entityType.GetIndexes()); Assert.Same(index2, entityType.GetIndexes().Single()); Assert.Same(index2, entityType.RemoveIndex(new[] { property1, property2 })); Assert.Null(((Index)index1).Builder); Assert.Null(((Index)index2).Builder); - Assert.Equal(0, entityType.GetIndexes().Count()); + Assert.Empty(entityType.GetIndexes()); Assert.False(property1.IsIndex()); Assert.Empty(property1.GetContainingIndexes()); } diff --git a/test/EFCore.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs b/test/EFCore.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs index d53b62a5516..b105b690d03 100644 --- a/test/EFCore.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs @@ -253,8 +253,8 @@ public void ForeignKey_promotes_derived_foreign_key_of_lower_or_equal_source() new[] { Order.IdProperty.Name }, ConfigurationSource.Convention); - Assert.Equal(1, derivedEntityBuilder.Metadata.GetForeignKeys().Count()); - Assert.Equal(1, entityBuilder.Metadata.GetForeignKeys().Count()); + Assert.Single(derivedEntityBuilder.Metadata.GetForeignKeys()); + Assert.Single(entityBuilder.Metadata.GetForeignKeys()); var foreignKeyBuilder = entityBuilder.HasRelationship( principalEntityBuilder.Metadata.Name, @@ -262,7 +262,7 @@ public void ForeignKey_promotes_derived_foreign_key_of_lower_or_equal_source() primaryKey, ConfigurationSource.Convention); - Assert.Equal(1, entityBuilder.Metadata.GetForeignKeys().Count()); + Assert.Single(entityBuilder.Metadata.GetForeignKeys()); Assert.Empty(derivedEntityBuilder.Metadata.GetDeclaredForeignKeys()); Assert.Equal(ConfigurationSource.DataAnnotation, foreignKeyBuilder.Metadata.GetConfigurationSource()); Assert.True(foreignKeyBuilder.Metadata.IsUnique); @@ -544,7 +544,7 @@ public void Removing_relationship_does_not_remove_conventional_index_if_in_use() Assert.NotNull(dependentEntityBuilder.HasNoRelationship(relationshipBuilder.Metadata, ConfigurationSource.DataAnnotation)); - Assert.Equal(1, dependentEntityBuilder.Metadata.GetIndexes().Count()); + Assert.Single(dependentEntityBuilder.Metadata.GetIndexes()); Assert.Equal(Order.CustomerIdProperty.Name, dependentEntityBuilder.Metadata.GetIndexes().First().Properties.First().Name); Assert.Empty(dependentEntityBuilder.Metadata.GetForeignKeys()); } @@ -2518,8 +2518,8 @@ public void Can_set_base_type_if_duplicate_properties_of_higher_source() derivedEntityBuilder, derivedEntityBuilder.HasBaseType(entityBuilder.Metadata.Name, ConfigurationSource.Convention)); Assert.Same(entityBuilder.Metadata, derivedEntityBuilder.Metadata.BaseType); - Assert.Equal(1, entityBuilder.Metadata.GetDeclaredProperties().Count()); - Assert.Equal(0, derivedEntityBuilder.Metadata.GetDeclaredProperties().Count()); + Assert.Single(entityBuilder.Metadata.GetDeclaredProperties()); + Assert.Empty(derivedEntityBuilder.Metadata.GetDeclaredProperties()); } [ConditionalFact] @@ -2532,13 +2532,13 @@ public void Can_only_set_base_type_if_keys_of_data_annotation_or_lower_source() Assert.Null(derivedEntityBuilder.HasBaseType(entityBuilder.Metadata, ConfigurationSource.Convention)); Assert.Null(derivedEntityBuilder.Metadata.BaseType); - Assert.Equal(1, derivedEntityBuilder.Metadata.GetDeclaredKeys().Count()); + Assert.Single(derivedEntityBuilder.Metadata.GetDeclaredKeys()); Assert.Same( derivedEntityBuilder, derivedEntityBuilder.HasBaseType(typeof(Order), ConfigurationSource.Explicit)); Assert.Same(entityBuilder.Metadata, derivedEntityBuilder.Metadata.BaseType); - Assert.Equal(0, derivedEntityBuilder.Metadata.GetDeclaredKeys().Count()); + Assert.Empty(derivedEntityBuilder.Metadata.GetDeclaredKeys()); } [ConditionalFact] @@ -2558,14 +2558,14 @@ public void Can_only_set_base_type_if_relationship_with_conflicting_navigation_o Assert.Null(derivedDependentEntityBuilder.HasBaseType(dependentEntityBuilder.Metadata, ConfigurationSource.Convention)); Assert.Null(derivedDependentEntityBuilder.Metadata.BaseType); - Assert.Equal(1, derivedDependentEntityBuilder.Metadata.GetDeclaredNavigations().Count()); + Assert.Single(derivedDependentEntityBuilder.Metadata.GetDeclaredNavigations()); Assert.Same( derivedDependentEntityBuilder, derivedDependentEntityBuilder.HasBaseType(dependentEntityBuilder.Metadata, ConfigurationSource.Explicit)); Assert.Same(dependentEntityBuilder.Metadata, derivedDependentEntityBuilder.Metadata.BaseType); - Assert.Equal(1, dependentEntityBuilder.Metadata.GetDeclaredNavigations().Count()); - Assert.Equal(0, derivedDependentEntityBuilder.Metadata.GetDeclaredNavigations().Count()); + Assert.Single(dependentEntityBuilder.Metadata.GetDeclaredNavigations()); + Assert.Empty(derivedDependentEntityBuilder.Metadata.GetDeclaredNavigations()); } [ConditionalFact] @@ -2584,8 +2584,8 @@ public void Can_set_base_type_if_relationship_with_conflicting_foreign_key_of_da derivedDependentEntityBuilder, derivedDependentEntityBuilder.HasBaseType(dependentEntityBuilder.Metadata, ConfigurationSource.Convention)); Assert.Same(dependentEntityBuilder.Metadata, derivedDependentEntityBuilder.Metadata.BaseType); - Assert.Equal(1, dependentEntityBuilder.Metadata.GetDeclaredForeignKeys().Count()); - Assert.Equal(0, derivedDependentEntityBuilder.Metadata.GetDeclaredForeignKeys().Count()); + Assert.Single(dependentEntityBuilder.Metadata.GetDeclaredForeignKeys()); + Assert.Empty(derivedDependentEntityBuilder.Metadata.GetDeclaredForeignKeys()); } [ConditionalFact] @@ -2598,13 +2598,13 @@ public void Setting_base_type_preserves_index() derivedEntityBuilder.Property(Order.IdProperty, ConfigurationSource.Convention); derivedEntityBuilder.HasIndex(new[] { Order.IdProperty.Name }, ConfigurationSource.DataAnnotation) .IsUnique(true, ConfigurationSource.Convention); - Assert.Equal(1, derivedEntityBuilder.Metadata.GetDeclaredIndexes().Count()); + Assert.Single(derivedEntityBuilder.Metadata.GetDeclaredIndexes()); Assert.Same( derivedEntityBuilder, derivedEntityBuilder.HasBaseType(entityBuilder.Metadata, ConfigurationSource.Convention)); - Assert.Equal(1, derivedEntityBuilder.Metadata.GetDeclaredIndexes().Count()); + Assert.Single(derivedEntityBuilder.Metadata.GetDeclaredIndexes()); Assert.True(derivedEntityBuilder.Metadata.GetDeclaredIndexes().First().IsUnique); } @@ -2625,16 +2625,16 @@ public void Setting_base_type_preserves_non_conflicting_referencing_relationship Customer.OrdersProperty.Name, ConfigurationSource.Convention) .HasPrincipalKey(new[] { derivedIdProperty }, ConfigurationSource.Convention); - Assert.Equal(1, derivedPrincipalEntityBuilder.Metadata.GetDeclaredKeys().Count()); + Assert.Single(derivedPrincipalEntityBuilder.Metadata.GetDeclaredKeys()); Assert.Same( derivedPrincipalEntityBuilder, derivedPrincipalEntityBuilder.HasBaseType(principalEntityBuilder.Metadata, ConfigurationSource.Convention)); - Assert.Equal(1, principalEntityBuilder.Metadata.GetDeclaredKeys().Count()); - Assert.Equal(0, derivedPrincipalEntityBuilder.Metadata.GetDeclaredKeys().Count()); - Assert.Equal(0, derivedPrincipalEntityBuilder.Metadata.GetForeignKeys().Count()); - Assert.Equal(0, principalEntityBuilder.Metadata.GetReferencingForeignKeys().Count()); + Assert.Single(principalEntityBuilder.Metadata.GetDeclaredKeys()); + Assert.Empty(derivedPrincipalEntityBuilder.Metadata.GetDeclaredKeys()); + Assert.Empty(derivedPrincipalEntityBuilder.Metadata.GetForeignKeys()); + Assert.Empty(principalEntityBuilder.Metadata.GetReferencingForeignKeys()); var fk = derivedPrincipalEntityBuilder.Metadata.GetReferencingForeignKeys().Single(); Assert.Equal(Order.CustomerProperty.Name, fk.DependentToPrincipal.Name); Assert.Equal(Customer.OrdersProperty.Name, fk.PrincipalToDependent.Name); @@ -2661,8 +2661,8 @@ public void Setting_base_type_preserves_non_conflicting_relationship_on_duplicat Assert.Same( derivedDependentEntityBuilder, derivedDependentEntityBuilder.HasBaseType(dependentEntityBuilder.Metadata, ConfigurationSource.Convention)); - Assert.Equal(0, dependentEntityBuilder.Metadata.GetForeignKeys().Count()); - Assert.Equal(0, dependentEntityBuilder.Metadata.GetDeclaredProperties().Count()); + Assert.Empty(dependentEntityBuilder.Metadata.GetForeignKeys()); + Assert.Empty(dependentEntityBuilder.Metadata.GetDeclaredProperties()); var fk = derivedDependentEntityBuilder.Metadata.GetForeignKeys().Single(); Assert.Equal(Order.CustomerProperty.Name, fk.DependentToPrincipal.Name); Assert.Equal(Customer.SpecialOrdersProperty.Name, fk.PrincipalToDependent.Name); @@ -2693,12 +2693,12 @@ public void Setting_base_type_fixes_relationship_conflicting_with_PK() Assert.Same( derivedDependentEntityBuilder, derivedDependentEntityBuilder.HasBaseType(dependentEntityBuilder.Metadata, ConfigurationSource.Explicit)); - Assert.Equal(0, dependentEntityBuilder.Metadata.GetForeignKeys().Count()); + Assert.Empty(dependentEntityBuilder.Metadata.GetForeignKeys()); var fk = derivedDependentEntityBuilder.Metadata.GetForeignKeys().Single(); Assert.Equal(Order.CustomerProperty.Name, fk.DependentToPrincipal.Name); Assert.Equal(Customer.SpecialOrdersProperty.Name, fk.PrincipalToDependent.Name); Assert.NotEqual(Order.IdProperty.Name, fk.Properties.Single().Name); - Assert.Equal(1, dependentEntityBuilder.Metadata.GetDeclaredProperties().Count()); + Assert.Single(dependentEntityBuilder.Metadata.GetDeclaredProperties()); } [ConditionalFact] @@ -2716,8 +2716,8 @@ public void Setting_base_type_removes_duplicate_service_properties() derivedEntityBuilder, derivedEntityBuilder.HasBaseType(entityBuilder.Metadata, ConfigurationSource.Explicit)); - Assert.Equal(1, entityBuilder.Metadata.GetServiceProperties().Count()); - Assert.Equal(1, derivedEntityBuilder.Metadata.GetServiceProperties().Count()); + Assert.Single(entityBuilder.Metadata.GetServiceProperties()); + Assert.Single(derivedEntityBuilder.Metadata.GetServiceProperties()); } [ConditionalFact] @@ -2731,7 +2731,7 @@ public void Can_access_discriminator() Assert.NotNull(typeBuilder.HasNoDeclaredDiscriminator()); Assert.Null(typeBuilder.Metadata.GetDiscriminatorProperty()); - Assert.Equal(0, typeBuilder.Metadata.GetProperties().Count()); + Assert.Empty(typeBuilder.Metadata.GetProperties()); Assert.NotNull(typeBuilder.HasDiscriminator("Splod", typeof(int?))); Assert.Equal("Splod", typeBuilder.Metadata.GetDiscriminatorProperty().Name); @@ -2778,7 +2778,7 @@ public void Discriminator_is_not_set_if_default_ignored() typeBuilder.Ignore("Discriminator", true); Assert.Null(typeBuilder.HasDiscriminator()); - Assert.Equal(0, typeBuilder.Metadata.GetProperties().Count()); + Assert.Empty(typeBuilder.Metadata.GetProperties()); } [ConditionalFact] @@ -2790,8 +2790,8 @@ public void Can_access_discriminator_value() var otherDerivedTypeBuilder = typeBuilder.ModelBuilder.Entity("Splow"); Assert.NotNull(typeBuilder.HasDiscriminator()); - Assert.Equal(1, typeBuilder.Metadata.GetDeclaredProperties().Count()); - Assert.Equal(0, derivedTypeBuilder.Metadata.GetDeclaredProperties().Count()); + Assert.Single(typeBuilder.Metadata.GetDeclaredProperties()); + Assert.Empty(derivedTypeBuilder.Metadata.GetDeclaredProperties()); var discriminatorBuilder = typeBuilder.HasDiscriminator("Splowed", typeof(int?)); Assert.NotNull(discriminatorBuilder.HasValue(typeBuilder.Metadata, 1)); @@ -2847,8 +2847,8 @@ public void Changing_discriminator_type_removes_values() var otherDerivedTypeBuilder = typeBuilder.ModelBuilder.Entity("Splow"); Assert.NotNull(typeBuilder.HasDiscriminator()); - Assert.Equal(1, typeBuilder.Metadata.GetDeclaredProperties().Count()); - Assert.Equal(0, derivedTypeBuilder.Metadata.GetDeclaredProperties().Count()); + Assert.Single(typeBuilder.Metadata.GetDeclaredProperties()); + Assert.Empty(derivedTypeBuilder.Metadata.GetDeclaredProperties()); var discriminatorBuilder = typeBuilder.HasDiscriminator("Splowed", typeof(int)); Assert.NotNull(discriminatorBuilder.HasValue(typeBuilder.Metadata, 1)); diff --git a/test/EFCore.Tests/Metadata/Internal/InternalModelBuilderTest.cs b/test/EFCore.Tests/Metadata/Internal/InternalModelBuilderTest.cs index f388f641732..ffb31b02cdc 100644 --- a/test/EFCore.Tests/Metadata/Internal/InternalModelBuilderTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/InternalModelBuilderTest.cs @@ -216,7 +216,7 @@ public void Cannot_ignore_entity_type_referenced_from_higher_source_foreign_key( Assert.Null(modelBuilder.Ignore(typeof(Customer), ConfigurationSource.DataAnnotation)); Assert.Equal(2, modelBuilder.Metadata.GetEntityTypes().Count()); - Assert.Equal(1, orderEntityTypeBuilder.Metadata.GetForeignKeys().Count()); + Assert.Single(orderEntityTypeBuilder.Metadata.GetForeignKeys()); } [ConditionalFact] diff --git a/test/EFCore.Tests/Metadata/Internal/InternalRelationshipBuilderTest.cs b/test/EFCore.Tests/Metadata/Internal/InternalRelationshipBuilderTest.cs index b17ab0b2fb0..a71489e6899 100644 --- a/test/EFCore.Tests/Metadata/Internal/InternalRelationshipBuilderTest.cs +++ b/test/EFCore.Tests/Metadata/Internal/InternalRelationshipBuilderTest.cs @@ -182,7 +182,7 @@ public void ForeignKey_uses_same_relationship_if_conflicting_properties_configur .HasRelationship(customerEntityBuilder.Metadata, ConfigurationSource.DataAnnotation) .HasForeignKey(new[] { Order.CustomerIdProperty, Order.CustomerUniqueProperty }, ConfigurationSource.DataAnnotation)); - Assert.Equal(1, orderEntityBuilder.Metadata.GetForeignKeys().Count()); + Assert.Single(orderEntityBuilder.Metadata.GetForeignKeys()); } [ConditionalFact] @@ -660,7 +660,7 @@ public void Can_lift_self_referencing_relationships() relationshipBuilder = relationshipBuilder.PrincipalEntityType( orderEntityBuilder.Metadata, ConfigurationSource.DataAnnotation); - Assert.Equal(1, specialOrderEntityBuilder.Metadata.GetForeignKeys().Count()); + Assert.Single(specialOrderEntityBuilder.Metadata.GetForeignKeys()); Assert.Same(specialOrderEntityBuilder.Metadata, relationshipBuilder.Metadata.DeclaringEntityType); Assert.Same(orderEntityBuilder.Metadata, relationshipBuilder.Metadata.PrincipalEntityType); Assert.Null(relationshipBuilder.Metadata.DependentToPrincipal); @@ -820,8 +820,8 @@ public void Navigation_to_principal_uses_same_relationship_if_conflicting_naviga pointsToPrincipal: true, ConfigurationSource.DataAnnotation)); - Assert.Equal(1, customerEntityBuilder.Metadata.GetForeignKeys().Count()); - Assert.Equal(0, orderEntityBuilder.Metadata.GetForeignKeys().Count()); + Assert.Single(customerEntityBuilder.Metadata.GetForeignKeys()); + Assert.Empty(orderEntityBuilder.Metadata.GetForeignKeys()); } [ConditionalFact] @@ -866,7 +866,7 @@ public void Navigation_to_dependent_uses_same_relationship_if_conflicting_naviga nameof(Customer.Orders), pointsToPrincipal: false, ConfigurationSource.DataAnnotation)); - Assert.Equal(1, orderEntityBuilder.Metadata.GetForeignKeys().Count()); + Assert.Single(orderEntityBuilder.Metadata.GetForeignKeys()); } [ConditionalFact] diff --git a/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs b/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs index 0f98b68700e..b929edacd2a 100644 --- a/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs @@ -47,8 +47,8 @@ public virtual void Can_map_derived_types_first() modelBuilder.FinalizeModel(); var model = modelBuilder.Model; - Assert.Equal(0, model.FindEntityType(typeof(ExtraSpecialBookLabel)).GetDeclaredProperties().Count()); - Assert.Equal(0, model.FindEntityType(typeof(SpecialBookLabel)).GetDeclaredProperties().Count()); + Assert.Empty(model.FindEntityType(typeof(ExtraSpecialBookLabel)).GetDeclaredProperties()); + Assert.Empty(model.FindEntityType(typeof(SpecialBookLabel)).GetDeclaredProperties()); Assert.NotNull(model.FindEntityType(typeof(SpecialBookLabel)).FindProperty(nameof(BookLabel.BookId))); } @@ -85,7 +85,7 @@ public virtual void Can_map_derived_self_ref_many_to_one() modelBuilder.FinalizeModel(); var model = modelBuilder.Model; - Assert.Equal(0, model.FindEntityType(typeof(SelfRefManyToOneDerived)).GetDeclaredProperties().Count()); + Assert.Empty(model.FindEntityType(typeof(SelfRefManyToOneDerived)).GetDeclaredProperties()); Assert.NotNull(model.FindEntityType(typeof(SelfRefManyToOne)).FindNavigation(nameof(SelfRefManyToOne.SelfRef1))); Assert.NotNull(model.FindEntityType(typeof(SelfRefManyToOne)).FindNavigation(nameof(SelfRefManyToOne.SelfRef2))); } @@ -518,7 +518,7 @@ public virtual void Index_removed_when_covered_by_an_inherited_foreign_key() c => new { c.Id }); var fk = dependentEntityType.GetForeignKeys().Single(); - Assert.Equal(1, dependentEntityType.GetIndexes().Count()); + Assert.Single(dependentEntityType.GetIndexes()); Assert.False(dependentEntityType.FindIndex(fk.Properties).IsUnique); Assert.False(derivedDependentEntityType.GetDeclaredForeignKeys().Single().IsUnique); Assert.Empty(derivedDependentEntityType.GetDeclaredIndexes()); @@ -539,7 +539,7 @@ public virtual void Index_removed_when_covered_by_an_inherited_foreign_key() derivedDependentEntityBuilder.HasBaseType(); fk = dependentEntityType.GetForeignKeys().Single(); - Assert.Equal(1, dependentEntityType.GetIndexes().Count()); + Assert.Single(dependentEntityType.GetIndexes()); Assert.False(dependentEntityType.FindIndex(fk.Properties).IsUnique); AssertEqual(initialProperties, derivedDependentEntityType.GetProperties(), new PropertyComparer(compareAnnotations: false)); diff --git a/test/EFCore.Tests/ModelBuilding/ManyToOneTestBase.cs b/test/EFCore.Tests/ModelBuilding/ManyToOneTestBase.cs index 6d474b93aef..8082fe00d4b 100644 --- a/test/EFCore.Tests/ModelBuilding/ManyToOneTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/ManyToOneTestBase.cs @@ -817,7 +817,7 @@ public virtual void Creates_both_navigations_and_overrides_existing_FK_if_unique modelBuilder.FinalizeModel(); - Assert.Equal(1, dependentType.GetForeignKeys().Count()); + Assert.Single(dependentType.GetForeignKeys()); var fk = (IForeignKey)dependentType.GetForeignKeys().Single(); Assert.False(fk.IsUnique); @@ -940,7 +940,7 @@ public virtual void Can_use_non_PK_principal() Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.NotSame(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1095,7 +1095,7 @@ public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_ Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.NotSame(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1148,7 +1148,7 @@ public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_ Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.NotSame(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1721,7 +1721,7 @@ public virtual void Creates_relationship_on_existing_FK_is_using_different_princ var fk = dependentType.GetForeignKeys().Single(foreignKey => foreignKey != existingFk); Assert.NotSame(principalKey, fk.PrincipalKey); Assert.Empty(principalType.GetIndexes()); - Assert.Equal(1, dependentType.GetIndexes().Count()); + Assert.Single(dependentType.GetIndexes()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); } diff --git a/test/EFCore.Tests/ModelBuilding/ModelBuilderGenericTest.cs b/test/EFCore.Tests/ModelBuilding/ModelBuilderGenericTest.cs index 7cb4d6dcdaf..978315e3990 100644 --- a/test/EFCore.Tests/ModelBuilding/ModelBuilderGenericTest.cs +++ b/test/EFCore.Tests/ModelBuilding/ModelBuilderGenericTest.cs @@ -71,9 +71,7 @@ public virtual void Changing_propertyInfo_updates_Property() modelBuilder.FinalizeModel(); var property = modelBuilder.Model.FindEntityType(typeof(DoubleProperty)).GetProperty("Property"); - Assert.True( - property.GetIdentifyingMemberInfo().Name - .EndsWith(typeof(IReplacable).Name + "." + nameof(IReplacable.Property))); + Assert.EndsWith(typeof(IReplacable).Name + "." + nameof(IReplacable.Property), property.GetIdentifyingMemberInfo().Name); } [ConditionalFact] @@ -86,7 +84,7 @@ public virtual void Can_add_ignore_explicit_interface_implementation_property() modelBuilder.Entity().Property(e => ((IEntityBase)e).Target); - Assert.Equal(1, modelBuilder.Model.FindEntityType(typeof(EntityBase)).GetProperties().Count()); + Assert.Single(modelBuilder.Model.FindEntityType(typeof(EntityBase)).GetProperties()); } } diff --git a/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs b/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs index cbbcb8b7e98..b4f1de0dc42 100644 --- a/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs @@ -469,7 +469,7 @@ public virtual void Ignoring_a_navigation_property_removes_discovered_entity_typ modelBuilder.FinalizeModel(); - Assert.Equal(1, model.GetEntityTypes().Count()); + Assert.Single(model.GetEntityTypes()); } [ConditionalFact] @@ -487,8 +487,8 @@ public virtual void Ignoring_a_navigation_property_removes_discovered_relationsh modelBuilder.FinalizeModel(); - Assert.Equal(0, model.GetEntityTypes().First().GetForeignKeys().Count()); - Assert.Equal(0, model.GetEntityTypes().Last().GetForeignKeys().Count()); + Assert.Empty(model.GetEntityTypes().First().GetForeignKeys()); + Assert.Empty(model.GetEntityTypes().Last().GetForeignKeys()); Assert.Equal(2, model.GetEntityTypes().Count()); } diff --git a/test/EFCore.Tests/ModelBuilding/OneToManyTestBase.cs b/test/EFCore.Tests/ModelBuilding/OneToManyTestBase.cs index 23223878549..b1ef52998ed 100644 --- a/test/EFCore.Tests/ModelBuilding/OneToManyTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/OneToManyTestBase.cs @@ -833,7 +833,7 @@ public virtual void Creates_both_navigations_and_overrides_existing_FK_when_uniq modelBuilder.FinalizeModel(); - Assert.Equal(1, dependentType.GetForeignKeys().Count()); + Assert.Single(dependentType.GetForeignKeys()); Assert.False(fk.IsUnique); Assert.Equal("BigMak", dependentType.GetNavigations().Single().Name); @@ -956,7 +956,7 @@ public virtual void Can_use_non_PK_principal() Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.NotSame(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1110,7 +1110,7 @@ public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_ Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.NotSame(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1163,7 +1163,7 @@ public virtual void Can_have_FK_by_convention_specified_with_explicit_principal_ Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.NotSame(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1215,7 +1215,7 @@ public virtual void Can_have_FK_semi_specified_with_explicit_PK() var principalKey = principalType.GetKeys().Single(); Assert.Same(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(dependentType.GetKeys().Single(), dependentType.FindPrimaryKey()); expectedPrincipalProperties.Add(fk.PrincipalKey.Properties.Single()); @@ -1423,7 +1423,7 @@ public virtual void Principal_key_by_convention_is_not_replaced_with_new_incompa var primaryPrincipalKey = principalType.FindPrimaryKey(); Assert.Same(principalProperty, primaryPrincipalKey.Properties.Single()); Assert.Equal(2, principalType.GetKeys().Count()); - Assert.True(principalType.GetKeys().Contains(fk.PrincipalKey)); + Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.Same(dependentKey, dependentType.GetKeys().SingleOrDefault()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1472,7 +1472,7 @@ public virtual void Explicit_principal_key_is_not_replaced_with_new_primary_key( var primaryPrincipalKey = principalType.FindPrimaryKey(); Assert.Same(principalProperty, primaryPrincipalKey.Properties.Single()); Assert.Equal(2, principalType.GetKeys().Count()); - Assert.True(principalType.GetKeys().Contains(nonPrimaryPrincipalKey)); + Assert.Contains(nonPrimaryPrincipalKey, principalType.GetKeys()); var oldKeyProperty = principalType.FindProperty(nameof(BigMak.Id)); var newKeyProperty = principalType.FindProperty(nameof(BigMak.AlternateKey)); Assert.False(oldKeyProperty.RequiresValueGenerator()); @@ -1949,7 +1949,7 @@ public virtual void Creates_relationship_on_existing_FK_is_using_different_princ Assert.NotSame(principalKey, fk.PrincipalKey); Assert.Equal(existingFk.Properties, fk.Properties); Assert.Empty(principalType.GetIndexes()); - Assert.Equal(1, dependentType.GetIndexes().Count()); + Assert.Single(dependentType.GetIndexes()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); } diff --git a/test/EFCore.Tests/ModelBuilding/OneToOneTestBase.cs b/test/EFCore.Tests/ModelBuilding/OneToOneTestBase.cs index 23d4d22694e..37cb45090d4 100644 --- a/test/EFCore.Tests/ModelBuilding/OneToOneTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/OneToOneTestBase.cs @@ -38,7 +38,7 @@ public virtual void Finds_existing_navigations_and_uses_associated_FK() modelBuilder.Entity().HasOne(e => e.Details).WithOne(e => e.Customer); - Assert.Equal(1, dependentType.GetForeignKeys().Count()); + Assert.Single(dependentType.GetForeignKeys()); Assert.Same(navToPrincipal, dependentType.GetNavigations().Single()); Assert.Same(navToDependent, principalType.GetNavigations().Single()); Assert.Same(fk.PrincipalKey, principalType.GetNavigations().Single().ForeignKey.PrincipalKey); @@ -173,7 +173,7 @@ public virtual void Creates_both_navigations_and_shadow_FK_if_existing_FK() Assert.Same(dependentKey, dependentType.GetKeys().Single()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); - Assert.Equal(1, dependentType.GetIndexes().Count()); + Assert.Single(dependentType.GetIndexes()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); Assert.Empty(principalType.GetIndexes()); } @@ -1192,7 +1192,7 @@ public virtual void Can_use_alternate_principal_key() Assert.Contains(fk.PrincipalKey, principalType.GetKeys()); Assert.NotSame(principalKey, fk.PrincipalKey); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); @@ -1425,7 +1425,7 @@ public virtual void Can_have_dependent_side_specified_explicitly_on_optional() var dependentKey = dependentType.GetKeys().Single(); Assert.False(fk.IsRequired); - Assert.Equal(1, dependentType.GetForeignKeys().Count()); + Assert.Single(dependentType.GetForeignKeys()); Assert.Same(navToPrincipal, dependentType.GetNavigations().Single()); Assert.Same(navToDependent, principalType.GetNavigations().Single()); Assert.Same(fk.PrincipalKey, principalType.GetNavigations().Single().ForeignKey.PrincipalKey); @@ -1480,7 +1480,7 @@ public virtual void Does_not_use_existing_FK_when_principal_key_specified() Assert.Same(dependentKey, dependentType.GetKeys().Single()); Assert.Same(principalKey, principalType.FindPrimaryKey()); Assert.Same(dependentKey, dependentType.FindPrimaryKey()); - Assert.Equal(1, dependentType.GetIndexes().Count()); + Assert.Single(dependentType.GetIndexes()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); Assert.Empty(principalType.GetIndexes()); } @@ -2669,8 +2669,8 @@ public virtual void Creates_self_referencing_FK_on_PK() Assert.Equal(nameof(SelfRef.SelfRef1), fk.DependentToPrincipal?.Name); Assert.Equal(nameof(SelfRef.SelfRef2), fk.PrincipalToDependent?.Name); Assert.Equal(2, entityType.GetNavigations().Count()); - Assert.Equal(0, fk.DeclaringEntityType.GetIndexes().Count()); - Assert.Equal(1, fk.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Empty(fk.DeclaringEntityType.GetIndexes()); + Assert.Single(fk.DeclaringEntityType.GetForeignKeys()); } [ConditionalFact] @@ -2769,7 +2769,7 @@ public virtual void Creates_self_referencing_FK_by_convention() Assert.Equal(nameof(SelfRef.SelfRef2), fk.PrincipalToDependent?.Name); Assert.Equal(nameof(SelfRef.SelfRef1), fk.DependentToPrincipal?.Name); Assert.Equal(2, entityType.GetNavigations().Count()); - Assert.Equal(1, fk.DeclaringEntityType.GetIndexes().Count()); + Assert.Single(fk.DeclaringEntityType.GetIndexes()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); } @@ -2790,7 +2790,7 @@ public virtual void Creates_self_referencing_FK_by_convention_inverted() Assert.Equal(nameof(SelfRef.SelfRef1), fk.PrincipalToDependent?.Name); Assert.Equal(nameof(SelfRef.SelfRef2), fk.DependentToPrincipal?.Name); Assert.Equal(2, entityType.GetNavigations().Count()); - Assert.Equal(1, fk.DeclaringEntityType.GetIndexes().Count()); + Assert.Single(fk.DeclaringEntityType.GetIndexes()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); } @@ -3081,7 +3081,7 @@ public virtual void Overrides_FK_if_specified_PK_count_does_not_match_separately .HasPrincipalKey(nameof(Customer.Id)).Metadata; Assert.Same(principalType.FindProperty(nameof(Customer.Id)), fk.PrincipalKey.Properties.Single()); - Assert.Equal(1, fk.Properties.Count()); + Assert.Single(fk.Properties); } [ConditionalFact] @@ -3193,7 +3193,7 @@ public virtual void Creates_relationship_on_existing_FK_if_using_different_princ var fk = dependentType.GetForeignKeys().Single(foreignKey => foreignKey != existingFk); Assert.NotSame(principalKey, fk.PrincipalKey); Assert.Empty(principalType.GetIndexes()); - Assert.Equal(1, dependentType.GetIndexes().Count()); + Assert.Single(dependentType.GetIndexes()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); Assert.Empty(principalType.GetIndexes()); } @@ -3230,7 +3230,7 @@ public virtual void Creates_index_even_if_covered_by_an_alternate_key() modelBuilder.Entity().Ignore(t => t.BurgerId2); - Assert.Equal(1, dependentType.GetKeys().Count()); + Assert.Single(dependentType.GetKeys()); Assert.Equal(dependentType.GetForeignKeys().Count(), dependentType.GetIndexes().Count()); Assert.True(fk.DeclaringEntityType.FindIndex(fk.Properties).IsUnique); Assert.Empty(principalType.GetIndexes()); diff --git a/test/EFCore.Tests/ModelBuilding/OwnedTypesTestBase.cs b/test/EFCore.Tests/ModelBuilding/OwnedTypesTestBase.cs index 765ad3181d0..b39d3ff0daf 100644 --- a/test/EFCore.Tests/ModelBuilding/OwnedTypesTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/OwnedTypesTestBase.cs @@ -42,7 +42,7 @@ public virtual void Can_configure_owned_type() Assert.Equal("CustomerAlternateKey", ownership.Properties.Single().Name); Assert.Equal(nameof(Customer.AlternateKey), ownership.PrincipalKey.Properties.Single().Name); var owned = ownership.DeclaringEntityType; - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); Assert.Equal(nameof(CustomerDetails.CustomerId), owned.GetIndexes().Single().Properties.Single().Name); Assert.Equal( new[] { "CustomerAlternateKey", nameof(CustomerDetails.CustomerId), nameof(CustomerDetails.Id) }, @@ -67,7 +67,7 @@ public virtual void Can_configure_owned_type_using_nested_closure() var owned = ownership.DeclaringEntityType; Assert.True(ownership.IsOwnership); Assert.Equal("bar", owned.FindAnnotation("foo").Value); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); } [ConditionalFact] @@ -92,7 +92,7 @@ public virtual void Can_configure_owned_type_inverse() Assert.Equal(nameof(CustomerDetails.Customer), ownership.DependentToPrincipal.Name); Assert.Same(ownee, ownership.DeclaringEntityType); Assert.Equal(nameof(CustomerDetails.CustomerId), ownee.FindPrimaryKey().Properties.Single().Name); - Assert.Equal(1, ownership.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(ownership.DeclaringEntityType.GetForeignKeys()); } [ConditionalFact] @@ -152,7 +152,7 @@ public virtual void Can_configure_ownership_foreign_key() var ownership = model.FindEntityType(typeof(Customer)).FindNavigation(nameof(Customer.Details)).ForeignKey; Assert.Equal(nameof(CustomerDetails.Id), ownership.Properties.Single().Name); Assert.Equal(nameof(CustomerDetails.Id), ownership.DeclaringEntityType.FindPrimaryKey().Properties.Single().Name); - Assert.Equal(1, ownership.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(ownership.DeclaringEntityType.GetForeignKeys()); } [ConditionalFact] @@ -173,8 +173,8 @@ public virtual void Can_configure_multiple_ownerships() Assert.Equal(typeof(CustomerDetails), ownership2.DeclaringEntityType.ClrType); Assert.NotSame(ownership1.DeclaringEntityType, ownership2.DeclaringEntityType); Assert.Equal(2, model.GetEntityTypes().Count(e => e.ClrType == typeof(CustomerDetails))); - Assert.Equal(1, ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, ownership2.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(ownership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(ownership2.DeclaringEntityType.GetForeignKeys()); } [ConditionalFact] @@ -240,7 +240,7 @@ public virtual void Can_configure_owned_type_collection_from_an_owned_type() Assert.Equal(nameof(Order.Customer), chainedOwnership.DependentToPrincipal.Name); Assert.Equal(nameof(Order.CustomerId), chainedOwnership.Properties.Single().Name); Assert.Equal(nameof(Order.OrderId), chainedOwned.FindPrimaryKey().Properties.Single().Name); - Assert.Equal(1, chainedOwned.GetForeignKeys().Count()); + Assert.Single(chainedOwned.GetForeignKeys()); Assert.Equal(nameof(Order.CustomerId), chainedOwned.GetIndexes().Single().Properties.Single().Name); Assert.Same(entityBuilder.OwnedEntityType, chainedOwned); @@ -289,8 +289,8 @@ public virtual void Can_configure_owned_type_collection() Assert.NotNull(model.FindEntityType(typeof(Order))); Assert.Equal(1, model.GetEntityTypes().Count(e => e.ClrType == typeof(Order))); - Assert.Equal(1, owned.GetForeignKeys().Count()); - Assert.Equal(1, owned.GetNavigations().Count()); + Assert.Single(owned.GetForeignKeys()); + Assert.Single(owned.GetNavigations()); } [ConditionalFact] @@ -322,7 +322,7 @@ public virtual void Can_configure_owned_type_collection_using_nested_closure() Assert.True(ownership.IsOwnership); Assert.Equal("DifferentCustomerId", ownership.Properties.Single().Name); Assert.Equal("bar", owned.FindAnnotation("foo").Value); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); Assert.Equal("Id", owned.FindPrimaryKey().Properties.Single().Name); Assert.Equal(2, owned.GetIndexes().Count()); Assert.Equal(nameof(Order.AnotherCustomerId), owned.GetIndexes().First().Properties.Single().Name); @@ -379,7 +379,7 @@ public virtual void Can_configure_one_to_one_relationship_from_an_owned_type_col Assert.Equal(2, model.GetEntityTypes().Count(e => e.ClrType == typeof(Order))); Assert.Equal(2, ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, ownership2.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(ownership2.DeclaringEntityType.GetForeignKeys()); Assert.Null(model.FindEntityType(typeof(SpecialOrder))); } @@ -404,7 +404,7 @@ public virtual void Can_configure_owned_type_from_an_owned_type_collection() var ownership = model.FindEntityType(typeof(Customer)).FindNavigation(nameof(Customer.Orders)).ForeignKey; var owned = ownership.DeclaringEntityType; Assert.Equal(nameof(Order.CustomerId), ownership.Properties.Single().Name); - Assert.Equal(1, ownership.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(ownership.DeclaringEntityType.GetForeignKeys()); var chainedOwnership = owned.FindNavigation(nameof(Order.Details)).ForeignKey; var chainedOwned = chainedOwnership.DeclaringEntityType; Assert.True(chainedOwnership.IsOwnership); @@ -439,7 +439,7 @@ public virtual void Can_chain_owned_type_collection_configurations() var ownership = model.FindEntityType(typeof(Customer)).FindNavigation(nameof(Customer.Orders)).ForeignKey; var owned = ownership.DeclaringEntityType; - Assert.Equal(1, ownership.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(ownership.DeclaringEntityType.GetForeignKeys()); var seedData = owned.GetSeedData().Single(); Assert.Equal(-2, seedData[nameof(Order.OrderId)]); Assert.Equal(-1, seedData[nameof(Order.CustomerId)]); @@ -479,11 +479,11 @@ public virtual void Can_configure_owned_type_collection_without_explicit_key() Assert.True(ownership.IsOwnership); Assert.Equal(nameof(Order.Customer), ownership.DependentToPrincipal.Name); Assert.Equal(nameof(Order.CustomerId), ownership.Properties.Single().Name); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); var pk = owned.FindPrimaryKey(); Assert.Equal(new[] { nameof(Order.CustomerId), nameof(Order.OrderId) }, pk.Properties.Select(p => p.Name)); Assert.Equal(ValueGenerated.OnAdd, pk.Properties.Last().ValueGenerated); - Assert.Equal(0, owned.GetIndexes().Count()); + Assert.Empty(owned.GetIndexes()); var chainedOwnership = owned.FindNavigation(nameof(Order.Products)).ForeignKey; var chainedOwned = chainedOwnership.DeclaringEntityType; @@ -494,7 +494,7 @@ public virtual void Can_configure_owned_type_collection_without_explicit_key() var chainedPk = chainedOwned.FindPrimaryKey(); Assert.Equal(new[] { "OrderCustomerId", "OrderId", nameof(Product.Id) }, chainedPk.Properties.Select(p => p.Name)); Assert.Equal(ValueGenerated.OnAdd, chainedPk.Properties.Last().ValueGenerated); - Assert.Equal(0, chainedOwned.GetIndexes().Count()); + Assert.Empty(chainedOwned.GetIndexes()); Assert.Equal(4, model.GetEntityTypes().Count()); } @@ -524,11 +524,11 @@ public virtual void Can_configure_owned_type_collection_without_explicit_key_or_ Assert.False(ownership.IsUnique); Assert.Equal(nameof(Order.Customer), ownership.DependentToPrincipal.Name); Assert.Equal(nameof(Order.CustomerId), ownership.Properties.Single().Name); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); var pk = owned.FindPrimaryKey(); Assert.Equal(new[] { nameof(Order.CustomerId), "Id" }, pk.Properties.Select(p => p.Name)); Assert.Equal(ValueGenerated.OnAdd, pk.Properties.Last().ValueGenerated); - Assert.Equal(0, owned.GetIndexes().Count()); + Assert.Empty(owned.GetIndexes()); var chainedOwnership = owned.FindNavigation(nameof(Order.Products)).ForeignKey; var chainedOwned = chainedOwnership.DeclaringEntityType; @@ -539,7 +539,7 @@ public virtual void Can_configure_owned_type_collection_without_explicit_key_or_ var chainedPk = chainedOwned.FindPrimaryKey(); Assert.Equal(new[] { "OrderCustomerId", "OrderId", "Id1" }, chainedPk.Properties.Select(p => p.Name)); Assert.Equal(ValueGenerated.OnAdd, chainedPk.Properties.Last().ValueGenerated); - Assert.Equal(0, chainedOwned.GetIndexes().Count()); + Assert.Empty(chainedOwned.GetIndexes()); Assert.Equal(4, model.GetEntityTypes().Count()); } @@ -725,7 +725,7 @@ public virtual void Can_map_base_of_owned_type() Assert.Null(owned.BaseType); Assert.NotNull(model.FindEntityType(typeof(CustomerDetails))); Assert.Equal(1, model.GetEntityTypes().Count(e => e.ClrType == typeof(CustomerDetails))); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); } [ConditionalFact] @@ -747,7 +747,7 @@ public virtual void Can_map_base_of_owned_type_first() Assert.Null(owned.BaseType); Assert.NotNull(model.FindEntityType(typeof(CustomerDetails))); Assert.Equal(1, model.GetEntityTypes().Count(e => e.ClrType == typeof(CustomerDetails))); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); } [ConditionalFact] @@ -770,7 +770,7 @@ public virtual void Can_map_derived_of_owned_type() return targetType != typeof(DetailsBase) && typeof(DetailsBase).IsAssignableFrom(targetType); }); Assert.Empty(navigationsToDerived); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); Assert.Equal(1, model.GetEntityTypes().Count(e => e.ClrType == typeof(DetailsBase))); Assert.Same(owned, model.FindEntityType(typeof(CustomerDetails)).BaseType); @@ -797,7 +797,7 @@ public virtual void Can_map_derived_of_owned_type_first() var targetType = n.GetTargetType().ClrType; return targetType != typeof(DetailsBase) && typeof(DetailsBase).IsAssignableFrom(targetType); })); - Assert.Equal(1, owned.GetForeignKeys().Count()); + Assert.Single(owned.GetForeignKeys()); Assert.Equal(1, model.GetEntityTypes().Count(e => e.ClrType == typeof(DetailsBase))); Assert.Same(owned, model.FindEntityType(typeof(CustomerDetails)).BaseType); @@ -1028,8 +1028,8 @@ protected virtual void VerifyOwnedBookLabelModel(IMutableModel model) var bookOwnership2 = model.FindEntityType(typeof(Book)).FindNavigation(nameof(Book.AlternateLabel)).ForeignKey; Assert.NotSame(bookOwnership1.DeclaringEntityType, bookOwnership2.DeclaringEntityType); - Assert.Equal(1, bookOwnership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookOwnership1.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(bookOwnership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookOwnership1.DeclaringEntityType.GetForeignKeys()); Assert.Null(bookOwnership1.DependentToPrincipal); Assert.Null(bookOwnership2.DependentToPrincipal); @@ -1058,14 +1058,14 @@ protected virtual void VerifyOwnedBookLabelModel(IMutableModel model) Assert.NotSame(bookLabel1Ownership1.DeclaringEntityType, bookLabel2Ownership1.DeclaringEntityType); Assert.NotSame(bookLabel1Ownership2.DeclaringEntityType, bookLabel2Ownership2.DeclaringEntityType); - Assert.Equal(1, bookLabel1Ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel1Ownership2.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership1.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership2.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel1Ownership1Subownership.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel1Ownership2Subownership.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership1Subownership.DeclaringEntityType.GetForeignKeys().Count()); - Assert.Equal(1, bookLabel2Ownership2Subownership.DeclaringEntityType.GetForeignKeys().Count()); + Assert.Single(bookLabel1Ownership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel1Ownership2.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership1.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership2.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel1Ownership1Subownership.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel1Ownership2Subownership.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership1Subownership.DeclaringEntityType.GetForeignKeys()); + Assert.Single(bookLabel2Ownership2Subownership.DeclaringEntityType.GetForeignKeys()); Assert.Equal(nameof(SpecialBookLabel.AnotherBookLabel), bookLabel1Ownership1Subownership.DependentToPrincipal.Name); Assert.Equal(nameof(AnotherBookLabel.SpecialBookLabel), bookLabel1Ownership2Subownership.DependentToPrincipal.Name); Assert.Equal(nameof(SpecialBookLabel.AnotherBookLabel), bookLabel2Ownership1Subownership.DependentToPrincipal.Name); diff --git a/test/EFCore.Tests/ServiceProviderCacheTest.cs b/test/EFCore.Tests/ServiceProviderCacheTest.cs index a6f5f16f580..9102e657a82 100644 --- a/test/EFCore.Tests/ServiceProviderCacheTest.cs +++ b/test/EFCore.Tests/ServiceProviderCacheTest.cs @@ -28,7 +28,7 @@ public void Returns_same_provider_for_same_type_of_configured_extensions() Assert.Same(cache.GetOrAdd(config1, true), cache.GetOrAdd(config2, true)); - Assert.Equal(1, loggerFactory.Log.Count); + Assert.Single(loggerFactory.Log); Assert.Equal( CoreResources.LogServiceProviderCreated(new TestLogger()).GenerateMessage(), @@ -84,7 +84,7 @@ public void Returns_same_provider_for_same_type_of_configured_extensions_and_rep Assert.Same(cache.GetOrAdd(config1, true), cache.GetOrAdd(config2, true)); - Assert.Equal(1, loggerFactory.Log.Count); + Assert.Single(loggerFactory.Log); Assert.Equal( CoreResources.LogServiceProviderCreated(new TestLogger()).GenerateMessage(), diff --git a/test/EFCore.Tests/Storage/ValueComparerTest.cs b/test/EFCore.Tests/Storage/ValueComparerTest.cs index 4de8839c0a6..029c5f6147d 100644 --- a/test/EFCore.Tests/Storage/ValueComparerTest.cs +++ b/test/EFCore.Tests/Storage/ValueComparerTest.cs @@ -229,7 +229,7 @@ private static bool InternalEquals(JustAClassWithEqualityOperators left, JustACl => !InternalEquals(left, right); } - public void GenericCompareTest(T value1, T value2, int? hashCode = null) + private void GenericCompareTest(T value1, T value2, int? hashCode = null) { var comparer = new ValueComparer(false); var equals = comparer.EqualsExpression.Compile(); diff --git a/test/EFCore.Tests/Storage/ValueConverterTest.cs b/test/EFCore.Tests/Storage/ValueConverterTest.cs index d6d29bc86c1..6be6947fe05 100644 --- a/test/EFCore.Tests/Storage/ValueConverterTest.cs +++ b/test/EFCore.Tests/Storage/ValueConverterTest.cs @@ -289,7 +289,9 @@ public void Cannot_compose_converters_with_mismatched_types() () => _enumToNumber.ComposeWith(_uIntToInt)).Message); } +#pragma warning disable xUnit1013 // Public method should be marked as test public static void OrderingTest( +#pragma warning restore xUnit1013 // Public method should be marked as test ValueConverter converter, params TModel[] values) { @@ -304,7 +306,9 @@ public void Cannot_compose_converters_with_mismatched_types() .ToArray()); } +#pragma warning disable xUnit1013 // Public method should be marked as test public static void OrderingTest( +#pragma warning restore xUnit1013 // Public method should be marked as test ValueConverter converter, params TModel[] values) { diff --git a/test/EFCore.Tests/Utilities/MultigraphTest.cs b/test/EFCore.Tests/Utilities/MultigraphTest.cs index 2fa0dd4abd5..f8516d48144 100644 --- a/test/EFCore.Tests/Utilities/MultigraphTest.cs +++ b/test/EFCore.Tests/Utilities/MultigraphTest.cs @@ -140,7 +140,7 @@ public void AddEdge_adds_an_edge() Assert.Equal(2, graph.Edges.Count()); Assert.Equal(2, graph.Edges.Intersect(new[] { edgeOne, edgeTwo }).Count()); - Assert.Equal(0, graph.GetEdges(vertexTwo, vertexOne).Count()); + Assert.Empty(graph.GetEdges(vertexTwo, vertexOne)); Assert.Equal(2, graph.GetEdges(vertexOne, vertexTwo).Count()); Assert.Equal(2, graph.GetEdges(vertexOne, vertexTwo).Intersect(new[] { edgeOne, edgeTwo }).Count()); } @@ -180,7 +180,7 @@ public void AddEdges_adds_multiple_edges() graph.AddEdges(vertexOne, vertexTwo, new[] { edgeOne }); graph.AddEdges(vertexOne, vertexTwo, new[] { edgeTwo, edgeThree }); - Assert.Equal(0, graph.GetEdges(vertexTwo, vertexOne).Count()); + Assert.Empty(graph.GetEdges(vertexTwo, vertexOne)); Assert.Equal(3, graph.GetEdges(vertexOne, vertexTwo).Count()); Assert.Equal(3, graph.GetEdges(vertexOne, vertexTwo).Intersect(new[] { edgeOne, edgeTwo, edgeThree }).Count()); } diff --git a/test/EFCore.Tests/Utilities/TypeExtensionsTest.cs b/test/EFCore.Tests/Utilities/TypeExtensionsTest.cs index 38aafbbdefb..f6e910616fa 100644 --- a/test/EFCore.Tests/Utilities/TypeExtensionsTest.cs +++ b/test/EFCore.Tests/Utilities/TypeExtensionsTest.cs @@ -69,7 +69,7 @@ public void GetDeclaredConstructor_finds_ctor_no_args() var constructorInfo = typeof(CtorFixture).GetDeclaredConstructor(null); Assert.NotNull(constructorInfo); - Assert.Equal(0, constructorInfo.GetParameters().Length); + Assert.Empty(constructorInfo.GetParameters()); } [ConditionalFact] @@ -84,7 +84,7 @@ public void GetDeclaredConstructor_finds_ctor_args() var constructorInfo = typeof(CtorFixture).GetDeclaredConstructor(new[] { typeof(int) }); Assert.NotNull(constructorInfo); - Assert.Equal(1, constructorInfo.GetParameters().Length); + Assert.Single(constructorInfo.GetParameters()); } [ConditionalFact] @@ -361,9 +361,9 @@ private class Role2014 : IRole2014 public void GetBaseTypes_return_all_base_types() { Assert.Equal(3, typeof(MultipleHierarchy).GetBaseTypes().Count()); - Assert.True(typeof(MultipleHierarchy).GetBaseTypes().Contains(typeof(Some))); - Assert.True(typeof(MultipleHierarchy).GetBaseTypes().Contains(typeof(Base))); - Assert.True(typeof(MultipleHierarchy).GetBaseTypes().Contains(typeof(object))); + Assert.Contains(typeof(Some), typeof(MultipleHierarchy).GetBaseTypes()); + Assert.Contains(typeof(Base), typeof(MultipleHierarchy).GetBaseTypes()); + Assert.Contains(typeof(object), typeof(MultipleHierarchy).GetBaseTypes()); } [ConditionalFact] diff --git a/test/Microsoft.Data.Sqlite.Tests/SqliteBlobTest.cs b/test/Microsoft.Data.Sqlite.Tests/SqliteBlobTest.cs index c98e355f2ad..2cbe720a867 100644 --- a/test/Microsoft.Data.Sqlite.Tests/SqliteBlobTest.cs +++ b/test/Microsoft.Data.Sqlite.Tests/SqliteBlobTest.cs @@ -258,11 +258,10 @@ public void Read_throws_when_disposed() } [Theory] - [InlineData(0, 1, -1, SeekOrigin.Begin)] - [InlineData(0, 1, -2, SeekOrigin.Current)] - [InlineData(0, 1, -3, SeekOrigin.End)] + [InlineData(1, -1, SeekOrigin.Begin)] + [InlineData(1, -2, SeekOrigin.Current)] + [InlineData(1, -3, SeekOrigin.End)] public void Seek_throws_when_negative( - long expected, long initialPosition, long offset, SeekOrigin origin)