Exemple #1
0
 protected override void Validate(ByLevelQuery query)
 {
     if (query.Level <= 0)
     {
         throw new ValidationException("Level should be more than 0");
     }
 }
        public async Task <IEnumerable <CategoryModel> > GetByLevel(int level)
        {
            var query = new ByLevelQuery {
                Level = level
            };

            return(await _queryProcessor.ProcessAsync(query).ConfigureAwait(true));
        }
Exemple #3
0
        public async Task TestGetByLevelValidation()
        {
            var mock = new Mock <IQueryHandler <ByLevelQuery, IEnumerable <CategoryModel> > >();

            var query = new ByLevelQuery {
                Level = 0
            };

            var queryHandler = new ByLevelValidateQueryHandlerDecorator(mock.Object);

            await Assert.ThrowsAsync <ValidationException>(async() => await queryHandler.HandleAsync(query).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task TestGetByLevel(int level, int[] ids)
        {
            var query = new ByLevelQuery {
                Level = level
            };

            var queryHandler = new ByLevelQueryHandler(_repository);

            var result = await queryHandler.HandleAsync(query).ConfigureAwait(false);

            Assert.IsAssignableFrom <IEnumerable <CategoryModel> >(result);

            var resultIds = result.Select(_ => _.Id).OrderBy(_ => _).ToArray();

            Assert.Equal(ids.Length, resultIds.Length);
            Assert.Equal(ids, resultIds);
        }
        public async Task <IEnumerable <CategoryModel> > HandleAsync(ByLevelQuery query)
        {
            var categories = await _repository.GetCategoriesByLevel(query.Level).ConfigureAwait(false);

            return(Mapper.Map <IEnumerable <CategoryModel> >(categories));
        }