Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,56 +2014,6 @@ public virtual void Throws_when_accessing_complex_entries_using_incorrect_cardin
Assert.Throws<InvalidOperationException>(() => entry.ComplexCollection(e => (IList<Team>)e.FeaturedTeam)).Message);
}

[ConditionalTheory]
[InlineData(false)]
[InlineData(true)]
public virtual async Task Can_null_complex_property_with_default_values_and_multiple_properties(bool async)
{
await ExecuteWithStrategyInTransactionAsync(
async context =>
{
var entity = Fixture.UseProxies
? context.CreateProxy<EntityWithOptionalMultiPropComplex>()
: new EntityWithOptionalMultiPropComplex();

entity.Id = Guid.NewGuid();
// Set the complex property with default values
entity.ComplexProp = new MultiPropComplex
{
IntValue = 0,
BoolValue = false,
DateValue = default,
};

_ = async ? await context.AddAsync(entity) : context.Add(entity);
_ = async ? await context.SaveChangesAsync() : context.SaveChanges();

Assert.NotNull(entity.ComplexProp);
},
async context =>
{
var entity = async
? await context.Set<EntityWithOptionalMultiPropComplex>().SingleAsync()
: context.Set<EntityWithOptionalMultiPropComplex>().Single();

Assert.NotNull(entity.ComplexProp);

entity.ComplexProp = null;

_ = async ? await context.SaveChangesAsync() : context.SaveChanges();

Assert.Null(entity.ComplexProp);
},
async context =>
{
var entity = async
? await context.Set<EntityWithOptionalMultiPropComplex>().SingleAsync()
: context.Set<EntityWithOptionalMultiPropComplex>().Single();

Assert.Null(entity.ComplexProp);
});
}

protected void AssertPropertyValues(EntityEntry entry)
{
Assert.Equal("The FBI", entry.Property("Name").CurrentValue);
Expand Down Expand Up @@ -4653,6 +4603,56 @@ await ExecuteWithStrategyInTransactionAsync(
});
}

[ConditionalTheory]
[InlineData(false)]
[InlineData(true)]
public virtual async Task Can_null_complex_property_with_default_values_and_multiple_properties(bool async)
{
await ExecuteWithStrategyInTransactionAsync(
async context =>
{
var entity = Fixture.UseProxies
? context.CreateProxy<EntityWithOptionalMultiPropComplex>()
: new EntityWithOptionalMultiPropComplex();

entity.Id = Guid.NewGuid();
// Set the complex property with default values
entity.ComplexProp = new MultiPropComplex
{
IntValue = 0,
BoolValue = false,
DateValue = default,
};

_ = async ? await context.AddAsync(entity) : context.Add(entity);
_ = async ? await context.SaveChangesAsync() : context.SaveChanges();

Assert.NotNull(entity.ComplexProp);
},
async context =>
{
var entity = async
? await context.Set<EntityWithOptionalMultiPropComplex>().SingleAsync()
: context.Set<EntityWithOptionalMultiPropComplex>().Single();

Assert.NotNull(entity.ComplexProp);

entity.ComplexProp = null;

_ = async ? await context.SaveChangesAsync() : context.SaveChanges();

Assert.Null(entity.ComplexProp);
},
async context =>
{
var entity = async
? await context.Set<EntityWithOptionalMultiPropComplex>().SingleAsync()
: context.Set<EntityWithOptionalMultiPropComplex>().Single();

Assert.Null(entity.ComplexProp);
});
}

public class EntityWithOptionalMultiPropComplex
{
public virtual Guid Id { get; set; }
Expand Down
Loading