public void Fire_MatchingFactOfTypeOneMultipleOfTypeTwo_FiresOnce() { //Arrange var fact1 = new FactType1 { TestProperty = "Valid Value 1" }; var fact2 = new FactType2 { TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty }; var fact3 = new FactType2 { TestProperty = "Valid Value 3", JoinProperty = fact1.TestProperty }; Session.Insert(fact1); var facts = new[] { fact2, fact3 }; Session.InsertAll(facts); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_MatchingFactsTwoInsertedThenSecondRetracted_DoesNotFire() { //Arrange var fact1 = new FactType1 { TestProperty = "Valid Value 1" }; var fact2 = new FactType2 { TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty }; var fact3 = new FactType3 { TestProperty = "Valid Value 3", JoinProperty = fact1.TestProperty }; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); Session.Retract(fact3); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Fire_MatchingFactsSecondPart_FactsInContext() { //Arrange var fact1 = new FactType1 { TestProperty = "Valid Value 1" }; var fact2 = new FactType2 { TestProperty = "Invalid Value 2", JoinProperty = fact1.TestProperty }; var fact3 = new FactType3 { TestProperty = "Valid Value 3", JoinProperty = fact1.TestProperty }; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); IFactMatch[] matches = null; GetRuleInstance <TestRule>().Action = ctx => { matches = ctx.Facts.ToArray(); }; //Act Session.Fire(); //Assert AssertFiredOnce(); Assert.Equal(3, matches.Length); Assert.Equal("fact1", matches[0].Declaration.Name); Assert.Same(fact1, matches[0].Value); Assert.Equal("fact2", matches[1].Declaration.Name); Assert.Same(fact2, matches[1].Value); Assert.Equal("fact3", matches[2].Declaration.Name); Assert.Same(fact3, matches[2].Value); }
public void Fire_Rule_RaisesActionExpressionEvalEvent() { //Arrange var factory = CreateTarget(); var session = factory.CreateSession(); var handledEvents = new List <RhsExpressionEventArgs>(); factory.Events.RhsExpressionEvaluatedEvent += (sender, args) => { handledEvents.Add(args); }; var fact1 = new FactType1 { TestProperty = "Valid Value" }; var fact2 = new FactType2 { JoinProperty = "Valid Value", SelectProperty = "1234567890A" }; //Act session.Insert(fact1); session.Insert(fact2); session.Fire(); //Assert Assert.Single(handledEvents); var eventArgs = handledEvents[0]; Assert.Collection(eventArgs.Arguments, x => Assert.Equal(fact1, x), x => Assert.Equal("1234567890A", x)); Assert.Collection(eventArgs.Match.Facts.Select(x => x.Value), x => Assert.Equal(fact1, x), x => Assert.Equal("1234567890A", x), x => Assert.Equal(11, x)); Assert.Null(eventArgs.Result); Assert.Null(eventArgs.Exception); Assert.Equal("Test Rule", eventArgs.Match.Rule.Name); Assert.Equal(MatchTrigger.Created, eventArgs.Match.Trigger); }
public void Fire_FailedAssertThenAssertForSameJoin_Fires() { //Arrange Session.Events.AggregateFailedEvent += (sender, args) => args.IsHandled = true; var fact11 = new FactType1 { TestProperty = "Valid Value 1" }; Session.Insert(fact11); GetRuleInstance <TestRule>().Grouping = ThrowGrouping; var fact21 = new FactType2 { GroupProperty = "Group1", JoinProperty = "Valid Value 1" }; Session.Insert(fact21); GetRuleInstance <TestRule>().Grouping = x => x.GroupProperty; var fact22 = new FactType2 { GroupProperty = "Group1", JoinProperty = "Valid Value 1" }; Session.Insert(fact22); //Act Session.Fire(); //Assert AssertFiredOnce(); var group = GetFiredFact <IEnumerable <FactType2> >(); Assert.Equal(2, group.Count()); }
private static string GetKey(FactType1 fact1, FactType2 fact2) { return($"{fact1.GroupKey}|{fact2.GroupKey}"); }
public GroupElement(FactType1 fact1, FactType2 fact2) { TestProperty = $"{fact1.TestProperty}|{fact2.TestProperty}"; }
public FactProjection(FactType1 fact1, FactType2 fact2) { Value = $"{fact1.TestProperty}|{fact2.TestProperty}"; }
private bool Condition(FactType2 f2, FactType3 f3, FactType0 f0) { return(true); }
private bool Condition(FactType0 f0, FactType1 f1, FactType2 f2) { return(true); }
private void Action(FactType2 f2, FactType0 f0, FactType3 f3) { }
public CalculatedFact3(FactType1 fact1, FactType2 fact2) { Value = $"{fact1.TestProperty}|{fact2.TestProperty}"; }
private static FactType2 Update(FactType1 fact1, FactType2 fact2) { fact2.TestProperty = fact1.ChainProperty; fact2.UpdateCount++; return(fact2); }
private static FactType2 TransformFact(FactType2 fact) { return(fact); }
private bool ValidGroup(FactType1 fact1, FactType2 fact21, FactType2 fact22, IGrouping <string, FactType3> group) { fact1.EvalCount++; return(group.Key == fact1.JoinProperty); }
private static string GetValue(FactType1 fact1, FactType2 fact2) { return(fact1 != null ? fact1.Value : fact2.Value); }
public CalculatedFact4(FactType1 fact1, FactType2 fact2) { Value = fact1.Counter + fact2.Counter; }