public DimensionsValidatorTests()
        {
            _listQueryValidator    = new ListQueryValidator();
            _detailsQueryValidator = new DetailsQueryValidator();

            _addCommandValidator             = new AddCommandValidator();
            _updateCommandValidator          = new UpdateCommandValidator();
            _updatePartiallyCommandValidator = new UpdatePartiallyCommandValidator();
            _deleteOneCommandValidator       = new DeleteOneCommandValidator();
            _deleteManyCommandValidator      = new DeleteManyCommandValidator();
        }
Esempio n. 2
0
        public GenresValidatorTests()
        {
            _listQueryValidator      = new ListQueryValidator();
            _listBooksQueryValidator = new ListBooksQueryValidator();
            _detailsQueryValidator   = new DetailsQueryValidator();

            _addCommandValidator        = new AddCommandValidator();
            _updateCommandValidator     = new UpdateCommandValidator();
            _deleteOneCommandValidator  = new DeleteOneCommandValidator();
            _deleteManyCommandValidator = new DeleteManyCommandValidator();
        }
Esempio n. 3
0
        public AuthorsValidatorTests()
        {
            _listQueryValidator       = new ListQueryValidator();
            _listBooksQueryValidator  = new ListBooksQueryValidator();
            _listSeriesQueryValidator = new ListSeriesQueryValidator();
            _detailsQueryValidator    = new DetailsQueryValidator();

            _addCommandValidator             = new AddCommandValidator();
            _updatePartiallyCommandValidator = new UpdatePartiallyCommandValidator();
            _updateCommandValidator          = new UpdateCommandValidator();
            _deleteOneCommandValidator       = new DeleteOneCommandValidator();
            _deleteManyCommandValidator      = new DeleteManyCommandValidator();
        }
Esempio n. 4
0
        public BooksValidatorTests()
        {
            _listQueryValidator           = new ListQueryValidator();
            _listEditionQueryValidator    = new ListEditionQueryValidator();
            _detailsQueryValidator        = new DetailsQueryValidator();
            _detailsEditionQueryValidator = new DetailsEditionQueryValidator();

            _addCommandValidator        = new AddCommandValidator();
            _addEditionCommandValidator = new AddEditionCommandValidator();

            _updateCommandValidator        = new UpdateCommandValidator();
            _updateEditionCommandValidator = new UpdateEditionCommandValidator();

            _updatePartiallyCommandValidator        = new UpdatePartiallyCommandValidator();
            _updatePartiallyEditionCommandValidator = new UpdatePartiallyEditionCommandValidator();

            _deleteOneCommandValidator        = new DeleteOneCommandValidator();
            _deleteOneEditionCommandValidator = new DeleteOneEditionCommandValidator();

            _deleteManyCommandValidator        = new DeleteManyCommandValidator();
            _deleteManyEditionCommandValidator = new DeleteManyEditionCommandValidator();
        }
        public async Task <ListResponse <_TEntity> > Handle(_TListQuery request,
                                                            CancellationToken cancellationToken)
        {
            Logger.LogInformation(AppLogEvent.HandleRequest,
                                  "Handle Get Project List {Request}", request.ToDictionary());

            if (request is null)
            {
                Logger.LogWarning(AppLogEvent.HandleArgumentError,
                                  "Handle Get Project List request with empty request");
                return(ErrorResponse("Request empty argument"));
            }

            try
            {
                // Validate request
                var validator        = new ListQueryValidator <_TListQuery>();
                var validationResult = await validator.ValidateAsync(request)
                                       .ConfigureAwait(false);

                if (!validationResult.IsValid)
                {
                    Logger.LogError("Query validation error. " +
                                    "Request={Request}. Error={Error}.",
                                    request.ToDictionary(),
                                    validationResult.Errors.Select(x => x.ErrorMessage));
                    return(ErrorResponse
                               (validationResult.Errors.Select(x => x.ErrorMessage)));
                }

                // Build filter
                var defaultLimit = Configuration.GetValue
                                       (Defaults.ConfigurationApiDefaultLimitParameterName,
                                       Defaults.ConfigurationApiDefaultLimitDefaultValue);
                var maxLimit = Configuration.GetValue
                                   (Defaults.ConfigurationApiMaxLimitParameterName,
                                   Defaults.ConfigurationApiMaxLimitDefaultValue);
                var dbRequest = new DbGetProjectFilterRequest
                {
                    Offset = request.Offset,
                    Limit  = request.Limit == 0
                        ? defaultLimit
                        : Math.Min(request.Limit, maxLimit),
                    Archived = request.Archived,
                    Contains = request.СontainsKeyWords
                };

                // Get Actor for current user by user name
                var currentActorResponse = await Mediator
                                           .Send(new DbGetActorByNameRequest
                                                 (request.CurrentPrincipal?.Identity?.Name))
                                           .ConfigureAwait(false);

                Actor currentActor = null;
                if (currentActorResponse.Success)
                {
                    currentActor = currentActorResponse.Entity;
                }
                else
                {
                    Logger.LogWarning(AppLogEvent.HandleArgumentError,
                                      "Not found current actor");
                    return(ErrorResponse("Not found current actor"));
                }

                // Apply security filter
                var securizator = new DbGetProjectFilterRequestSecurityBuilder
                                      (dbRequest, currentActor);
                DbGetProjectFilterRequest securedFilter = securizator.Build();

                return(await Mediator
                       .Send(securedFilter)
                       .ConfigureAwait(false));
            }
            catch (Exception e)
            {
                Logger.LogError(AppLogEvent.HandleErrorResponse, e,
                                "Call repository exception");
                return(ErrorResponse("Not found"));
            }
        }
        public async Task <ListResponse <_TEntity> > Handle(_TListQuery request,
                                                            CancellationToken cancellationToken)
        {
            Logger.LogInformation(AppLogEvent.HandleRequest,
                                  "Handle Get Geo List {Request}", request.ToDictionary());

            if (request is null)
            {
                Logger.LogWarning(AppLogEvent.HandleArgumentError,
                                  "Handle Get Geo List request with empty request");
                return(ErrorResponse("Request empty argument"));
            }

            try
            {
                // Validate request
                var validator        = new ListQueryValidator <_TListQuery>();
                var validationResult = await validator.ValidateAsync(request)
                                       .ConfigureAwait(false);

                if (!validationResult.IsValid)
                {
                    Logger.LogError("Query validation error. " +
                                    "Request={Request}. Error={Error}.",
                                    request.ToDictionary(),
                                    validationResult.Errors.Select(x => x.ErrorMessage));
                    return(ErrorResponse
                               (validationResult.Errors.Select(x => x.ErrorMessage)));
                }

                // Build request
                var defaultLimit = Configuration.GetValue
                                       (Defaults.ConfigurationApiDefaultLimitParameterName,
                                       Defaults.ConfigurationApiDefaultLimitDefaultValue);
                var maxLimit = Configuration.GetValue
                                   (Defaults.ConfigurationApiMaxLimitParameterName,
                                   Defaults.ConfigurationApiMaxLimitDefaultValue);

                var dbGeoListRequest = request
                                       .ToDbGetGeoFilterRequest(defaultLimit, maxLimit);

                // Check current actor
                var currentActorResponse = await Mediator
                                           .Send(new DbGetActorByNameRequest
                                                 (request.CurrentPrincipal?.Identity?.Name))
                                           .ConfigureAwait(false);

                if (!currentActorResponse.Success ||
                    currentActorResponse.Entity.IsArchived)
                {
                    Logger.LogWarning(AppLogEvent.HandleArgumentError,
                                      "Not found current actor");
                    return(ErrorResponse("Not found current actor"));
                }

                return(await Mediator
                       .Send(dbGeoListRequest)
                       .ConfigureAwait(false));
            }
            catch (Exception e)
            {
                Logger.LogError(AppLogEvent.HandleErrorResponse, e,
                                "Call repository exception");
                return(ErrorResponse("Not found"));
            }
        }
 public void TestInitialize()
 {
     _validator = new ListQueryValidator();
 }