Пример #1
0
        public async Task <IEnumerable <CategoryResponseDto> > Handle(GetCategoryQuery request, CancellationToken cancellationToken)
        {
            using var dbcontext = _dataContextFactory.SpawnDbContext();
            var categories = await dbcontext.Categories.ToListAsync();

            return(_mapper.Map <IEnumerable <CategoryResponseDto> >(categories));
        }
Пример #2
0
        public async Task SaveCategoryUpdateSuccess_Test()
        {
            Categories category1 = new Categories()
            {
                Id           = 1,
                CategoryName = "abc",
                Type         = "123",
                Enabled      = true
            };

            _dbContext.Set <Categories>().Add(category1);

            CategoryViewModel model = new CategoryViewModel()
            {
                Id           = 1,
                CategoryName = "abc123",
                Type         = "123",
                Enabled      = true
            };

            await _dbContext.SaveChangesAsync();

            var efRepository        = new EfRepository <Categories>(_dbContext);
            var saveCategoryCommand = new SaveCategoryCommand(efRepository);
            var result = await saveCategoryCommand.ExecuteAsync(model);

            var getListCategory = new GetCategoryQuery(efRepository);
            var category        = (await getListCategory.ExecuteAsync()).FirstOrDefault();

            Assert.Equal(result.Data, model.Id);
            Assert.Equal(model.CategoryName, category.CategoryName);
        }
Пример #3
0
        public async Task GetListLibrary_Test()
        {
            var category1 = new Categories
            {
                Id           = 1,
                CategoryName = "category1",
                Type         = "Book",
                Enabled      = true
            };

            _dbContext.Set <Categories>().Add(category1);

            var category2 = new Categories
            {
                Id           = 2,
                CategoryName = "category1",
                Type         = "Book",
                Enabled      = false
            };

            _dbContext.Set <Categories>().Add(category2);

            await _dbContext.SaveChangesAsync();

            var efRepository   = new EfRepository <Categories>(_dbContext);
            var getListLibrary = new GetCategoryQuery(efRepository);
            var categories     = await getListLibrary.ExecuteAsync();

            Assert.NotNull(categories);
            Assert.Single(categories);
        }
Пример #4
0
        public ActionResult <CategoryDTO> GetCategory(int id)
        {
            var query       = new GetCategoryQuery(id);
            var category    = _queryHandler.Handle(query);
            var categoryDTO = _mapper.Map <CategoryDTO>(category);

            return(Ok(categoryDTO));
        }
        public async Task <IActionResult> GetCategory(int id)
        {
            var query  = new GetCategoryQuery(id);
            var result = await _mediator.Send(query);

            return(result != null
                ? (IActionResult)Ok(result)
                : NotFound(string.Format(ModelConstants.PropertyNotFoundFromController, "კატეგორია")));
        }
        public async Task <GetCategoryQuery.QueryResult> HandleAsync(GetCategoryQuery query)
        {
            var categoryDomainModel = await _categoriesService.GetCategoryAsync(query.Id);

            return(new GetCategoryQuery.QueryResult
            {
                CategoryModel = _mapper.Map <CategoryViewModel>(categoryDomainModel)
            });
        }
Пример #7
0
 public RouteTests()
 {
     _getCategoryBaseQuery      = new GetCategoryBaseQuery(DbContext, Cache);
     _getCategoryQuery          = new GetCategoryQuery(DbContext, _getCategoryBaseQuery, WorkContext);
     _getRouteQuery             = new GetRouteQuery(DbContext);
     _listRoutesQuery           = new ListRoutesQuery(DbContext);
     _listRouteQueryHandler     = new GetRouteQueryHandler(_getRouteQuery);
     _listRoutesQueryHandler    = new ListRoutesQueryHandler(_listRoutesQuery);
     _getRouteByUrlQueryHandler = new GetRouteByUrlQueryHandler(_listRoutesQuery, _getCategoryQuery);
 }
Пример #8
0
        public async Task <IActionResult> Edit(Guid id)
        {
            var query = new GetCategoryQuery {
                Id = id
            };
            var result = await _queries.Request <GetCategoryQuery, GetCategoryQueryResult>(query);

            var model = Mapper.Map <Category, CategoryEditModel>(result.Category);

            return(View(model));
        }
            public async Task <Result <CategoryDto> > Handle(GetCategoryQuery request, CancellationToken cancellationToken)
            {
                var category = await _dataContext.Categories.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken);

                if (category == null)
                {
                    return(Result.Error <CategoryDto>(Resource.CategoryIdDosentExist));
                }

                var productDto = _mapper.Map <CategoryDto>(category);

                return(Result.Ok(productDto));
            }
Пример #10
0
        public async Task <Result <CategoryViewModel> > Handle(GetCategoryQuery request, CancellationToken cancellationToken)
        {
            var foundCategory = await _dbContext.Categories.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken : cancellationToken);

            if (foundCategory == null)
            {
                return(Result <CategoryViewModel> .NotFoundResult());
            }

            var viewModel = _context.Map(foundCategory);

            return(viewModel.ToSuccessResult());
        }
Пример #11
0
 public CategoryTests()
 {
     _getSystemSettingQuery               = new GetSystemSettingQuery(DbContext);
     _getInputFormQuery                   = new GetInputFormQuery(DbContext, _getSystemSettingQuery);
     _getCategoryBaseQuery                = new GetCategoryBaseQuery(DbContext, Cache);
     _getCategoryQuery                    = new GetCategoryQuery(DbContext, _getCategoryBaseQuery, WorkContext);
     _listCategoriesQuery                 = new ListCategoriesQuery(DbContext);
     _listProductsByCategoryQuery         = new ListProductsByCategoryQuery(DbContext);
     _listCategoryNavigationsQueryHandler = new ListCategoryNavigationsQueryHandler(_listCategoriesQuery);
     _getInputFormQueryHandler            = new GetInputFormQueryHandler(_getInputFormQuery);
     _getCategoryQueryHandler             = new GetCategoryQueryHandler(_getCategoryQuery, WorkContext);
     _listCategoriesQueryHandler          = new ListCategoriesQueryHandler(_listCategoriesQuery);
     _listProductsByCategoryQueryHandler  = new ListProductsByCategoryQueryHandler(_listProductsByCategoryQuery);
 }
Пример #12
0
        public async Task <ActionResult <CategoryViewModel> > Get(int id)
        {
            var message = new GetCategoryQuery()
            {
                Id = id
            };
            var result = await _mediator.Send(message);

            if (!result)
            {
                return(NotFound());
            }

            return(result.Payload);
        }
Пример #13
0
        public async Task GetCategoryHandler_Returns_Category()
        {
            var category = await GetRandomCategory();

            var message = new GetCategoryQuery()
            {
                Id = category.Id
            };
            var handlerContext = TestContext.CreateHandlerContext <CategoryViewModel>(RequestDbContext);
            var handler        = new GetCategoryQueryHandler(handlerContext);

            var result = await handler.Handle(message, CancellationToken.None);

            Assert.Equal(category.Id, result.Payload.Id);
        }
Пример #14
0
        public async Task SaveCategoryInsertSuccess_Test()
        {
            CategoryViewModel model = new CategoryViewModel()
            {
                Id           = 0,
                CategoryName = "abc",
                Type         = "123",
                Enabled      = true
            };

            var efRepository        = new EfRepository <Categories>(_dbContext);
            var saveCategoryCommand = new SaveCategoryCommand(efRepository);
            var result = await saveCategoryCommand.ExecuteAsync(model);

            var getListCategory = new GetCategoryQuery(efRepository);
            var category        = (await getListCategory.ExecuteAsync()).FirstOrDefault();

            Assert.Equal(result.Data, model.Id);
            Assert.Equal(model.CategoryName, category.CategoryName);
            Assert.Equal(model.Type, category.Type);
            Assert.Equal(model.Enabled, category.Enabled);
        }
Пример #15
0
        public async Task Category_GetQuery_Success()
        {
            //Arrange
            GetCategoryQuery query = new GetCategoryQuery();

            _categoryRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <Category, bool> > >()))
            .ReturnsAsync(new Category()
//propertyler buraya yazılacak
//{
//CategoryId = 1,
//CategoryName = "Test"
//}
                          );

            GetCategoryQueryHandler handler = new GetCategoryQueryHandler(_categoryRepository.Object, _mediator.Object);

            //Act
            var x = await handler.Handle(query, new System.Threading.CancellationToken());

            //Asset
            Assert.That(x.Success, Is.True);
            //Assert.That(x.Data.CategoryId, Is.EqualTo(1));
        }
 public async Task <CategoryDto> GetById([FromRoute] GetCategoryQuery query)
 {
     return(await _mediator.Send(query));
 }
Пример #17
0
 public async Task <IActionResult> GetCategories([FromQuery] GetCategoryQuery query) => Ok(await _mediator.Send(query));
 public async Task <GetCategoryQuery.QueryResult> GetCategoryAsync([FromQuery] GetCategoryQuery query)
 {
     return(await _handler.HandleAsync(query));
 }
Пример #19
0
 public async Task <IActionResult> Get([FromRoute] GetCategoryQuery query)
 {
     return(await Execute(query));
 }
 public async Task <CategoryDto> GetCategory([FromRoute] GetCategoryQuery query, CancellationToken cancellationToken)
 {
     return(await _mediator.Send(query, cancellationToken));
 }
Пример #21
0
        public CategoryDto Handle(GetCategoryQuery query)
        {
            var item = _categoryRepository.Get(query.Id);

            return(_mapper.Map <CategoryDto>(item));
        }