0
|
1 using System;
|
|
2
|
|
3 using NUnit.Framework;
|
|
4
|
|
5 using BLToolkit.DataAccess;
|
|
6
|
|
7 namespace HowTo.DataAccess
|
|
8 {
|
|
9 [TestFixture]
|
|
10 public class ExecuteScalar
|
|
11 {
|
|
12 public abstract class /*[a]*/PersonAccessor/*[/a]*/ : /*[a]*/DataAccessor/*[/a]*/<Person>
|
|
13 {
|
|
14 [SqlQuery("SELECT Count(*) FROM Person")]
|
|
15 public abstract int GetCount();
|
|
16
|
|
17 // The Person_Insert sproc returns an id of the created record.
|
|
18 //
|
|
19 [SprocName("Person_Insert")]
|
|
20 public abstract /*[a]*/int/*[/a]*/ Insert(Person person);
|
|
21 }
|
|
22
|
|
23 [Test]
|
|
24 public void Test()
|
|
25 {
|
|
26 PersonAccessor pa = DataAccessor.CreateInstance<PersonAccessor>();
|
|
27
|
|
28 // ExecuteScalar.
|
|
29 //
|
|
30 Assert.IsTrue(pa.GetCount() > 0);
|
|
31
|
|
32 // Insert and get id.
|
|
33 //
|
|
34 Person person = new Person();
|
|
35
|
|
36 person.FirstName = "Crazy";
|
|
37 person.LastName = "Frog";
|
|
38 person.Gender = Gender.Unknown;
|
|
39
|
|
40 int id = pa./*[a]*/Insert(person)/*[/a]*/;
|
|
41
|
|
42 Assert.IsFalse(id == 0);
|
|
43
|
|
44 new SprocQuery<Person>().DeleteByKey(id);
|
|
45 }
|
|
46 }
|
|
47 }
|