comparison UnitTests/Linq/BatchTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using BLToolkit.Data;
3 using BLToolkit.Data.Linq;
4 using BLToolkit.DataAccess;
5 using BLToolkit.Mapping;
6
7 using Data.Linq;
8 using Data.Linq.Model;
9
10 using NUnit.Framework;
11
12 namespace Update
13 {
14 [TestFixture]
15 public class BatchTest : TestBase
16 {
17 [Test]
18 public void Transaction([DataContexts(ExcludeLinqService = true)] string context)
19 {
20 using (var db = new TestDbManager(context))
21 {
22 var list = new[]
23 {
24 new Parent { ParentID = 1111, Value1 = 1111 },
25 new Parent { ParentID = 2111, Value1 = 2111 },
26 new Parent { ParentID = 3111, Value1 = 3111 },
27 new Parent { ParentID = 4111, Value1 = 4111 },
28 };
29
30 foreach (var parent in list)
31 db.Parent.Delete(p => p.ParentID == parent.ParentID);
32
33 db.BeginTransaction();
34 db.InsertBatch(list);
35 db.CommitTransaction();
36
37 foreach (var parent in list)
38 db.Parent.Delete(p => p.ParentID == parent.ParentID);
39 }
40 }
41
42 [Test]
43 public void NoTransaction([DataContexts(ExcludeLinqService=true)] string context)
44 {
45 using (var db = new TestDbManager(context))
46 {
47 var list = new[]
48 {
49 new Parent { ParentID = 1111, Value1 = 1111 },
50 new Parent { ParentID = 2111, Value1 = 2111 },
51 new Parent { ParentID = 3111, Value1 = 3111 },
52 new Parent { ParentID = 4111, Value1 = 4111 },
53 };
54
55 foreach (var parent in list)
56 db.Parent.Delete(p => p.ParentID == parent.ParentID);
57
58 db.InsertBatch(list);
59
60 foreach (var parent in list)
61 db.Parent.Delete(p => p.ParentID == parent.ParentID);
62 }
63 }
64
65 [TableName(Database="KanoonIr", Name="Area")]
66 public class Area
67 {
68 [ PrimaryKey(1)] public int AreaCode { get; set; }
69 public string AreaName { get; set; }
70 public int StateCode { get; set; }
71 [ PrimaryKey(2)] public int CityCode { get; set; }
72 public string Address { get; set; }
73 public string Tels { get; set; }
74 [Nullable ] public string WebSite { get; set; }
75 public bool IsActive { get; set; }
76 }
77
78 [Test, ExpectedException(typeof(InvalidOperationException), ExpectedMessage="Cannot access destination table '[KanoonIr]..[Area]'.")]
79 public void Issue260([IncludeDataContexts("Sql2005")] string context)
80 {
81 using (var db = GetDataContext(context))
82 {
83 ((DbManager)db).InsertBatch(new[] { new Area { AreaCode = 1 } });
84 }
85 }
86 }
87 }