Skip to content

Commit 2fcf88e

Browse files
committed
Add dedicated test for double statement delimiter
1 parent ebde0b7 commit 2fcf88e

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using Xtensive.Orm.Configuration;
7+
using Xtensive.Orm.Model;
8+
using Xtensive.Orm.Tests.Issues.MysqlStrangeDoubleSemicolumnInCommandIssueModel;
9+
10+
namespace Xtensive.Orm.Tests.Issues.MysqlStrangeDoubleSemicolumnInCommandIssueModel
11+
{
12+
[HierarchyRoot(InheritanceSchema.ClassTable)]
13+
public class Product : Entity
14+
{
15+
[Field, Key]
16+
public long Id { get; set; }
17+
18+
[Field]
19+
public string Name { get; set; }
20+
21+
[Field]
22+
public DateTime CreationDate { get; set; }
23+
24+
[Field]
25+
public Guid UIndentifier { get; set; }
26+
27+
public Product(Session session)
28+
: base(session)
29+
{
30+
}
31+
}
32+
33+
public class DerivedProduct : Product
34+
{
35+
[Field]
36+
public TimeSpan TimeSpan { get; set; }
37+
38+
public DerivedProduct(Session session)
39+
: base(session)
40+
{
41+
}
42+
}
43+
}
44+
45+
namespace Xtensive.Orm.Tests.Issues
46+
{
47+
public sealed class MysqlStrangeDoubleSemicolumnInCommandIssue : AutoBuildTest
48+
{
49+
protected override void CheckRequirements() => Require.ProviderIs(StorageProvider.MySql);
50+
51+
protected override DomainConfiguration BuildConfiguration()
52+
{
53+
var config = base.BuildConfiguration();
54+
config.Types.Register(typeof(Product));
55+
config.Types.Register(typeof(DerivedProduct));
56+
config.UpgradeMode = DomainUpgradeMode.Recreate;
57+
58+
return config;
59+
}
60+
61+
[Test]
62+
public void BatchingTest()
63+
{
64+
using (var session = Domain.OpenSession()) {
65+
session.Events.DbCommandExecuting += BatchingHandler;
66+
using (var transaction = session.OpenTransaction()) {
67+
var product = new Product(session) {
68+
Name = "BatchingTestProduct",
69+
CreationDate = DateTime.UtcNow,
70+
UIndentifier = Guid.NewGuid(),
71+
};
72+
73+
var dProduct = new DerivedProduct(session) {
74+
Name = "BatchingTestDerivedProduct",
75+
CreationDate = DateTime.UtcNow,
76+
UIndentifier = Guid.NewGuid(),
77+
TimeSpan = TimeSpan.FromDays(3)
78+
};
79+
session.SaveChanges(); // split persist and transaction commit
80+
transaction.Complete();
81+
}
82+
session.Events.DbCommandExecuting -= BatchingHandler;
83+
84+
using (var transaction = session.OpenTransaction()) {
85+
var allProducts = session.Query.All<Product>().ToList();
86+
Assert.That(allProducts.Count, Is.EqualTo(2));
87+
88+
var derivedProducts = session.Query.All<DerivedProduct>().ToList();
89+
Assert.That(derivedProducts.Count, Is.EqualTo(1));
90+
}
91+
}
92+
}
93+
94+
private void BatchingHandler(object sender, DbCommandEventArgs e)
95+
{
96+
var commandText = e.Command.CommandText;
97+
if (commandText.Contains("INSERT")) {
98+
var firstInsertIdx = commandText.IndexOf("INSERT", StringComparison.OrdinalIgnoreCase);
99+
var lastInsertIdx = commandText.LastIndexOf("INSERT", StringComparison.OrdinalIgnoreCase);
100+
if (firstInsertIdx == lastInsertIdx) {
101+
throw new Exception("No batching happened");
102+
}
103+
Assert.That(commandText.Contains(";;"), Is.False, $"Command = {commandText}");
104+
}
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)