public void Test_GetFruitList_Return_Passed() { var fruit = new FruitDTO(1, "test", 1.25, true, new DateTime(2018, 08, 08)); var fruit1 = new FruitDTO(2, "test", 2.25, false, new DateTime(2018, 01, 01)); var fruitList = new List <FruitDTO> { fruit, fruit1 }; var mockInterface = new Mock <IFruitService>(); mockInterface.Setup(repo => repo.GetFruitList()).Returns(fruitList); var controller = new HomeController(mockInterface.Object); var result = controller.Index(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <FruitDTO> >( viewResult.ViewData.Model); Assert.Equal(2, model.Count()); }
private static FruitDTO GetFruit(Fruit fruit) { FruitDTO newFruit = new FruitDTO(); newFruit.Sugar = fruit.Sugar; newFruit.Acid = fruit.Acid; newFruit.Price = fruit.Price; return(newFruit); }
public List <FruitDTO> Add(Fruit fruit) { var newId = fruitList.LastOrDefault().Id; if (newId != 0) { newId++; } var fruitDTO = new FruitDTO(newId, fruit.Name, fruit.Price, fruit.InStock, DateTime.Now); fruitList.Add(fruitDTO); return(fruitList); }