Exemplo n.º 1
0
        public async Task Should_not_add_error_everything_defined()
        {
            var action = new AlgoliaAction {
                AppId = "APP", ApiKey = "KEY", IndexName = "IDX"
            };

            var errors = await RuleActionValidator.ValidateAsync(action);

            Assert.Empty(errors);
        }
Exemplo n.º 2
0
        public async Task Should_add_error_if_index_name_not_defined()
        {
            var action = new AlgoliaAction {
                AppId = "APP", ApiKey = "KEY", IndexName = null
            };

            var errors = await RuleActionValidator.ValidateAsync(action);

            Assert.NotEmpty(errors);
        }
Exemplo n.º 3
0
        public async Task Should_add_error_if_index_name_not_defined()
        {
            var action = new AlgoliaAction {
                AppId = "APP", ApiKey = "KEY", IndexName = null
            };

            var errors = await RuleActionValidator.ValidateAsync(action);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Index name is required.", "IndexName")
            });
        }
Exemplo n.º 4
0
        public async Task Should_add_error_if_api_key_not_defined()
        {
            var action = new AlgoliaAction {
                AppId = "APP", ApiKey = null, IndexName = "IDX"
            };

            var errors = await RuleActionValidator.ValidateAsync(action);

            errors.ShouldBeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Api Key is required.", "ApiKey")
            });
        }
Exemplo n.º 5
0
        public async Task Should_add_error_if_app_id_not_defined()
        {
            var action = new AlgoliaAction {
                AppId = null, ApiKey = "KEY", IndexName = "IDX"
            };

            var errors = await RuleActionValidator.ValidateAsync(action);

            errors.Should().BeEquivalentTo(
                new List <ValidationError>
            {
                new ValidationError("Application ID is required.", "AppId")
            });
        }
Exemplo n.º 6
0
        public Task <IEnumerable <ValidationError> > Visit(AlgoliaAction action)
        {
            var errors = new List <ValidationError>();

            if (string.IsNullOrWhiteSpace(action.ApiKey))
            {
                errors.Add(new ValidationError("Api key is required.", nameof(action.ApiKey)));
            }

            if (string.IsNullOrWhiteSpace(action.AppId))
            {
                errors.Add(new ValidationError("Application ID key is required.", nameof(action.AppId)));
            }

            if (string.IsNullOrWhiteSpace(action.IndexName))
            {
                errors.Add(new ValidationError("Index name is required.", nameof(action.IndexName)));
            }

            return(Task.FromResult <IEnumerable <ValidationError> >(errors));
        }
Exemplo n.º 7
0
 public RuleActionDto Visit(AlgoliaAction action)
 {
     return(SimpleMapper.Map(action, new AlgoliaActionDto()));
 }