Skip to content

Commit

Permalink
Fix combining cascades
Browse files Browse the repository at this point in the history
Fixes #472

+semver:fix
  • Loading branch information
hazzik committed Oct 9, 2020
1 parent 3b66ce6 commit e4c6e16
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public void CascadeSetsModelCascadePropertyToValue()
.ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
}

[Test]
public void CascadeAppendModelCascadePropertyToValue()
{
Any<SecondMappedObject>()
.Mapping(m => m
.IdentityType<int>()
.EntityIdentifierColumn("col")
.EntityTypeColumn("col2")
.Cascade.Merge().Cascade.SaveUpdate())
.ModelShouldMatch(x => x.Cascade.ShouldEqual("merge,save-update"));
}

[Test]
public void IdentityTypeSetsModelIdTypePropertyToPropertyTypeName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public void DefaultCascadeShouldSetModelDefaultCascadePropertyToValue()
.ModelShouldMatch(x => x.DefaultCascade.ShouldEqual("all"));
}

[Test]
public void DefaultCascadeShouldAppendModelDefaultCascadePropertyToValue()
{
HibernateMapping()
.Mapping(m => { m.DefaultCascade.Merge(); m.DefaultCascade.SaveUpdate(); })
.ModelShouldMatch(x => x.DefaultCascade.ShouldEqual("merge,save-update"));
}

[Test]
public void DefaultLazyShouldSetModelDefaultLazyPropertyToTrue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public void CascadeShouldSetModelCascadePropertyToValue()
.ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
}

[Test]
public void CascadeShouldAppendModelCascadePropertyToValue()
{
ManyToMany(x => x.BagOfChildren)
.Mapping(m => { m.Cascade.SaveUpdate(); m.Cascade.Merge(); })
.ModelShouldMatch(x => x.Cascade.ShouldEqual("save-update,merge"));
}

[Test]
public void CollectionTypeShouldSetModelCollectionTypePropertyToValue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,37 @@ public void ClassShouldSetModelClassPropertyToValue()
}

[Test]
public void CascadeShouldSetModelCascadePropertyToTrue()
public void ConstrainedShouldSetModelConstrainedPropertyToTrue()
{
OneToOne()
.Mapping(m => m.Constrained())
.ModelShouldMatch(x => x.Constrained.ShouldBeTrue());
}

[Test]
public void NotCascadeShouldSetModelCascadePropertyToFalse()
public void NotConstrainedShouldSetModelConstrainedPropertyToFalse()
{
OneToOne()
.Mapping(m => m.Not.Constrained())
.ModelShouldMatch(x => x.Constrained.ShouldBeFalse());
}

[Test]
public void CascadeSetsModelCascadePropertyToValue()
{
OneToOne()
.Mapping(m => m.Cascade.All())
.ModelShouldMatch(x => x.Cascade.ShouldEqual("all"));
}

[Test]
public void CascadeAppendModelCascadePropertyToValue()
{
OneToOne()
.Mapping(m => { m.Cascade.Merge(); m.Cascade.SaveUpdate(); })
.ModelShouldMatch(x => x.Cascade.ShouldEqual("merge,save-update"));
}

[Test]
public void FetchShouldSetModelFetchPropertyToValue()
{
Expand Down
6 changes: 5 additions & 1 deletion src/FluentNHibernate/Mapping/AnyPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public AnyPart(Type entity, Member member)
this.entity = entity;
this.member = member;
access = new AccessStrategyBuilder<AnyPart<T>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
cascade = new CascadeExpression<AnyPart<T>>(this, value => attributes.Set("Cascade", Layer.UserSupplied, value));
cascade = new CascadeExpression<AnyPart<T>>(this, value =>
{
var current = attributes.Get("Cascade") as string;
attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
});

SetDefaultAccess();
}
Expand Down
6 changes: 5 additions & 1 deletion src/FluentNHibernate/Mapping/HibernateMappingPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public class HibernateMappingPart : IHibernateMappingProvider

public HibernateMappingPart()
{
defaultCascade = new CascadeExpression<HibernateMappingPart>(this, value => attributes.Set("DefaultCascade", Layer.UserSupplied, value));
defaultCascade = new CascadeExpression<HibernateMappingPart>(this, value =>
{
var current = attributes.Get("DefaultCascade") as string;
attributes.Set("DefaultCascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
});
defaultAccess = new AccessStrategyBuilder<HibernateMappingPart>(this, value => attributes.Set("DefaultAccess", Layer.UserSupplied, value));
}

Expand Down
8 changes: 1 addition & 7 deletions src/FluentNHibernate/Mapping/OneToManyPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class OneToManyPart<TChild> : ToManyBase<OneToManyPart<TChild>, TChild>
{
private readonly Type entity;
private readonly ColumnMappingCollection<OneToManyPart<TChild>> keyColumns;
private readonly CollectionCascadeExpression<OneToManyPart<TChild>> cascade;
private readonly NotFoundExpression<OneToManyPart<TChild>> notFound;
private IndexManyToManyPart manyToManyIndex;
private readonly Type childType;
Expand All @@ -31,11 +30,6 @@ protected OneToManyPart(Type entity, Member member, Type collectionType)
childType = collectionType;

keyColumns = new ColumnMappingCollection<OneToManyPart<TChild>>(this);
cascade = new CollectionCascadeExpression<OneToManyPart<TChild>>(this, value =>
{
var current = collectionAttributes.Get("Cascade") as string;
collectionAttributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
});
notFound = new NotFoundExpression<OneToManyPart<TChild>>(this, value => relationshipAttributes.Set("NotFound", Layer.UserSupplied, value));

collectionAttributes.Set("Name", Layer.Defaults, member.Name);
Expand All @@ -54,7 +48,7 @@ public NotFoundExpression<OneToManyPart<TChild>> NotFound
/// </summary>
public new CollectionCascadeExpression<OneToManyPart<TChild>> Cascade
{
get { return cascade; }
get { return base.Cascade; }
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/FluentNHibernate/Mapping/OneToOnePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public OneToOnePart(Type entity, Member member)
{
access = new AccessStrategyBuilder<OneToOnePart<TOther>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
fetch = new FetchTypeExpression<OneToOnePart<TOther>>(this, value => attributes.Set("Fetch", Layer.UserSupplied, value));
cascade = new CascadeExpression<OneToOnePart<TOther>>(this, value => attributes.Set("Cascade", Layer.UserSupplied, value));
cascade = new CascadeExpression<OneToOnePart<TOther>>(this, value =>
{
var current = attributes.Get("Cascade") as string;
attributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
});
this.entity = entity;
this.member = member;

Expand Down
6 changes: 5 additions & 1 deletion src/FluentNHibernate/Mapping/ToManyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ protected ToManyBase(Type entity, Member member, Type type)
AsBag();
access = new AccessStrategyBuilder<T>((T)this, value => collectionAttributes.Set("Access", Layer.UserSupplied, value));
fetch = new FetchTypeExpression<T>((T)this, value => collectionAttributes.Set("Fetch", Layer.UserSupplied, value));
cascade = new CollectionCascadeExpression<T>((T)this, value => collectionAttributes.Set("Cascade", Layer.UserSupplied, value));
cascade = new CollectionCascadeExpression<T>((T)this, value =>
{
var current = collectionAttributes.Get("Cascade") as string;
collectionAttributes.Set("Cascade", Layer.UserSupplied, current == null ? value : string.Format("{0},{1}", current, value));
});

SetDefaultCollectionType();
SetCustomCollectionType(type);
Expand Down

0 comments on commit e4c6e16

Please sign in to comment.