Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Examples/QuickStart
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23374/QuickStart
Added Files:
User.cs User.hbm.xml UserFixture.cs
Log Message:
Adding examples into cvs.
--- NEW FILE: User.cs ---
using System;
namespace NHibernate.Examples.QuickStart
{
/// <summary>
/// Summary description for User.
/// </summary>
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;
public User()
{
}
public string Id
{
get { return id; }
set { id = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
public DateTime LastLogon
{
get { return lastLogon; }
set { lastLogon = value; }
}
}
}
--- NEW FILE: User.hbm.xml ---
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Examples.QuickStart.User, NHibernate.Examples" table="users">
<id name="Id" column="LogonId" type="String(20)">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String(40)"/>
<property name="Password" type="String(20)"/>
<property name="EmailAddress" type="String(40)"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
--- NEW FILE: UserFixture.cs ---
using System;
using System.Collections;
using NHibernate.Cfg;
using NUnit.Framework;
namespace NHibernate.Examples.QuickStart
{
/// <summary>
/// Summary description for UserFixture.
/// </summary>
[TestFixture]
public class UserFixture
{
[Test]
public void ValidateQuickStart()
{
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "jo...@co...";
newUser.LastLogon = DateTime.Now;
// Tell NHibernate that this object should be saved
session.Save(newUser);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
// open another session to retrieve the just inserted user
session = factory.OpenSession();
User joeCool = (User)session.Load(typeof(User), "joe_cool");
// set Joe Cool's Last Login property
joeCool.LastLogon = DateTime.Now;
// flush the changes from the Session to the Database
session.Flush();
IList recentUsers = session.CreateCriteria(typeof(User))
.Add(Expression.Expression.Gt("LastLogon", new DateTime(2004, 03, 14, 20, 0, 0)))
.List();
foreach(User user in recentUsers)
{
Assert.IsTrue(user.LastLogon > (new DateTime(2004, 03, 14, 20, 0, 0)) );
}
session.Close();
}
}
}
|