public void GetReturnsListOfDistricts() { //Arrange var moq = new Mock <IDistrictsRepository>(); moq.Setup(m => m.Get()).Returns(Task.FromResult(new List <District>() as IEnumerable <District>)); DistrictsController controller = new DistrictsController(moq.Object); //Act var result = controller.Get().Result; //Assert Assert.IsInstanceOfType(result, typeof(IEnumerable <District>)); }
public void GetIdReturnsDistrict() { //Arrange var moq = new Mock <IDistrictsRepository>(); moq.Setup(m => m.Get(It.IsAny <object[]>())).Returns <object[]>(id => Task.FromResult(new District { Id = (int)id[0] })); DistrictsController controller = new DistrictsController(moq.Object); int districtId = 3; //Act var result = controller.Get(districtId).Result; //Assert Assert.IsInstanceOfType(result, typeof(District)); Assert.AreEqual(districtId, result.Id); }