Maybe in Setup use It.IsAny<string> and It.IsAny<object> ?
-----Oorspronkelijk bericht-----
Van: "[email protected]" <[email protected]>
Verzonden: 3-8-2016 11:35
Aan: "nhusers" <[email protected]>
Onderwerp: [nhusers] Moq NHibernate Session for Unit Testing
Hi, I am writing the Unit tests against the MVC application, which is based on
Nhibernate. I have successfully Moq ed some repository classes / functions in
order to test my service layer methods. But I came to this function below in
my repository and I don't know how to Moq it. I need to Moq this function as
many other functions rely on it. The function:
public T GetByProperty<T>(string property, object value){ return (T)
this.Session.CreateCriteria(typeof(T))
.Add(NHibernate.Criterion.Restrictions.Eq(property, value))
.SetCacheable(RepositoryFactory.CanCache<T>()).SetCacheMode(CacheMode.Normal)
.UniqueResult();}
I've never worked with Nhibernate before and I am not sure whether I need to
Moq Session or somehow I can Moq the whole method or what?
I've tried this but it always returns null:
Mock mockRepository = new Mock<IRepository>();
mockRepository.Setup(x => x.GetByProperty<Account>(“UserName”, “MyUserName”))
.Returns(new Account { UserName = “MyUserName” });
I appreciate for you suggestions, thanks.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.