- northwind.zip
- Castle.ActiveRecord.dll
- Castle.Core.dll
- Iesi.Collections.dll
- log4net.dll
- NHibernate.dll
- NMock2.dll
- Northwind.DataAccess.Test
- Northwind.DataAccess
- Northwind.Domain.Test
- Northwind.Domain
- Northwind.Presentation.Test
- Northwind.Presentation
- Northwind.Services.Test
- Northwind.Services
- NorthWind.sln
- Northwind.TransferObjects.Test
- Northwind.TransferObjects
- Northwind.UI.Controls
- Northwind.UI
- nunit.framework.dll
|
using Castle.ActiveRecord;
using NHibernate;
using Northwind.DataAccess;
using Northwind.DataAccess.Repository;
using Northwind.Domain.Model;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
namespace Northwind.DataAccess.Test
{
[TestFixture]
public class InMemoryCustomerRepositoryTest
{
private Customer customer;
private InMemoryCustomerRepository customerRepository;
[SetUp]
public void Setup()
{
customer = new Customer();
customerRepository = new InMemoryCustomerRepository();
//We must initialize ActiveRecord db settings before working with ActiveRecords.
DataAccessHelper.Initialize();
}
[Test]
public void InsertAndGetCustomerTest()
{
Customer c = new Customer();
Assert.AreEqual(true, c.IsNew, "c.IsNew");
c.ID = "TEST";
c.CompanyName = "CUSTOMER TEST";
c.ContactName = "CONTACT TEST";
using (ISession session = DataAccessHelper.SessionFactory.OpenSession())
{
session.BeginTransaction();
customerRepository.AddOrUpdate(session, c);
session.Transaction.Commit();
}
Assert.AreEqual(false, c.IsNew, "c.IsNew");
Customer c2 = customerRepository.Load("TEST");
using (ISession session = DataAccessHelper.SessionFactory.OpenSession())
{
session.BeginTransaction();
customerRepository.Remove(session, c2);
session.Transaction.Commit();
}
}
[Test]
public void InsertAndUpdateCustomerTest()
{
Customer c = new Customer();
c.ID = "TEST";
c.CompanyName = "CUSTOMER TEST";
c.ContactName = "CONTACT TEST";
using (ISession session = DataAccessHelper.SessionFactory.OpenSession())
{
session.BeginTransaction();
customerRepository.AddOrUpdate(session, c);
session.Transaction.Commit();
}
Customer c2 = customerRepository.Load("TEST");
c2.CompanyName = "CUSTOMER TEST UPDATED";
c2.ContactName = "CONTACT TEST UPDATED";
using (ISession session = DataAccessHelper.SessionFactory.OpenSession())
{
session.BeginTransaction();
customerRepository.AddOrUpdate(session, c2);
session.Transaction.Commit();
}
Customer c3 = customerRepository.Load("TEST");
Assert.AreEqual("CUSTOMER TEST UPDATED", c3.CompanyName);
Customer c4 = customerRepository.Load("TEST");
using (ISession session = DataAccessHelper.SessionFactory.OpenSession())
{
session.BeginTransaction();
customerRepository.Remove(session, c4);
session.Transaction.Commit();
}
}
[Test]
public void InsertAndDeleteCustomerTest()
{
Customer c = new Customer();
c.ID = "TEST";
c.CompanyName = "CUSTOMER TEST";
c.ContactName = "CONTACT TEST";
using (ISession session = DataAccessHelper.SessionFactory.OpenSession())
{
session.BeginTransaction();
customerRepository.AddOrUpdate(session, c);
session.Transaction.Commit();
}
Customer c2 = customerRepository.Load("TEST");
using (ISession session = DataAccessHelper.SessionFactory.OpenSession())
{
session.BeginTransaction();
customerRepository.Remove(session, c2);
session.Transaction.Commit();
}
try
{
Customer c3 = customerRepository.Load("TEST");
Assert.IsTrue(c3 == null, "customer has not been deleted");
}
catch
{
}
}
[TearDown]
public void TearDown()
{
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.