コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }