Answer the question
In order to leave comments, you need to log in
Moq Library: How to return a List in an emulated method?
Hello!
I'm trying to use the Moq library for unit testing.
Here is an option that works:
Application app = InitTestApplication(id);
var repositoryMock = new Mock<IRepository> ();
repositoryMock.Setup (x => x.Create (app)).Returns (app);
var repositoryMongo = repositoryMock.Object;
var repository = new ApplicationRepository (repositoryMongo);
var appResult = repository.Create (app);
Assert.AreEqual (app.Id, appResult.Id);
repositoryMock.Setup (x => x.ExecuteQuery<Application> (predicate))
.Returns (() => new List<Application> { new Application (){
Id = id,
Title = "Application Title",
SubTitle = "Application SubTitle",
EmailOwner = "n****[email protected]",
Copyright = "© Copyright *** 2013.",
IconSource = "2.png",
IsTest = true,
TestUid = TestUid,
CreatedAt = DateTime.MinValue,
UpdatedAt = DateTime.MinValue
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question