public void Evaluate_Returns_Error_Missing_Macro()
        {
            //arrange
            var ruleField = new RuleField(
                new Element[]
            {
                new Element(new Guid("{94C5C335-0902-4B45-B528-11B220005DD7}"), new string[] {}),
            }
                );

            _ruleFieldParser.Setup(r => r.Parse(It.IsAny <string>())).Returns(ruleField);
            _emptyRuleValidator.GetText = (s, strings) => "error message";
            _mockField.SetupProperty(f => f.Value, "non empty");

            var item = new Mock <IItem>();

            item.Setup(i => i["text"]).Returns("run [scriptid,Script,,specific] script");

            _mockRepos.Setup(d => d.Get(new Guid("94C5C335-0902-4B45-B528-11B220005DD7"))).Returns(item.Object);

            //act
            var result = _emptyRuleValidator.TestEvaluate();

            //assert
            Assert.That(result, Is.EqualTo(_emptyRuleValidator.MaxValidatorResult));
            Assert.That(_emptyRuleValidator.Text, Is.EqualTo("error message"));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> GetByIdAsync(int id, RuleField fields, CancellationToken cancellationToken)
        {
            var rule = await _ruleManager.FindByIdAsync(id, fields, cancellationToken);

            if (rule == null)
            {
                return(NotFound());
            }
            return(new RuleItemContentResult(rule, this));
        }
Beispiel #3
0
        /// <summary>
        /// Finds a rule with the given primary key value.
        /// </summary>
        /// <param name="id">The primary key for the item to be found.</param>
        /// <param name="fields">The related fields to include in the query results.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <RuleItem> FindByIdAsync(int id, RuleField fields, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var ruleEntity = await Rules.FindAsync(cancellationToken, id);

            if (ruleEntity == null)
            {
                return(null);
            }
            return(LoggingQueries.ToRuleItem(ruleEntity));
        }
Beispiel #4
0
 void AddFieldToCriteria(RuleField field)
 {
     foreach (Criteria c in Criteria)
     {
         if (c.Values.FirstOrDefault(i => i.Field == field) == null)
         {
             c.Values.Add(new Criterion()
             {
                 Field = field, Operation = 1
             });
         }
     }
 }
Beispiel #5
0
 public void AddField(string name, string header)
 {
     if (_Fields.FirstOrDefault(i => i.Name == name) == null)
     {
         RuleField field = new RuleField(_Fields.Count)
         {
             Name   = name,
             Header = header
         };
         _Fields.Add(field);
         AddFieldToCriteria(field);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Finds a collection of rules with the given values.
        /// </summary>
        /// <param name="userId">The user identifier for the item to be found.</param>
        /// <param name="fields">The related fields to include in the query results.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <ListResult <RuleItem> > FindAllAsync(int userId, RuleField fields, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var rules = await Rules.Where(userId).ToArrayAsync(cancellationToken);

            var list = new List <RuleItem>();

            foreach (var rule in rules)
            {
                list.Add(LoggingQueries.ToRuleItem(rule));
            }
            return(ListResult.Create(list));
        }
Beispiel #7
0
 /// <summary>
 /// Finds a collection of rules with the given values.
 /// </summary>
 /// <param name="userId">The user identifier for the item to be found.</param>
 /// <param name="fields">The related fields to include in the query results.</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous operation.
 /// </returns>
 public virtual Task <ListResult <RuleItem> > FindAllAsync(int userId, RuleField fields, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     return(Store.FindAllAsync(userId, fields, cancellationToken));
 }
Beispiel #8
0
 /// <summary>
 /// Finds a rule with the given primary key value.
 /// </summary>
 /// <param name="id">The primary key for the item to be found.</param>
 /// <param name="fields">The related fields to include in the query results.</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous operation.
 /// </returns>
 public virtual Task <RuleItem> FindByIdAsync(int id, RuleField fields, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     return(Store.FindByIdAsync(id, fields, cancellationToken));
 }