Как мне настроить свой тестовый метод на имитирующем репозиторий, принимающий объект?
Это что у меня есть:
Service.cs
public int AddCountry(string countryName)
{
Country country = new Country();
country.CountryName = countryName;
return geographicsRepository.SaveCountry(country).CountryId;
}
test.cs
[Test]
public void Insert_Country()
{
//Setup
var geographicsRepository = new Mock<IGeographicRepository>();
geographicsRepository.Setup(x => x.SaveCountry(It.Is<Country>(c => c.CountryName == "Jamaica"))); //How do I return a 1 here?
GeographicService geoService = new GeographicService(geographicsRepository.Object);
int id = geoService.AddCountry("Jamaica");
Assert.AreEqual(1, id);
}
SaveCountry (Country country);
возвращает int.
Мне нужно сделать 2 вещи:
Мне нужно создать второй тест Insert_Duplicate_Country_Throws_Exception ()
. В моей настройке, как мне указать репозиторию выдавать ошибку, когда я это делаю:
int id = geoService.AddCountry ("Jamaica");
int id = geoService.AddCountry («Ямайка»);
Платформа: