I am not sure what I am doing wrong but here is the scenario for which I am trying to write the unit test using NUnit
, MOQ
in C#
Model:
public class Model
{
public int ID { get; set; }
public string Name { get; set; }
public string Address1 { get; set; }
}
Repo
public class Repo : IRepo
{
public Model Execute(Datetime date)
{
// Calls DB Operation
// Maps only two properties and didn't map Address1
Id = Id,
Name = Name
}
}
Unit Test
public void UnitTestToMockDB()
{
var mockRepo = new Mock<IRepo>();
var expectedResult = new Model()
{
Id = 1,
Name = "Username",
Address1 = "Address line 1"
};
mockRepo.Setup(repo => repo.Execute(It.IsAny<DateTime>())).Returns(expectedResult);
var result = mockRepo.Object.Execute(DateTime.Now);
}
To my surprise, result
consists of the Address1
property, which it should not. What I am doing wrong? And why it is returning Address1
?