public void LoadCustomOperation()
        {
            var helper          = new OperationHelper();
            var operationsCount = helper.Operations.Count();
            var operations      = new List <IOperation> {
                new ThisDay()
            };

            helper.LoadOperations(operations);

            Assert.That(helper.Operations.Select(o => o.Name), Does.Contain(operations.Single().Name));
            Assert.That(helper.Operations.Count, Is.EqualTo(operationsCount + 1));

            OperationHelper.LoadDefaultOperations();
        }
        public void OverwritingOperations()
        {
            var helper          = new OperationHelper();
            var operationsCount = helper.Operations.Count();
            var operations      = new List <IOperation> {
                new EqualTo()
            };

            helper.LoadOperations(operations, true);

            Assert.That(helper.Operations.Where(o => o.Name == "EqualTo").Count, Is.EqualTo(2));
            Assert.That(helper.Operations.First(o => o.Name == "EqualTo" && o.Active).GetType().Namespace, Is.EqualTo("ExpressionBuilder.Test.CustomOperations"));
            Assert.That(helper.Operations.Count, Is.EqualTo(operationsCount + 1));

            OperationHelper.LoadDefaultOperations();
        }
        public void LoadingSameCustomOperationTwice_Failure()
        {
            var helper          = new OperationHelper();
            var operationsCount = helper.Operations.Count();
            var operations      = new List <IOperation> {
                new ThisDay(), new ThisDay(), new EqualTo()
            };

            helper.LoadOperations(operations);

            Assert.That(helper.Operations.Where(o => o.Name == operations.First().Name).Count, Is.EqualTo(1));
            Assert.That(helper.Operations.Single(o => o.Name == "EqualTo").GetType().Namespace, Is.EqualTo("ExpressionBuilder.Operations"));
            Assert.That(helper.Operations.Count, Is.EqualTo(operationsCount + 1));

            OperationHelper.LoadDefaultOperations();
        }
        public void GetOverwrittenOperationByName()
        {
            var helper     = new OperationHelper();
            var operations = new List <IOperation> {
                new EqualTo()
            };

            helper.LoadOperations(operations, true);

            var operation = helper.GetOperationByName("EqualTo");

            Assert.That(operation.Name, Is.EqualTo("EqualTo"));
            Assert.That(operation.Active, Is.True);
            Assert.That(operation.GetType().Namespace, Is.EqualTo("ExpressionBuilder.Test.CustomOperations"));

            OperationHelper.LoadDefaultOperations();
        }
Esempio n. 5
0
 /// <summary>
 /// Loads a list of custom operations into the <see cref="Operations"></see> list.
 /// </summary>
 /// <param name="operations">List of operations to load.</param>
 /// <param name="overloadExisting">Specifies that any matching pre-existing operations should be replaced by the ones from the list. (Useful to overwrite the default operations)</param>
 public static void LoadOperations(List <IOperation> operations, bool overloadExisting = false)
 {
     _operationHelper.LoadOperations(operations, overloadExisting);
 }