Skip to content

Commit ffc8a79

Browse files
github-actions[bot]ValResnick
authored andcommitted
Generate async files
1 parent 5ecf1d6 commit ffc8a79

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/NHibernate.Test/Async/FetchLazyProperties/FetchLazyPropertiesFixture.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,41 @@ void AssertPersons(List<Person> results, bool fetched)
10861086
}
10871087
}
10881088
}
1089+
1090+
[Test]
1091+
public async Task TestRefreshRemovesLazyLoadedPropertiesAsync()
1092+
{
1093+
using (var outerSession = OpenSession())
1094+
{
1095+
const string query = "from Person fetch Image where Id = 1";
1096+
const string namePostFix = "_MODIFIED";
1097+
const int imageLength = 4711;
1098+
1099+
Person outerPerson = await (outerSession.CreateQuery(query).UniqueResultAsync<Person>());
1100+
1101+
Assert.That(outerPerson.Name.EndsWith(namePostFix), Is.False); // Normal property
1102+
Assert.That(outerPerson.Image.Length, Is.EqualTo(1)); // Lazy Property
1103+
1104+
// Changing the properties of the person in a different sessions
1105+
using (var innerSession = OpenSession())
1106+
{
1107+
var transaction = innerSession.BeginTransaction();
1108+
1109+
Person innerPerson = await (innerSession.CreateQuery(query).UniqueResultAsync<Person>());
1110+
innerPerson.Image = new byte[imageLength];
1111+
innerPerson.Name += namePostFix;
1112+
await (innerSession.UpdateAsync(innerPerson));
1113+
1114+
await (transaction.CommitAsync());
1115+
}
1116+
1117+
// Refreshing the person in the outer session
1118+
await (outerSession.RefreshAsync(outerPerson));
1119+
1120+
Assert.That(outerPerson.Name.EndsWith(namePostFix), Is.True); // Value has changed
1121+
Assert.That(outerPerson.Image.Length, Is.EqualTo(imageLength)); // This is still the old value
1122+
}
1123+
}
10891124

10901125
private static Person GeneratePerson(int i, Person bestFriend)
10911126
{

src/NHibernate/Async/Event/Default/DefaultRefreshEventListener.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ public virtual async Task OnRefreshAsync(RefreshEvent @event, IDictionary refres
115115
}
116116

117117
await (EvictCachedCollectionsAsync(persister, id, source.Factory, cancellationToken)).ConfigureAwait(false);
118-
118+
119+
RefreshLazyProperties(persister, obj);
120+
119121
// NH Different behavior : NH-1601
120122
// At this point the entity need the real refresh, all elementes of collections are Refreshed,
121123
// the collection state was evicted, but the PersistentCollection (in the entity state)

0 commit comments

Comments
 (0)