죄송합니다.Nunit을 사용하여 Nhibernate를 테스트하는 방법은 무엇입니까?
내가 ORM에 대한 자 NHibernate를 사용하고 난 NUNIT 사용하여 단위 테스트를 수행해야하는이 클래스가있어 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NutritionLibrary.Entity;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace NutritionLibrary.DAO
{
public class IngredientDAONHibernate : NutritionLibrary.DAO.IngredientDAO
{
private Configuration config;
private ISessionFactory factory;
public IngredientDAONHibernate()
{
config = new Configuration();
config.AddClass(typeof(NutritionLibrary.Entity.Ingredient));
config.AddClass(typeof(Entity.Nutrient));
config.AddClass(typeof(Entity.NutrientIngredient));
factory = config.BuildSessionFactory();
}
/// <summary>
/// gets the list of ingredients from the db
/// </summary>
/// <returns>IList of ingredients</returns>
public System.Collections.Generic.IList<Ingredient> GetIngredientList()
{
System.Collections.Generic.IList<Ingredient> ingredients;
string hql = "from NutritionLibrary.Entity.Ingredient ingredient";
ISession session = null;
ITransaction tx = null;
try
{
session = factory.OpenSession();
tx = session.BeginTransaction();
IQuery q = session.CreateQuery(hql);
ingredients = q.List<Ingredient>();
tx.Commit();
}
catch (Exception e)
{
if (tx != null) tx.Rollback();
/*if (logger.IsErrorEnabled)
{
logger.Error("EXCEPTION OCCURRED", e);
}*/
ingredients = null;
}
finally
{
session.Close();
session = null;
tx = null;
}
return ingredients;
}
}
}
내가 생성자로 시작을하지만, 나는 그것 정말 필요하지 말라고 조언 몇 사람을 얻었다. 그래서 이것은 시험 할 필요가있는 나의 방법입니다. 그것은 db를 쿼리하고 나에게 성분 객체 목록을 제공합니다. getIngredientList() 메서드를 테스트하는 방법을 시작하는 데 어려움을 겪고 있습니다. 나는이 테스트 스텁이 :
[TestMethod()]
public void GetIngredientListTest()
{
IngredientDAONHibernate target = new IngredientDAONHibernate(); // TODO: Initialize to an appropriate value
IList<Ingredient> expected = null; // TODO: Initialize to an appropriate value
IList<Ingredient> actual;
actual = target.GetIngredientList();
Assert.AreEqual(expected, actual);
}
내가 테스트 할 수있는 다른 유사한 방법을 많이 가지고가, 그래서 누군가가 나이 시작하는 데 도움이 친절하게도이 될 수 있다면, 나는 방법에 대한 기본적인 생각을해야합니다 내 다른 방법에 대한 단위 테스트를 구현합니다.
다시 한 번 시간을내어 알려 주시고 조언 해주십시오.
+1 매우 흥미 롭습니다. –