Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/SIL.LCModel/DomainImpl/OverridesLing_Lex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,17 @@ internal override void RegisterVirtualsModifiedForObjectDeletion(IUnitOfWorkServ
Cache.ServiceLocator.GetInstance<Virtuals>().LexDbEntries,
() => cache.ServiceLocator.GetInstance<ILexEntryRepository>().AllInstances(),
new ILexEntry[0], new[] { this });
// Remove all the virtual ordering objects that refer to this entry.
UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Undo Remove Entry VOs",
"Redo Remove Entry VOs",
Cache.ActionHandlerAccessor,
() =>
{
var virtualOrderingObjects = Cache.ServiceLocator
.GetInstance<IVirtualOrderingRepository>().AllInstances().Where(vo => vo.SourceRA == this);
foreach (var vo in virtualOrderingObjects)
vo.Delete();
});
base.RegisterVirtualsModifiedForObjectDeletion(uow);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/SIL.LCModel.Tests/DomainImpl/LexEntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,39 @@ public void MorphBundleRefsFixedWhenSenseMovedToNewEntry()
Assert.That(mbBankStream.MorphRA, Is.EqualTo(newEntry.AlternateFormsOS[1]), "The morph for the stream analysis should be the new allomorph");
}

/// <summary>
/// Test that a virtual ordering is removed the entry that owns it is deleted
/// </summary>
[Test]
public void VerifyVirtualOrderingRemoved()
{
ILexEntry kick = null;
ILexEntry bucket = null;
ILexEntry kickBucket = null;
UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
() =>
{
kick = MakeEntryWithForm("kick");
bucket = MakeEntryWithForm("bucket");
kickBucket = MakeEntryWithForm("kick the bucket");
kickBucket.AddComponent(kick);
kickBucket.AddComponent(bucket);
var vof = Cache.ServiceLocator.GetInstance<IVirtualOrderingFactory>();
vof.Create(kick, "VisibleComplexFormBackRefs", new []{bucket, kickBucket});
});
var entryRef = kickBucket.EntryRefsOS[0];
Assert.That(entryRef.PrimaryLexemesRS[0], Is.EqualTo(kick));
var vos = Cache.ServiceLocator.GetInstance<IVirtualOrderingRepository>();
Assert.That(vos.Count, Is.EqualTo(1));
UndoableUnitOfWorkHelper.Do("doit", "undoit", Cache.ActionHandlerAccessor,
() =>
{
kick.Delete();
});
Cache.ServiceLocator.GetInstance<IVirtualOrderingRepository>();
Assert.That(vos.Count, Is.EqualTo(0));
}

/// <summary>
/// Ensure references are corrected when moving a sense between two existing entries
/// </summary>
Expand Down
Loading