public async void GetCategories_MapModelFromData_DataMap() { var categoryAppService = new Mock <ICategoryService>(); var categoriesApp = new[] { new CategoryModel() }; categoryAppService .Setup(x => x.GetCategoryList()) .ReturnsAsync(categoriesApp); var mapper = new Mock <IMapper>(); var categoryViewModels = new[] { new CategoryViewModel() }; mapper .Setup(x => x.Map <IEnumerable <CategoryViewModel> >(categoriesApp)) .Returns(categoryViewModels); var target = new CategoryPageService(categoryAppService.Object, mapper.Object); _ = await target.GetCategories(); mapper .Verify(x => x.Map <IEnumerable <CategoryViewModel> >(categoriesApp), Times.Once); }
public async void GetCategories_Return_MappedDataFromDataSource() { var categoryAppService = new Mock <ICategoryService>(); var categoriesApp = new[] { new CategoryModel() }; categoryAppService .Setup(x => x.GetCategoryList()) .ReturnsAsync(categoriesApp); var mapper = new Mock <IMapper>(); var categoryViewModels = new[] { new CategoryViewModel() }; mapper .Setup(x => x.Map <IEnumerable <CategoryViewModel> >(categoriesApp)) .Returns(categoryViewModels); var target = new CategoryPageService(categoryAppService.Object, mapper.Object); var result = await target.GetCategories(); result.Should().BeSameAs(categoryViewModels); }
public async void GetCategories_ReadDataFromDataSource_DataRead() { var categoryAppService = new Mock <ICategoryService>(); var categoriesApp = new[] { new CategoryModel() }; categoryAppService .Setup(x => x.GetCategoryList()) .ReturnsAsync(categoriesApp); var mapper = new Mock <IMapper>(); var categoryViewModels = new[] { new CategoryViewModel() { CategoryName = "MyTestCategory" } }; mapper .Setup(x => x.Map <IEnumerable <CategoryViewModel> >(It.Is <CategoryViewModel[]>(x => x.Length == 1 && x[0].CategoryName == "MyTestCategory"))) .Returns(categoryViewModels); //mapper //.Setup(x => x.Map<IEnumerable<CategoryViewModel>>(It.IsAny<CategoryViewModel[]>())) //.Returns(categoryViewModels); var target = new CategoryPageService(categoryAppService.Object, mapper.Object); _ = await target.GetCategories(); categoryAppService .Verify(x => x.GetCategoryList(), Times.Once); //mapper.Verify(x => x.Map<IEnumerable<CategoryViewModel>>(It.Is<CategoryViewModel[]>(x => x.Length == 1 && x[0].CategoryName == "MyTestCategory")), Times.Once); }