Esempio n. 1
0
        public void DefaultGroupValue_Get_NotExisting()
        {
            string pointerName = "grouppointername";
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            DeclaredValuePointer <G> groupPointer  = new DeclaredValuePointer <G>("group", valueProvider.Null)
            {
                Identifier = pointerName
            };
            List <DeclaredValuePointer <G> > groupPointers = new List <DeclaredValuePointer <G> >()
            {
                new DeclaredValuePointer <G>("group"), groupPointer, new DeclaredValuePointer <G>("group")
            };
            Dictionary <string, int> pointerMap = new Dictionary <string, int> {
                { pointerName, 1 }
            };
            G groupState = Mock.Of <G>(m => m.GroupPointers == groupPointers && m.PointerMap == pointerMap);
            DefaultStringValue <G> key = new DefaultStringValue <G>("otherpointer");


            DefaultGroupValue <G>  sut = new DefaultGroupValue <G>(groupState);
            EngineRuntimeException ex  = Assert.Throws <EngineRuntimeException>(() =>
            {
                sut.Get(key, true, valueProvider);
            });

            Assert.Equal("Cannot create group pointer using accessor", ex.Message);
        }
Esempio n. 2
0
        public void DefaultCollectionValue_Add_NonMapCollection()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > firstValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
            };
            Dictionary <IValuable <G>, ValuePointer <G> > secondValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };
            DefaultCollectionValue <G> otherCollection = new DefaultArrayMapValue <G>(secondValues, valueProvider) as DefaultCollectionValue <G>;

            DefaultArrayMapValue <G> sut       = new DefaultArrayMapValue <G>(firstValues, valueProvider);
            EngineRuntimeException   exception = Assert.Throws <EngineRuntimeException>(() => sut.Add(otherCollection, valueProvider) as DefaultCollectionValue <G>);

            Assert.Equal("Invalid values for addition", exception.Message);
        }
Esempio n. 3
0
        public void Log(RuntimeException runtimeError)
        {
            if (runtimeError == null)
            {
                return;
            }

            try
            {
                using (var ctx = SuiteEntitiesUtility.GetODataValidationSuiteEntities())
                {
                    var runtimeException = EngineRuntimeException.CreateEngineRuntimeException(
                        runtimeError.JobId,
                        runtimeError.RuleName,
                        runtimeError.Timestamp,
                        runtimeError.DestinationEndpoint,
                        0);
                    runtimeException.Message    = runtimeError.Message;
                    runtimeException.StackTrace = runtimeError.StackTrace;
                    runtimeException.Detail     = runtimeError.Detail;

                    ctx.AddToEngineRuntimeExceptions(runtimeException);
                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (!RuleEngine.Common.ExceptionHelper.IsCatchableExceptionType(ex))
                {
                    throw;
                }

                // swallows the exception since logging is considered low-prio task
            }
        }
Esempio n. 4
0
        public void DefaultValueProvider_GetAsValue_WithObject_Throws()
        {
            object data = new object();

            DefaultValueProvider <G> sut = new DefaultValueProvider <G>();
            EngineRuntimeException   ex  = Assert.Throws <EngineRuntimeException>(() => sut.GetAsValue(data));

            Assert.Equal("No implementation for externals", ex.Message);
        }
Esempio n. 5
0
        public void DefaultCollectionValue_Minus_MapCollection()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            IValuable <G>            sharedValue1  = Mock.Of <IValuable <G> >();
            IValuable <G>            sharedValue2  = Mock.Of <IValuable <G> >();
            Dictionary <IValuable <G>, ValuePointer <G> > firstValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(3), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(4), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(2), new ValuePointer <G> {
                      Value = sharedValue2
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = sharedValue1
                  } }
            };
            Dictionary <IValuable <G>, ValuePointer <G> > secondValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(0), new ValuePointer <G> {
                      Value = sharedValue2
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = sharedValue1
                  } },
                { new DefaultIntValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };
            DefaultArrayMapValue <G> otherCollection = new DefaultArrayMapValue <G>(secondValues, valueProvider);

            DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(firstValues, valueProvider);

            EngineRuntimeException exception = Assert.Throws <EngineRuntimeException>(() => sut.Minus(otherCollection, valueProvider));

            Assert.Equal("Invalid values for subtraction", exception.Message);
        }
Esempio n. 6
0
        public void InstructionExecutor_Execute_EngineRuntimeException_RethrownAsNewEngineRuntimeException()
        {
            InstructionExecutionBody <G> executionBody        = Mock.Of <InstructionExecutionBody <G> >();
            InstructionExecutionBody <G> specialExecutionBody = Mock.Of <InstructionExecutionBody <G> >();
            int    sourcePosition   = 20;
            string exceptionMessage = "Engine exception";
            EngineRuntimeException thrownException    = new EngineRuntimeException(exceptionMessage);
            Instruction <G>        specialInstruction = TestInstructionProvider <G> .GetInstruction(InstructionCode.NON, null, sourcePosition, false, specialExecutionBody);

            Group <G> group = new Group <G>
            {
                Instructions = new[]
                {
                    TestInstructionProvider <G> .GetInstruction(InstructionCode.NON, null, null, false, executionBody),
                    TestInstructionProvider <G> .GetInstruction(InstructionCode.NON, null, null, false, executionBody),
                    TestInstructionProvider <G> .GetInstruction(InstructionCode.NON, null, null, false, executionBody),
                    specialInstruction,
                    TestInstructionProvider <G> .GetInstruction(InstructionCode.NON, null, null, false, executionBody),
                    TestInstructionProvider <G> .GetInstruction(InstructionCode.NON, null, null, false, executionBody),
                    TestInstructionProvider <G> .GetInstruction(InstructionCode.NON, null, null, false, executionBody)
                }
            };
            G groupState = Mock.Of <G>(m => m.Group == group);

            Mock.Get(specialExecutionBody).Setup(m => m(It.IsAny <IInstructionExecutor <G> >(), It.IsAny <E>(), It.IsAny <object[]>(), It.IsAny <StackList <ValuePointer <G> > >(), It.IsAny <StackList <StackValuePointer <G> > >())).Callback((IInstructionExecutor <G> ie, ExecutionState <G> e, object[] payload, StackList <ValuePointer <G> > stackRegister, StackList <StackValuePointer <G> > stackPointers) =>
            {
                throw thrownException;
            });
            E executionState = new ExecutionState <G>(groupState);


            InstructionExecutor <G> sut = new InstructionExecutor <G>();
            EngineRuntimeException  ex  = Assert.Throws <EngineRuntimeException>(() => sut.Execute(executionState));

            Assert.Equal(exceptionMessage, ex.Message);
            Assert.Equal(thrownException, ex.InnerException);
            Assert.Equal(sourcePosition, ex.Position);
        }