public void GetFoodTemplatesPaged_Success_Test() { // Arrange string searchTerm = ""; int pageIndex = 0; int pageSize = 10; // list IList <R_FoodTemplate> list = new List <R_FoodTemplate>(); for (int i = 1; i <= pageSize; i++) { list.Add(SampleFoodTemplate(i)); } // create mock for repository var mock = new Mock <IFoodTemplateRepository>(); mock.Setup(s => s.GetFoodTemplates(Moq.It.IsAny <string>(), Moq.It.IsAny <int>(), Moq.It.IsAny <int>())).Returns(list); // service FoodTemplateService foodTemplateService = new FoodTemplateService(); FoodTemplateService.Repository = mock.Object; // Act var resultList = foodTemplateService.GetFoodTemplates(searchTerm, pageIndex, pageSize); FoodTemplateDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.FoodTemplateId); Assert.AreEqual(10, resultList.Count); }
public void GetFoodTemplates_Success_Test() { // Arrange R_FoodTemplate foodTemplate = SampleFoodTemplate(1); IList <R_FoodTemplate> list = new List <R_FoodTemplate>(); list.Add(foodTemplate); // create mock for repository var mock = new Mock <IFoodTemplateRepository>(); mock.Setup(s => s.GetFoodTemplates()).Returns(list); // service FoodTemplateService foodTemplateService = new FoodTemplateService(); FoodTemplateService.Repository = mock.Object; // Act var resultList = foodTemplateService.GetFoodTemplates(); FoodTemplateDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.FoodTemplateId); }