views:

13

answers:

1

Hey, I put my NHibernate data access class in WCF service to can consume it by Silverlight project, but I have error and want to test my queries.

It is possible to test this queries in service class using NUnit ? Earlier I test normally this class but how do it when it is in service class ??

It's my WCF service class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using DataTransfer;
using NHibernate;
using NHibernate.Cfg;
using System.Diagnostics;

namespace WcfService1
{
    public class Service1 : IService1
    {
        private ISession _session;
        public Service1()
        {
            try
            {
                _session = (new Configuration()).Configure().BuildSessionFactory().OpenSession();
            }
            catch (Exception e)
            {
                Debug.Write(e);
                throw;
            }
        }
        public IList<Dziecko> GetChildByFirstname(string _firstname)
        {
            return _session.CreateCriteria(typeof(Dziecko))
                .Add(NHibernate.Criterion.Expression.Eq("Imie", _firstname)).List<Dziecko>();
        }
        public IList<Dziecko> GetChildByLastname(string _lastname)
        {
            return _session.CreateCriteria(typeof(Dziecko))
                .Add(NHibernate.Criterion.Expression.Eq("Nazwisko", _lastname)).List<Dziecko>();
        }
        public IList<Dziecko> GetChildByFirstnameAndLastname(string _firstname, string _lastname)
        {
            return _session.CreateCriteria(typeof(Dziecko))
                .Add(NHibernate.Criterion.Expression.Eq("Imie", _firstname)).Add(NHibernate.Criterion.Expression.Eq("Nazwisko", _lastname)).List<Dziecko>();
        }
    }
}
+1  A: 

If you want to test the queries themselves, I'd recommend putting them into a separate assembly (maybe using the repository pattern) and calling the methods in this assembly from your service. This will make it easier to test the queries themselves, and also allow you to mock the repositories when testing the service.

AlexCuse