I am using Moq and I have a repository that I am trying to create mock methods.
The GetAll method returns the values however the GetById returns null.
var currencyRepo = new Mock<ICurrencyRepository>();
var currencies = new List<Currency>{new Currency
{
CurrencyCode = "USD",
CurrencyId = 1,
},
new Currency
{
CurrencyCode = "EUR",
CurrencyId = 2
}};
currencyRepo.Setup(c => c.GetAll()).Returns(currencies);
currencyRepo.Setup(c => c.GetById(It.IsAny<int>())).Returns((int i) => currencies.Single(c => c.CurrencyId == i));
var currency = currencyRepo.Object.GetById(1); //This always returns null
//currency is always null
//but calling the GetAll method works!
var currencyList = currencyRepo.Object.GetAll(); //this works!
any ideas?
I solved it change to long in setup method because the GetById accepts a long parameter. DUH!