Skip to content

Commit 303ac4d

Browse files
committed
Handle MySQL particularity in tests
1 parent 157d1c9 commit 303ac4d

1 file changed

Lines changed: 73 additions & 13 deletions

File tree

Orm/Xtensive.Orm.Tests/Issues/Issue0676_NonNullableReferenceBug.cs

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ namespace Xtensive.Orm.Tests.Issues
127127
[TestFixture]
128128
public class Issue0676_NonNullableReferenceBug : AutoBuildTest
129129
{
130-
private const string VersionFieldName = "Version";
131-
132130
protected override DomainConfiguration BuildConfiguration()
133131
{
134132
var configuration = base.BuildConfiguration();
@@ -139,21 +137,26 @@ protected override DomainConfiguration BuildConfiguration()
139137
[Test]
140138
public void StandardTest()
141139
{
140+
Require.ProviderIsNot(StorageProvider.MySql,
141+
@"Self-reference requires ability to temporary set nulls to non-nullable column and later update it to some value.
142+
MySQL doesn't allow this and we don't have a work-around implemented");
143+
142144
using (var session = Domain.OpenSession()) {
143-
var tAnimal = session.Domain.Model.Types[typeof (Animal)];
145+
var tAnimal = session.Domain.Model.Types[typeof(Animal)];
144146
var fMate = tAnimal.Fields["Mate"];
145-
Assert.AreEqual(OnRemoveAction.None, fMate.GetAssociation(tAnimal).OnOwnerRemove);
146-
Assert.AreEqual(OnRemoveAction.None, fMate.GetAssociation(tAnimal).OnTargetRemove);
147+
var fMateAssociation = fMate.GetAssociation(tAnimal);
148+
Assert.AreEqual(OnRemoveAction.None, fMateAssociation.OnOwnerRemove);
149+
Assert.AreEqual(OnRemoveAction.None, fMateAssociation.OnTargetRemove);
147150
var fMateDenyRemove = tAnimal.Fields["MateDenyRemove"];
148-
Assert.AreEqual(OnRemoveAction.None, fMateDenyRemove.GetAssociation(tAnimal).OnOwnerRemove);
149-
Assert.AreEqual(OnRemoveAction.Deny, fMateDenyRemove.GetAssociation(tAnimal).OnTargetRemove);
151+
var fMateDenyRemoveAssociation = fMateDenyRemove.GetAssociation(tAnimal);
152+
Assert.AreEqual(OnRemoveAction.None, fMateDenyRemoveAssociation.OnOwnerRemove);
153+
Assert.AreEqual(OnRemoveAction.Deny, fMateDenyRemoveAssociation.OnTargetRemove);
150154

151-
Animal a,b;
155+
Animal a, b;
152156
Key aKey;
153-
using (var tx = session.OpenTransaction())
154-
{
157+
using (var tx = session.OpenTransaction()) {
155158
a = new Animal("A");
156-
b = new Animal("B") {Mate = a, MateDenyRemove = a};
159+
b = new Animal("B") { Mate = a, MateDenyRemove = a };
157160
aKey = a.Key;
158161
AssertEx.Throws<ReferentialIntegrityException>(a.Remove);
159162
b.MateDenyRemove = b;
@@ -170,15 +173,51 @@ public void StandardTest()
170173
}
171174
}
172175

176+
[Test]
177+
public void StandardMysqlTest()
178+
{
179+
Require.ProviderIs(StorageProvider.MySql,
180+
@"Self-reference requires ability to temporary set nulls to non-nullable column and later update it to some value.
181+
MySQL doesn't allow this and we don't have a work-around implemented");
182+
183+
using (var session = Domain.OpenSession()) {
184+
var tAnimal = session.Domain.Model.Types[typeof(Animal)];
185+
var fMate = tAnimal.Fields["Mate"];
186+
var fMateAssociation = fMate.GetAssociation(tAnimal);
187+
Assert.AreEqual(OnRemoveAction.None, fMateAssociation.OnOwnerRemove);
188+
Assert.AreEqual(OnRemoveAction.None, fMateAssociation.OnTargetRemove);
189+
var fMateDenyRemove = tAnimal.Fields["MateDenyRemove"];
190+
var fMateDenyRemoveAssociation = fMateDenyRemove.GetAssociation(tAnimal);
191+
Assert.AreEqual(OnRemoveAction.None, fMateDenyRemoveAssociation.OnOwnerRemove);
192+
Assert.AreEqual(OnRemoveAction.Deny, fMateDenyRemoveAssociation.OnTargetRemove);
193+
194+
Animal a, b;
195+
Key aKey;
196+
using (var tx = session.OpenTransaction()) {
197+
a = new Animal("A");
198+
b = new Animal("B") { Mate = a, MateDenyRemove = a };
199+
aKey = a.Key;
200+
201+
// cannot insert NULL to non-nullable column
202+
_ = Assert.Throws<StorageException>(() => session.SaveChanges());
203+
}
204+
}
205+
}
206+
173207
[Test]
174208
public void HasNullEntityTest()
175209
{
210+
Require.ProviderIsNot(StorageProvider.MySql,
211+
@"Self-reference requires ability to temporary set nulls to non-nullable column and later update it to some value.
212+
MySQL doesn't allow this and we don't have a work-around implemented");
213+
176214
using (var session = Domain.OpenSession())
177215
using (var tx = session.OpenTransaction()) {
178216
var tPerson = session.Domain.Model.Types[typeof(Person)];
179217
var fMate = tPerson.Fields["Mate"];
180-
Assert.AreEqual(OnRemoveAction.None, fMate.GetAssociation(tPerson).OnOwnerRemove);
181-
Assert.AreEqual(OnRemoveAction.Clear, fMate.GetAssociation(tPerson).OnTargetRemove);
218+
var fMateAssociation = fMate.GetAssociation(tPerson);
219+
Assert.AreEqual(OnRemoveAction.None, fMateAssociation.OnOwnerRemove);
220+
Assert.AreEqual(OnRemoveAction.Clear, fMateAssociation.OnTargetRemove);
182221

183222
var nullPerson = new Person(Person.NullName);
184223
Assert.AreSame(nullPerson, Person.Null);
@@ -189,5 +228,26 @@ public void HasNullEntityTest()
189228
Assert.AreSame(nullPerson, b.Mate);
190229
}
191230
}
231+
232+
[Test]
233+
public void HasNullEntityMysqlTest()
234+
{
235+
Require.ProviderIs(StorageProvider.MySql,
236+
@"Self-reference requires ability to temporary set nulls to non-nullable column and later update it to some value.
237+
MySQL doesn't allow this and we don't have a work-around implemented");
238+
239+
using (var session = Domain.OpenSession())
240+
using (var tx = session.OpenTransaction()) {
241+
var tPerson = session.Domain.Model.Types[typeof(Person)];
242+
var fMate = tPerson.Fields["Mate"];
243+
var fMateAssociation = fMate.GetAssociation(tPerson);
244+
Assert.AreEqual(OnRemoveAction.None, fMateAssociation.OnOwnerRemove);
245+
Assert.AreEqual(OnRemoveAction.Clear, fMateAssociation.OnTargetRemove);
246+
247+
var nullPerson = new Person(Person.NullName);
248+
// cannot insert NULL to non-nullable column
249+
_ = Assert.Throws<StorageException>(() => session.SaveChanges());
250+
}
251+
}
192252
}
193253
}

0 commit comments

Comments
 (0)