Repository: dotnet/efcore
File: test/EFCore.SqlServer.FunctionalTests/ComplexTypesTrackingSqlServerTest.cs (C#)

Code before:
﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore;

public class ComplexTypesTrackingSqlServerTest(
    ComplexTypesTrackingSqlServerTest.SqlServerFixture fixture,
    ITestOutputHelper testOutputHelper)
    : ComplexTypesTrackingSqlServerTestBase<ComplexTypesTrackingSqlServerTest.SqlServerFixture>(fixture, testOutputHelper)
{
    [ConditionalFact]
    public virtual async Task Can_change_state_from_Deleted_to_Unchanged_with_complex_collection()
    {
        await ExecuteWithStrategyInTransactionAsync(
            async context =>
            {
                var pub = CreatePubWithCollections(context);
                context.Add(pub);
                await context.SaveChangesAsync();
            },
            async context =>
            {
                var pub = await context.Set<PubWithCollections>().Where(p => p.Name == "The FBI").FirstAsync();
                var entry = context.Entry(pub);

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

                // Change to Unchanged state to allow soft delete logic
                // This should not throw an exception
                entry.State = EntityState.Unchanged;
                Assert.Equal(EntityState.Unchanged, entry.State);

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

Review comment (refactor):
@copilot Move this and Can_change_state_from_Deleted_to_Modified_with_complex_collection to ComplexTypesTrackingTestBase and make is a single Theory, follow the pattern of tests in ComplexTypesTrackingTestBase to test against different classes

Code after:
﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore;

public class ComplexTypesTrackingSqlServerTest(
    ComplexTypesTrackingSqlServerTest.SqlServerFixture fixture,
    ITestOutputHelper testOutputHelper)
    : ComplexTypesTrackingSqlServerTestBase<ComplexTypesTrackingSqlServerTest.SqlServerFixture>(fixture, testOutputHelper)
{
    public class SqlServerFixture : SqlServerFixtureBase
    {
        protected override string StoreName
            => nameof(ComplexTypesTrackingSqlServerTest);
    }
}

public class ComplexTypesTrackingProxiesSqlServerTest(
    ComplexTypesTrackingProxiesSqlServerTest.SqlServerFixture fixture,
    ITestOutputHelper testOutputHelper)
    : ComplexTypesTrackingSqlServerTestBase<ComplexTypesTrackingProxiesSqlServerTest.SqlServerFixture>(fixture, testOutputHelper)
{
    // Fields can't be proxied
    public override Task Can_track_entity_with_complex_objects_with_fields(EntityState state, bool async)
        => Task.CompletedTask;

    // Fields can't be proxied
    public override void Can_mark_complex_type_properties_modified_with_fields(bool trackFromQuery)
    {
    }

    // Fields can't be proxied
    public override void Can_read_original_values_for_properties_of_complex_types_with_fields(bool trackFromQuery)
    {
    }

    // Fields can't be proxied