Author: marisic.net
(2009/01/27 22:02) About 3 years ago
2
3
using System;
4
using System.Web;
5
using Microsoft.Practices.Unity;
6
using PostSharp.Laos;
7
using Repository.NHibernateDataAccess.Conversation;
8
19
public string Phone { get; set; }
20
public string Salutation { get; set; }
21
public string JobTitle { get; set; }
22
public DateTime? HireDate { get; set; }
}
23
24
26
/// </summary>
27
public void Start()
28
{
29
if (Session != null)
if (Session != null && (Session.IsOpen || Session.IsConnected))
30
31
Abort();
32
...
40
public void Pause()
41
42
Commit(Session);
43
44
45
46
/// <summary>
51
if (Session == null)
50
52
Start();
53
54
55
throw new AccessViolationException("Session could not be created");
56
57
if (!Session.IsConnected)
return _conversation.Session.CreateCriteria(typeof(Territory)).List<Territory>();
void IEmployeeDataProvider.Save(Employee employee)
47
_conversation.Session.SaveOrUpdate(employee);
48
49
#endregion
13
Employee GetEmployee(int id);
14
void AddEmployee(Employee employee);
15
IList<Territory> GetTerritories();
16
void Save(Employee employee);
17
18
[Test]
public void AddEmployee()
var employee = new Employee
// Address = new Address {City = "Harrisburg", CountryRegionName = "USA", PostalCode = "17104", StateProvinceName = "PA", AddressLine1 = "123 Fake st"},
58
// BirthDate = new DateTime(1984, 6, 26),
59
FirstName = "Chris",
60
LastName = "Marisic",
61
//HireDate = DateTime.Now,
62
JobTitle = ".NET Master",
63
//Phone = "717-123-4568",
64
Salutation = "Mr."
65
};
66
_provider.AddEmployee(employee);
67
68
Assert.IsTrue(employee.Id > 0);
69
70
71
76
77
78
[BusinessConversation]
79
public void GetEmployees()
public void BusinessConversationTest()
80
81
const int id = 9;
82
var employee = _provider.GetEmployee(id);
employee.LastName = employee.FirstName + employee.LastName;
_provider.Save(employee);
83
72
84
Assert.IsNotNull(employee);
73
85
//Assert.IsTrue(employee.Id.HasValue);
74
94
95
Assert.IsTrue(territories.Count > 0);
96
Assert.IsFalse(string.IsNullOrEmpty(territories[0].Id));
86
87
var employee2= new Employee
88
89
90
91
92
93
HireDate = DateTime.Now,
97
98
_provider.AddEmployee(employee2);
99
100
101
102
103
using Microsoft.Practices.Unity;public string Phone { get; set; }public string Phone { get; set; }public string Salutation { get; set; }public string Salutation { get; set; }public string JobTitle { get; set; }public string JobTitle { get; set; }public DateTime? HireDate { get; set; }{{if (Session != null && (Session.IsOpen || Session.IsConnected)){{{{if (Session == null)throw new AccessViolationException("Session could not be created");throw new AccessViolationException("Session could not be created");{{{var employee = new Employee{// Address = new Address {City = "Harrisburg", CountryRegionName = "USA", PostalCode = "17104", StateProvinceName = "PA", AddressLine1 = "123 Fake st"},// BirthDate = new DateTime(1984, 6, 26),FirstName = "Chris",LastName = "Marisic",//HireDate = DateTime.Now,JobTitle = ".NET Master",//Phone = "717-123-4568",Salutation = "Mr."};_provider.AddEmployee(employee);Assert.IsTrue(employee.Id > 0);public void GetEmployees()public void BusinessConversationTest(){{{// Address = new Address {City = "Harrisburg", CountryRegionName = "USA", PostalCode = "17104", StateProvinceName = "PA", AddressLine1 = "123 Fake st"},