Author: marisic.net
(2009/02/15 21:44) Almost 3 years ago
66
break;
67
case ConversationMode.Rollback:
68
conversation.Abort();
69
70
default:
71
throw new ArgumentOutOfRangeException();
72
}
1
#region Using Statements
2
3
using System;
4
using System.Diagnostics;
5
6
#endregion
7
namespace StructuredWeb.Domain.Business
8
{
9
10
[Serializable]
11
[DebuggerDisplay("Id = {Id}, Name = {Name}, Description = {Description}")]
public class Category
12
13
public int Id { get; set; }
14
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StructuredWeb.Domain.Business.Component
[DebuggerDisplay("FirstName = {FirstName}, LastName = {LastName}")]
public class Person
public string FirstName { get; set; }
public string LastName { get; set; }
15
16
17
using Iesi.Collections.Generic;
using StructuredWeb.Domain.Business.Component;
namespace StructuredWeb.Domain.Business
[DebuggerDisplay("Id = {Id}, CustomerDesc = {CustomerDesc}")]
public class CustomerDemographic
public string Id { get; set; }
[DebuggerDisplay("Id = {Id}, Customer = {Customer.Person.LastName}, Employee = {Employee.Person.LastName}")]
public class Order
private Address _address;
[DebuggerDisplay("Id = {Id}, ProductName = {ProductName}, Discontinued = {Discontinued}")]
public class Product
[DebuggerDisplay("Id = {Id}, CompanyName = {CompanyName}, Phone = {Phone}")]
public class Shipper
[DebuggerDisplay("Id = {Id}, CompanyName = {CompanyName}, ContactName = {ContactName}")]
public class Supplier
[DebuggerDisplay("Id = {Id}, Description = {Description}")]
[DebuggerDisplay("Id = {Id}, Description = {Description}, Region = {Region}")]
public class Territory
m.LazyLoad();
};
73
74
)
75
.ForTypesThatDeriveFrom<Employee>(autoMap =>
76
77
autoMap.Map(p => p.JobTitle, "Title");
using StructuredWeb.Domain.Business;
using StructuredWeb.Repository.NHibernateDataAccess.Conversation;
using StructuredWeb.Repository.NHibernateDataAccess.Providers.Interfaces;
using Order = NHibernate.Criterion.Order;
using Order=NHibernate.Criterion.Order;
...
61
62
IList<Territory> IEmployeeDataProvider.GetTerritories()
63
64
return _conversation.Session.CreateCriteria(typeof(Territory)).List<Territory>();
return _conversation.Session.CreateCriteria(typeof (Territory)).List<Territory>();
65
36
37
38
39
/// These are the methods that return the physical boolean out of the extension method
40
41
#region Public Boolean Methods
42
43
/// <summary>
94
92
95
93
96
97
/// These are the methods that do the actual lifting
98
99
#region Private Static Methods
100
101
135
131
136
132
137
133
134
138
139
id = id.Substring(0, 5);
var customer = new Customer
Id = id,
//Address = "address1",
//City = "city",
CompanyName = "company",
ContactName = "Maria Anders",
ContactTitle = "hi",
//Country = "America",
Fax = "123-234-4456",
Phone = "123-444-5555",
//PostalCode = "12345"
_provider.Add(customer);
78
79
Assert.AreEqual(id, customer.Id);
</a>
</td>
<td>
<%# Eval("FirstName")%>
<%# Eval("Person.FirstName")%>
<%# Eval("LastName")%>
<%# Eval("Person.LastName")%>
<%# Eval("JobTitle")%>
using System.Web.UI;
using StructuredWeb.Modules.EmployeeManagement.View;
using StructureMap;
namespace StructuredWeb
public partial class _Default : Page, IEmployeeView
public partial class _Default : ViewBasePage<EmployeePresenter, IEmployeeView>, IEmployeeView
private EmployeePresenter _presenter;
18
19
public EmployeePresenter Presenter
20
21
get
22
23
if (_presenter == null)
24
25
ObjectFactory.BuildUp(this);
26
27
28
return _presenter;
29
30
set
31
32
_presenter = value;
33
_presenter.View = this;
34
35
protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
Presenter.OnViewInitialized();
_presenter.OnViewInitialized();
44
Presenter.OnViewLoaded();
_presenter.OnViewLoaded();
45
Page.DataBind();
46
47
//------------------------------------------------------------------------------
namespace StructuredWeb {
public partial class _Default {
public partial class _Default
/// Head1 control.
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="ViewBasePage.cs">
<SubType>ASPXCodeBehind</SubType>
</ItemGroup>
<ItemGroup>
80
<Content Include="Config\ConnectionString.config" />
81
#region Test Methods
[Test]
public void ValidEmployeeTest()
public void InvalidEmployeeTest()
var employee = new Employee {Person = new Person {FirstName = "Bob", LastName = "Bob"}};
var employee = new Employee {Person = new Person {FirstName = string.Empty, LastName = string.Empty}};
var results = ValidationFactory.Validate(employee);
Assert.IsNotNull(results);
Assert.IsTrue(results.Valid);
Assert.IsFalse(results.Valid);
Assert.IsTrue(results.Messages.Count == 0);
Assert.IsTrue(results.Messages.Count > 0);
48
49
50
51
public void ValidEmployeeWithWarningsTest()
52
53
var employee = new Employee {Person = new Person {FirstName = "Bob", LastName = "Bob"}, HireDate = new DateTime(3112, 3, 12)};
54
55
56
57
58
59
60
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ValidationFrameworkTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("418644ba-5dc9-4af1-8b12-973b6d2463db")]
// Version information for an assembly consists of the following four values:
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyTitle("ValidationFramework")]
[assembly: Guid("d3b10a08-b978-461e-916a-eb22fdf33dcc")]
public sealed class ValidationMessage
internal ValidationMessage()
public string Message { get; internal set; }
public bool Warning { get; internal set; }
//Only allow creation internally or by ValidationResult class.
private bool _dirty = true;
private bool _valid;
public ValidationResult()
Messages = new List<ValidationMessage>();
public bool Valid
public IList<ValidationMessage> Messages { get; internal set; }
if (employee != null)
if (!suppressWarnings && employee.HireDate > DateTime.Now)
result.Messages.Add(new ValidationMessage {
result.Messages.Add(new ValidationMessage
Message = string.Format("Employee hire date: {0} is set in the future.", employee.HireDate),
Warning = true});
Warning = true
});
if (employee.Person != null)
break;{{[DebuggerDisplay("Id = {Id}, Name = {Name}, Description = {Description}")]{{public int Id { get; set; }public int Id { get; set; }#endregion#region Using Statementsusing System;#region Using Statementsusing System.Collections.Generic;using System.Linq;using System.Text;{{[DebuggerDisplay("FirstName = {FirstName}, LastName = {LastName}")]{{public string FirstName { get; set; }public string FirstName { get; set; }public string LastName { get; set; }public string LastName { get; set; }using System.Collections.Generic;using Iesi.Collections.Generic;namespace StructuredWeb.Domain.Business#region Using Statementsusing System;using System.Diagnostics;#endregionnamespace StructuredWeb.Domain.Business{{[DebuggerDisplay("Id = {Id}, CustomerDesc = {CustomerDesc}")]{{public string Id { get; set; }public string Id { get; set; }{{[DebuggerDisplay("Id = {Id}, Customer = {Customer.Person.LastName}, Employee = {Employee.Person.LastName}")]{{namespace StructuredWeb.Domain.Business#region Using Statementsusing System;using System.Diagnostics;#endregionnamespace StructuredWeb.Domain.Business{{[DebuggerDisplay("Id = {Id}, ProductName = {ProductName}, Discontinued = {Discontinued}")]{{public int Id { get; set; }public int Id { get; set; }namespace StructuredWeb.Domain.Business#region Using Statementsusing System;using System.Diagnostics;#endregionnamespace StructuredWeb.Domain.Business{{[DebuggerDisplay("Id = {Id}, CompanyName = {CompanyName}, Phone = {Phone}")]{{public int Id { get; set; }public int Id { get; set; }namespace StructuredWeb.Domain.Business#region Using Statementsusing System;using System.Diagnostics;#endregionnamespace StructuredWeb.Domain.Business{{[DebuggerDisplay("Id = {Id}, CompanyName = {CompanyName}, ContactName = {ContactName}")]{{public int Id { get; set; }public int Id { get; set; }{{[DebuggerDisplay("Id = {Id}, Description = {Description}")][DebuggerDisplay("Id = {Id}, Description = {Description}, Region = {Region}")]{{public string Id { get; set; }public string Id { get; set; }){{using Order = NHibernate.Criterion.Order;using Order=NHibernate.Criterion.Order;{{return _conversation.Session.CreateCriteria(typeof (Territory)).List<Territory>();/// These are the methods that return the physical boolean out of the extension method/// These are the methods that do the actual lifting{{Id = id,//Address = "address1",//City = "city",CompanyName = "company",ContactName = "Maria Anders",ContactTitle = "hi",//Country = "America",Fax = "123-234-4456",Phone = "123-444-5555",//PostalCode = "12345"};<%# Eval("FirstName")%><%# Eval("Person.FirstName")%><%# Eval("LastName")%><%# Eval("Person.LastName")%><%# Eval("JobTitle")%><%# Eval("JobTitle")%>using System.Linq;using System.Web.UI;using StructureMap;{{public partial class _Default : Page, IEmployeeViewpublic partial class _Default : ViewBasePage<EmployeePresenter, IEmployeeView>, IEmployeeView{{private EmployeePresenter _presenter;public EmployeePresenter Presenter{get{if (_presenter == null){ObjectFactory.BuildUp(this);}return _presenter;}set{_presenter = value;_presenter.View = this;}}{{{{Presenter.OnViewInitialized();_presenter.OnViewInitialized();Presenter.OnViewLoaded();_presenter.OnViewLoaded();namespace StructuredWeb {namespace StructuredWeb {public partial class _Default {{public void ValidEmployeeTest()public void InvalidEmployeeTest(){{var employee = new Employee {Person = new Person {FirstName = "Bob", LastName = "Bob"}};var employee = new Employee {Person = new Person {FirstName = string.Empty, LastName = string.Empty}};Assert.IsTrue(results.Valid);Assert.IsFalse(results.Valid);Assert.IsTrue(results.Messages.Count == 0);Assert.IsTrue(results.Messages.Count > 0);public void ValidEmployeeWithWarningsTest(){{var employee = new Employee {Person = new Person {FirstName = "Bob", LastName = "Bob"}, HireDate = new DateTime(3112, 3, 12)};var employee = new Employee {Person = new Person {FirstName = "Bob", LastName = "Bob"}};Assert.IsTrue(results.Messages.Count > 0);Assert.IsTrue(results.Messages.Count == 0);public void InvalidEmployeeTest()public void ValidEmployeeWithWarningsTest(){{var employee = new Employee {Person = new Person {FirstName = string.Empty, LastName = string.Empty}};var employee = new Employee {Person = new Person {FirstName = "Bob", LastName = "Bob"}, HireDate = new DateTime(3112, 3, 12)};Assert.IsFalse(results.Valid);Assert.IsTrue(results.Valid);using System.Reflection;#region Using Statementsusing System.Runtime.CompilerServices;using System.Reflection;[assembly: AssemblyTitle("ValidationFrameworkTest")][assembly: AssemblyTitle("ValidationFrameworkTest")][assembly: AssemblyDescription("")][assembly: AssemblyDescription("")][assembly: AssemblyConfiguration("")][assembly: AssemblyConfiguration("")][assembly: Guid("418644ba-5dc9-4af1-8b12-973b6d2463db")][assembly: Guid("418644ba-5dc9-4af1-8b12-973b6d2463db")]// [assembly: AssemblyVersion("1.0.*")]// [assembly: AssemblyVersion("1.0.*")][assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")]using System.Reflection;#region Using Statementsusing System.Runtime.CompilerServices;using System.Reflection;[assembly: AssemblyTitle("ValidationFramework")][assembly: AssemblyTitle("ValidationFramework")][assembly: AssemblyDescription("")][assembly: AssemblyDescription("")][assembly: AssemblyConfiguration("")][assembly: AssemblyConfiguration("")][assembly: Guid("d3b10a08-b978-461e-916a-eb22fdf33dcc")][assembly: Guid("d3b10a08-b978-461e-916a-eb22fdf33dcc")]// [assembly: AssemblyVersion("1.0.*")]// [assembly: AssemblyVersion("1.0.*")][assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")][assembly: AssemblyFileVersion("1.0.0.0")]{{{{{public string Message { get; internal set; }public string Message { get; internal set; }public bool Warning { get; internal set; }public bool Warning { get; internal set; }internal ValidationMessage(){}{{{public ValidationResult(){Messages = new List<ValidationMessage>();}public IList<ValidationMessage> Messages { get; internal set; }public IList<ValidationMessage> Messages { get; internal set; }{{result.Messages.Add(new ValidationMessage {Message = string.Format("Employee hire date: {0} is set in the future.", employee.HireDate),{Warning = true});Message = string.Format("Employee hire date: {0} is set in the future.", employee.HireDate),Warning = true});{{