comparison HowTo/DataAccess/Update.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
3 using NUnit.Framework;
4
5 using BLToolkit.Data;
6 using BLToolkit.DataAccess;
7 using BLToolkit.Mapping;
8
9 namespace HowTo.DataAccess
10 {
11 [TestFixture]
12 public class Update
13 {
14 int _id;
15
16 [TestFixtureSetUp]
17 public void Insert()
18 {
19 using (DbManager db = new DbManager())
20 {
21 _id = db
22 .SetCommand(@"
23 INSERT INTO Person (
24 FirstName, LastName, Gender
25 ) VALUES (
26 @FirstName, @LastName, @Gender
27 )
28 SELECT Cast(SCOPE_IDENTITY() as int)",
29 db.Parameter("@FirstName", "Crazy"),
30 db.Parameter("@LastName", "Frog"),
31 db.Parameter("@Gender", Map.EnumToValue(Gender.Unknown)))
32 .ExecuteScalar<int>();
33 }
34 }
35
36 [Test]
37 public void Test1()
38 {
39 /*[a]*/SprocQuery<Person> query = new SprocQuery<Person>()/*[/a]*/;
40
41 Person person = query.SelectByKey(_id);
42
43 person.Gender = Gender.Other;
44
45 query./*[a]*/Update(person)/*[/a]*/;
46 }
47
48 [Test]
49 public void Test2()
50 {
51 using (DbManager db = new DbManager())
52 {
53 /*[a]*/SprocQuery<Person> query = new SprocQuery<Person>()/*[/a]*/;
54
55 Person person = query.SelectByKey(db, _id);
56
57 person.Gender = Gender.Other;
58
59 query./*[a]*/Update(db, person)/*[/a]*/;
60 }
61 }
62
63 [TestFixtureTearDown]
64 public void Delete()
65 {
66 using (DbManager db = new DbManager())
67 {
68 db
69 .SetCommand("DELETE FROM Person WHERE PersonID = @id",
70 db.Parameter("@id", _id))
71 .ExecuteNonQuery();
72 }
73 }
74 }
75 }
76