public void Eval_GivenComposedConditionNodeWithAndOperatorAndUnknownConditionNodeWithSearchMode_ThrowsNotSupportedException() { // Arrange StubConditionNode <ConditionType> condition1 = new StubConditionNode <ConditionType>(); StringConditionNode <ConditionType> condition2 = new StringConditionNode <ConditionType>(ConditionType.IsoCurrency, Operators.NotEqual, "SGD"); ComposedConditionNode <ConditionType> composedConditionNode = new ComposedConditionNode <ConditionType>( LogicalOperators.Or, new IConditionNode <ConditionType>[] { condition1, condition2 }); IEnumerable <Condition <ConditionType> > conditions = new[] { new Condition <ConditionType> { Type = ConditionType.IsoCurrency, Value = "SGD" }, new Condition <ConditionType> { Type = ConditionType.IsoCountryCode, Value = "PT" } }; EvaluationOptions evaluationOptions = new EvaluationOptions { MatchMode = MatchModes.Search, ExcludeRulesWithoutSearchConditions = true }; Mock <IDeferredEval> mockDeferredEval = new Mock <IDeferredEval>(); mockDeferredEval.SetupSequence(x => x.GetDeferredEvalFor(It.IsAny <IValueConditionNode <ConditionType> >(), It.Is <MatchModes>(mm => mm == MatchModes.Exact))) .Returns(() => { return((c) => false); }) .Returns(() => { return((c) => true); }) .Throws(new NotImplementedException("Shouldn't have gotten any more deferred evals.")); ConditionsEvalEngine <ConditionType> sut = new ConditionsEvalEngine <ConditionType>(mockDeferredEval.Object); // Act NotSupportedException notSupportedException = Assert.Throws <NotSupportedException>(() => sut.Eval(composedConditionNode, conditions, evaluationOptions)); // Assert notSupportedException.Should().NotBeNull(); notSupportedException.Message.Should().Be("Unsupported condition node: 'StubConditionNode`1'."); mockDeferredEval.Verify(x => x.GetDeferredEvalFor(It.IsAny <IValueConditionNode <ConditionType> >(), It.Is <MatchModes>(mm => mm == MatchModes.Exact)), Times.Exactly(0)); }
public void AddNotSupported() { // arrange var manager = new WrapperObjectManager <object>( Mock.Of <ITaskObjectCollection <object> >(), _ => new object()); // act NotSupportedException ex = Capture <NotSupportedException>( () => manager.Add(Mock.Of <ObjectCreator <object> >())); // assert ex.Should().NotBeNull(); }
public void GetOperatorEvalStrategy_GivenUnknownOperator_ThrowsNotSupportedException() { // Arrange Operators expectedOperator = (Operators)(-1); OperatorEvalStrategyFactory sut = new OperatorEvalStrategyFactory(); // Act NotSupportedException notSupportedException = Assert.Throws <NotSupportedException>(() => sut.GetOperatorEvalStrategy(expectedOperator)); // Assert notSupportedException.Should().NotBeNull(); notSupportedException.Message.Should().Be("Operator evaluation is not supported for operator '-1'."); }
public void GetDeferredEvalFor_GivenUnknownConditionNodeType_ThrowsNotSupportedException() { // Arrange Mock <IValueConditionNode <ConditionType> > mockValueConditionNode = new Mock <IValueConditionNode <ConditionType> >(); Mock <IOperatorEvalStrategyFactory> mockOperatorEvalStrategyFactory = new Mock <IOperatorEvalStrategyFactory>(); MatchModes matchMode = MatchModes.Exact; RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); DeferredEval sut = new DeferredEval(mockOperatorEvalStrategyFactory.Object, rulesEngineOptions); // Act NotSupportedException notSupportedException = Assert.Throws <NotSupportedException>(() => sut.GetDeferredEvalFor(mockValueConditionNode.Object, matchMode)); // Assert notSupportedException.Should().NotBeNull(); notSupportedException.Message.Should().Be($"Unsupported value condition node: '{mockValueConditionNode.Object.GetType().Name}'."); }
public void Eval_GivenComposedConditionNodeWithEvalOperator_ThrowsNotSupportedException() { // Arrange BooleanConditionNode <ConditionType> condition1 = new BooleanConditionNode <ConditionType>(ConditionType.IsVip, Operators.Equal, true); StringConditionNode <ConditionType> condition2 = new StringConditionNode <ConditionType>(ConditionType.IsoCurrency, Operators.NotEqual, "SGD"); ComposedConditionNode <ConditionType> composedConditionNode = new ComposedConditionNode <ConditionType>( LogicalOperators.Eval, new IConditionNode <ConditionType>[] { condition1, condition2 }); IEnumerable <Condition <ConditionType> > conditions = new[] { new Condition <ConditionType> { Type = ConditionType.IsoCurrency, Value = "SGD" }, new Condition <ConditionType> { Type = ConditionType.IsVip, Value = true } }; EvaluationOptions evaluationOptions = new EvaluationOptions { MatchMode = MatchModes.Exact }; Mock <IDeferredEval> mockDeferredEval = new Mock <IDeferredEval>(); ConditionsEvalEngine <ConditionType> sut = new ConditionsEvalEngine <ConditionType>(mockDeferredEval.Object); // Act NotSupportedException notSupportedException = Assert.Throws <NotSupportedException>(() => sut.Eval(composedConditionNode, conditions, evaluationOptions)); // Assert notSupportedException.Should().NotBeNull(); notSupportedException.Message.Should().Be("Unsupported logical operator: 'Eval'."); mockDeferredEval.Verify(x => x.GetDeferredEvalFor(It.IsAny <IValueConditionNode <ConditionType> >(), It.Is <MatchModes>(mm => mm == MatchModes.Exact)), Times.Never()); }
public void Eval_GivenComposedConditionNodeWithUnknownConditionNode_ThrowsNotSupportedException() { // Arrange Mock <IConditionNode <ConditionType> > mockConditionNode = new Mock <IConditionNode <ConditionType> >(); IEnumerable <Condition <ConditionType> > conditions = new[] { new Condition <ConditionType> { Type = ConditionType.IsoCurrency, Value = "SGD" }, new Condition <ConditionType> { Type = ConditionType.IsVip, Value = true } }; EvaluationOptions evaluationOptions = new EvaluationOptions { MatchMode = MatchModes.Exact }; Mock <IDeferredEval> mockDeferredEval = new Mock <IDeferredEval>(); ConditionsEvalEngine <ConditionType> sut = new ConditionsEvalEngine <ConditionType>(mockDeferredEval.Object); // Act NotSupportedException notSupportedException = Assert.Throws <NotSupportedException>(() => sut.Eval(mockConditionNode.Object, conditions, evaluationOptions)); // Assert notSupportedException.Should().NotBeNull(); notSupportedException.Message.Should().Be($"Unsupported condition node: '{mockConditionNode.Object.GetType().Name}'."); mockDeferredEval.Verify(x => x.GetDeferredEvalFor(It.IsAny <IValueConditionNode <ConditionType> >(), It.Is <MatchModes>(mm => mm == MatchModes.Exact)), Times.Never()); }