Repository: dotnet/efcore
File: test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs (C#)

Code before:
        => WriteOriginalValuesTest(trackFromQuery, CreateFieldPubWithRecords);

    [ConditionalTheory, InlineData(EntityState.Added, false), InlineData(EntityState.Added, true), InlineData(EntityState.Unchanged, false),
     InlineData(EntityState.Unchanged, true), InlineData(EntityState.Modified, false), InlineData(EntityState.Modified, true),
     InlineData(EntityState.Deleted, false), InlineData(EntityState.Deleted, true)]
    public virtual Task Can_track_entity_with_complex_type_collections(EntityState state, bool async)
        => TrackAndSaveTest(state, async, CreatePubWithCollections);

    [ConditionalTheory, InlineData(false), InlineData(true)]
    public virtual void Can_mark_complex_type_collection_properties_modified(bool trackFromQuery)
        => MarkModifiedTest(trackFromQuery, CreatePubWithCollections);

    [ConditionalTheory, InlineData(false), InlineData(true)]
    public virtual void Can_read_original_values_for_properties_of_complex_type_collections(bool trackFromQuery)
        => ReadOriginalValuesTest(trackFromQuery, CreatePubWithCollections);

    [ConditionalTheory, InlineData(false), InlineData(true)]
    public virtual void Can_write_original_values_for_properties_of_complex_type_collections(bool trackFromQuery)
        => WriteOriginalValuesTest(trackFromQuery, CreatePubWithCollections);

    [ConditionalTheory]
    [InlineData(EntityState.Unchanged, false)]
    [InlineData(EntityState.Unchanged, true)]
    [InlineData(EntityState.Modified, false)]
    [InlineData(EntityState.Modified, true)]
    public virtual async Task Can_change_state_from_Deleted_with_complex_collection(EntityState newState, bool async)
    {
        await ExecuteWithStrategyInTransactionAsync(
            async context =>
            {
                var pub = CreatePubWithCollections(context);
                context.Add(pub);
                _ = async ? await context.SaveChangesAsync() : context.SaveChanges();
            },
            async context =>
            {
                var pub = async
                    ? await context.Set<PubWithCollections>().Where(p => p.Name == "The FBI").FirstAsync()
                    : context.Set<PubWithCollections>().Where(p => p.Name == "The FBI").First();
                var entry = context.Entry(pub);

                // Set to Deleted state (soft delete pattern)
                entry.State = EntityState.Deleted;
                Assert.Equal(EntityState.Deleted, entry.State);

                // Change to target state - this should not throw an exception
                entry.State = newState;
                Assert.Equal(newState, entry.State);

                // Verify the complex collection is still accessible
                var activitiesEntry = entry.ComplexCollection(e => e.Activities);

Review comment (bug):
@copilot Extract a common method that takes a createPub delegate and call it from different test theories with different Create*Pub* methods, mark the ones failing as skipped

Code after:
    public virtual void Can_write_original_values_for_properties_of_record_complex_types_with_fields(bool trackFromQuery)
        => WriteOriginalValuesTest(trackFromQuery, CreateFieldPubWithRecords);

    [ConditionalTheory, InlineData(EntityState.Added, false), InlineData(EntityState.Added, true), InlineData(EntityState.Unchanged, false),
     InlineData(EntityState.Unchanged, true), InlineData(EntityState.Modified, false), InlineData(EntityState.Modified, true),
     InlineData(EntityState.Deleted, false), InlineData(EntityState.Deleted, true)]
    public virtual Task Can_track_entity_with_complex_type_collections(EntityState state, bool async)
        => TrackAndSaveTest(state, async, CreatePubWithCollections);

    [ConditionalTheory, InlineData(false), InlineData(true)]
    public virtual void Can_mark_complex_type_collection_properties_modified(bool trackFromQuery)
        => MarkModifiedTest(trackFromQuery, CreatePubWithCollections);

    [ConditionalTheory, InlineData(false), InlineData(true)]
    public virtual void Can_read_original_values_for_properties_of_complex_type_collections(bool trackFromQuery)
        => ReadOriginalValuesTest(trackFromQuery, CreatePubWithCollections);

    [ConditionalTheory, InlineData(false), InlineData(true)]
    public virtual void Can_write_original_values_for_properties_of_complex_type_collections(bool trackFromQuery)
        => WriteOriginalValuesTest(trackFromQuery, CreatePubWithCollections);

    [ConditionalTheory]
    [InlineData(EntityState.Unchanged, false)]
    [InlineData(EntityState.Unchanged, true)]
    [InlineData(EntityState.Modified, false)]
    [InlineData(EntityState.Modified, true)]
    public virtual Task Can_change_state_from_Deleted_with_complex_collection(EntityState newState, bool async)
        => ChangeStateFromDeletedTest(newState, async, CreatePubWithCollections);

    [ConditionalTheory(Skip = "Issue #31411")]
    [InlineData(EntityState.Unchanged, false)]
    [InlineData(EntityState.Unchanged, true)]
    [InlineData(EntityState.Modified, false)]
    [InlineData(EntityState.Modified, true)]
    public virtual Task Can_change_state_from_Deleted_with_complex_struct_collection(EntityState newState, bool async)
        => ChangeStateFromDeletedTest(newState, async, CreatePubWithStructCollections);

    [ConditionalTheory(Skip = "Issue #31621")]
    [InlineData(EntityState.Unchanged, false)]
    [InlineData(EntityState.Unchanged, true)]
    [InlineData(EntityState.Modified, false)]
    [InlineData(EntityState.Modified, true)]
    public virtual Task Can_change_state_from_Deleted_with_complex_readonly_struct_collection(EntityState newState, bool async)
        => ChangeStateFromDeletedTest(newState, async, CreatePubWithReadonlyStructCollections);

    [ConditionalTheory]
    [InlineData(EntityState.Unchanged, false)]
    [InlineData(EntityState.Unchanged, true)]
    [InlineData(EntityState.Modified, false)]
    [InlineData(EntityState.Modified, true)]
    public virtual Task Can_change_state_from_Deleted_with_complex_record_collection(EntityState newState, bool async)