Exemplo n.º 1
0
        public async Task <string> GetAllStoreComponentsAsync()
        {
            var allComponents = await _shopRepository.GetComponentsAsync();

            var components = new ShopComponentsModel()
            {
                Products   = (List <Product>)allComponents[0],
                Categories = (List <Category>)allComponents[1],
                Statuses   = (List <Status>)allComponents[2],
                Sizes      = (List <Size>)allComponents[3]
            };

            string objectsJson = _jsonHelper.JsonSerializeObject(components);

            return(objectsJson);
        }
        public void SetUp()
        {
            _shopRepository = new Mock <IShopRepository>();
            _jsonHelper     = new Mock <IJsonHelper>();


            List <Product> products = new List <Product>()
            {
                new Product()
                {
                    ProductId = 1, Name = "Product_a", Price = 10, IsInactive = false
                },
                new Product()
                {
                    ProductId = 2, Name = "Product_b", Price = 10, IsInactive = false
                },
                new Product()
                {
                    ProductId = 3, Name = "Product_c", Price = 10, IsInactive = false
                },
                new Product()
                {
                    ProductId = 4, Name = "Product_d", Price = 10, IsInactive = false
                },
            };
            List <Category> categories = new List <Category>()
            {
                new Category()
                {
                    CategoryId = 1, Name = "Category_a", IsInactive = false
                },
                new Category()
                {
                    CategoryId = 2, Name = "Category_b", IsInactive = false
                },
                new Category()
                {
                    CategoryId = 3, Name = "Category_c", IsInactive = false
                },
                new Category()
                {
                    CategoryId = 4, Name = "Category_d", IsInactive = false
                },
            };
            List <Status> statuses = new List <Status>()
            {
                new Status()
                {
                    StatusId = 1, Name = "Status_a", IsInactive = false
                },
                new Status()
                {
                    StatusId = 2, Name = "Status_b", IsInactive = false
                },
                new Status()
                {
                    StatusId = 3, Name = "Status_c", IsInactive = false
                },
                new Status()
                {
                    StatusId = 4, Name = "Status_d", IsInactive = false
                },
            };
            List <Size> sizes = new List <Size>()
            {
                new Size()
                {
                    SizeId = 1, Description = "size_a", IsInactive = false
                },
                new Size()
                {
                    SizeId = 2, Description = "size_a", IsInactive = false
                },
                new Size()
                {
                    SizeId = 3, Description = "size_a", IsInactive = false
                },
                new Size()
                {
                    SizeId = 4, Description = "size_a", IsInactive = false
                },
            };

            List <object> allItems = new List <object>()
            {
                products, categories, statuses, sizes
            };

            _shopModel = new ShopComponentsModel()
            {
                Products   = products,
                Categories = categories,
                Statuses   = statuses,
                Sizes      = sizes,
            };

            _shopRepository
            .Setup(c => c.GetComponentsAsync())
            .Returns(async() => {
                return(await Task.Run(() => {
                    return allItems;
                }));
            });

            _shopService = new ShopService(_shopRepository.Object, _jsonHelper.Object);
        }