Skip to content

Commit 80a3b58

Browse files
Regenerate async.
1 parent 5d10b90 commit 80a3b58

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using NHibernate.Cfg.MappingSchema;
12+
using NHibernate.Mapping.ByCode;
13+
using NUnit.Framework;
14+
15+
namespace NHibernate.Test.NHSpecificTest.GH1413
16+
{
17+
using System.Threading.Tasks;
18+
using System.Threading;
19+
[TestFixture]
20+
public class ByCodeFixtureAsync : TestCaseMappingByCode
21+
{
22+
private int _parentId;
23+
24+
protected override HbmMapping GetMappings()
25+
{
26+
var mapper = new ModelMapper();
27+
mapper.Class<EntityParent>(rc =>
28+
{
29+
rc.Id(x => x.Id, m => m.Generator(Generators.Native));
30+
rc.Property(x => x.Name);
31+
rc.Bag(x => x.Children, m =>
32+
{
33+
m.Cascade(Mapping.ByCode.Cascade.All);
34+
m.Inverse(true);
35+
}, a => a.OneToMany()
36+
);
37+
});
38+
39+
mapper.Class<EntityChild>(rc =>
40+
{
41+
rc.Id(x => x.Id, m => m.Generator(Generators.Native));
42+
rc.Property(x => x.Name);
43+
});
44+
45+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
46+
}
47+
48+
protected override void OnSetUp()
49+
{
50+
using (ISession session = OpenSession())
51+
using (ITransaction transaction = session.BeginTransaction())
52+
{
53+
var parent = new EntityParent
54+
{
55+
Name = "InitialParent",
56+
};
57+
session.Save(parent);
58+
59+
session.Flush();
60+
transaction.Commit();
61+
_parentId = parent.Id;
62+
}
63+
}
64+
65+
protected override void OnTearDown()
66+
{
67+
using (ISession session = OpenSession())
68+
using (ITransaction transaction = session.BeginTransaction())
69+
{
70+
session.Delete("from System.Object");
71+
72+
session.Flush();
73+
transaction.Commit();
74+
}
75+
}
76+
77+
[Test]
78+
public async Task SessionIsDirtyShouldNotTriggerCascadeSavingAsync()
79+
{
80+
Sfi.Statistics.IsStatisticsEnabled = true;
81+
using (ISession session = OpenSession())
82+
using (session.BeginTransaction())
83+
{
84+
var parent = await (GetParentAsync(session));
85+
var entityChild = new EntityChild
86+
{
87+
Name = "NewListElem"
88+
};
89+
90+
//parent.Children is cascaded
91+
parent.Children.Add(entityChild);
92+
93+
Sfi.Statistics.Clear();
94+
var isDirty = await (session.IsDirtyAsync());
95+
96+
Assert.That(Sfi.Statistics.EntityInsertCount, Is.EqualTo(0), "Dirty has triggered an insert");
97+
Assert.That(
98+
entityChild.Id,
99+
Is.EqualTo(0),
100+
"Transient objects should not be saved by ISession.IsDirty() call (expected 0 as Id)");
101+
Assert.That(isDirty, "ISession.IsDirty() call should return true.");
102+
}
103+
}
104+
105+
private Task<EntityParent> GetParentAsync(ISession session, CancellationToken cancellationToken = default(CancellationToken))
106+
{
107+
return session.GetAsync<EntityParent>(_parentId, cancellationToken);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)