public async Task TestGetNotExistingById()
        {
            var query = new ByIdQuery {
                Id = 110
            };

            var queryHandler = new ByIdValidateQueryHandlerDecorator <ByIdQuery>(new ByIdQueryHandler(_repository));

            await Assert.ThrowsAsync <EntityNotFoundException>(async() => await queryHandler.HandleAsync(query).ConfigureAwait(false)).ConfigureAwait(false);
        }
Пример #2
0
        public async Task TestGetByIdValidation()
        {
            var mock = new Mock <IQueryHandler <ByIdQuery, CategoryModel> >();

            var query = new ByIdQuery {
                Id = 0
            };

            var queryHandler = new ByIdValidateQueryHandlerDecorator <ByIdQuery>(mock.Object);

            await Assert.ThrowsAsync <ValidationException>(async() => await queryHandler.HandleAsync(query).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task TestGetById()
        {
            var query = new ByIdQuery {
                Id = 101
            };

            var queryHandler = new ByIdValidateQueryHandlerDecorator <ByIdQuery>(new ByIdQueryHandler(_repository));

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

            Assert.IsType <CategoryModel>(result);
            Assert.Equal(101, result.Id);
            Assert.NotNull(result.ParentId);
            Assert.Equal(100, result.ParentId.Value);
            Assert.Equal("Accounting", result.Name);
            Assert.Equal("Taxes", result.Keywords);
        }