public void Fire_OneMatchingFact_FiresFirstRuleAndChainsSecond() { //Arrange var fact1 = new FactType2 {TestProperty = "Valid Value 1", JoinProperty = null}; Session.Insert(fact1); //Act - Assert var ex = Assert.Throws<RuleActionEvaluationException>(() => Session.Fire()); Assert.NotNull(ex.InnerException); Assert.IsInstanceOf<RuleConditionEvaluationException>(ex.InnerException); }
public void Fire_OneMatchingFactErrorInSecondCondition_FiresFirstRuleAndChainsSecond() { //Arrange var fact1 = new FactType2 {TestProperty = "Valid Value 1", JoinProperty = "Valid Value 1"}; Session.Insert(fact1); //Act Session.Fire(); //Assert AssertFiredOnce<ForwardChainingFirstRule>(); AssertFiredOnce<ForwardChainingSecondRule>(); }
public void Query_RuleInsertsSecondFact_TwoFactsInMemory() { //Arrange var fact1 = new FactType2 {TestProperty = "Valid Value 1", JoinProperty = "Valid Value 1"}; Session.Insert(fact1); Session.Fire(); //Act var query = Session.Query<object>(); var facts = query.ToList(); //Assert Assert.AreEqual(2, facts.Count); }
public void Query_OneFact_RetrievesFactFromQuery() { //Arrange var fact1 = new FactType2 {TestProperty = "Valid Value 1", JoinProperty = "Valid Value 1"}; Session.Insert(fact1); //Act var query = Session.Query<object>(); var facts = query.ToList(); //Assert Assert.AreEqual(1, facts.Count); Assert.AreSame(fact1, facts[0]); }
public void Fire_FactsMatchingSecondPartOfOrGroup_FiresOnce() { //Arrange var fact1 = new FactType1 {TestProperty = "Invalid Value 1"}; var fact2 = new FactType2 { TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty }; Session.Insert(fact1); Session.Insert(fact2); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_MatchingNotPatternFactsFirst_DoesNotFire() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Query_QueryFactsByType_OnlyReturnsFactsOfThatType() { //Arrange var fact1 = new FactType2 {TestProperty = "Valid Value 1", JoinProperty = "Valid Value 1"}; Session.Insert(fact1); Session.Fire(); //Act var query = Session.Query<FactType3>(); var facts = query.ToList(); //Assert Assert.AreEqual(1, facts.Count); Assert.AreEqual(fact1.TestProperty, facts[0].JoinProperty); }
public void Fire_MatchingFactsReverseOrder_FiresOnce() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact2); Session.Insert(fact1); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_MatchingNotPatternFactAssertedThenRetracted_FiresOnce() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Retract(fact2); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_MatchingFactOfFirstKindAndMatchingFactOfOtherKind_EachFiresOnce() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); //Act Session.Fire(); //Assert AssertFiredOnce<TwoFactOneCollectionRule>(); AssertFiredOnce<TwoFactOneExistsCheckRule>(); }
public void Fire_OneMatchingFactOfOneKindAndOneOfAnotherKind_FiresSecondRuleDirectlyAndChained() { //Arrange var fact1 = new FactType2 {TestProperty = "Valid Value 1", JoinProperty = "Valid Value 1"}; var fact2 = new FactType3 {TestProperty = "Valid Value 2"}; Session.Insert(fact1); Session.Insert(fact2); //Act Session.Fire(); //Assert AssertFiredOnce<ForwardChainingFirstRule>(); AssertFiredTwice<ForwardChainingSecondRule>(); }
public void Fire_FactOneValidFactTwoAssertedAndRetracted_DoesNotFire() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Retract(fact2); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Fire_FactOneAssertedAndUpdatedFactTwoValid_FiresOnce() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Update(fact1); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_MatchingMainFactAndOnePartOfOrGroupAndGroupFactRetracted_DoesNotFire() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Retract(fact2); //Act Session.Fire(); //Assert AssertDidNotFire(); }
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); Session.Insert(fact2); Session.Insert(fact3); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_MatchingFactsInsertAndFireThenUpdateAndFire_FiresTwice() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); //Act Session.Fire(); Session.Update(fact1); Session.Fire(); //Assert AssertFiredTwice(); }
public void Fire_FactsMatchingBothPartsOfOrGroup_FiresTwice() { //Arrange var fact11 = new FactType1 {TestProperty = "Valid Value 1"}; var fact12 = new FactType1 {TestProperty = "Invalid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact12.TestProperty}; Session.Insert(fact11); Session.Insert(fact12); Session.Insert(fact2); //Act Session.Fire(); //Assert AssertFiredTwice(); }
public void Fire_FactOneValidFactTwoAssertedAndUpdatedToInvalid_DoesNotFire() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2"}; Session.Insert(fact1); Session.Insert(fact2); fact2.TestProperty = "Invalid Value 2"; Session.Update(fact2); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Fire_FactOfOneKindIsInvalidAndTwoOfAnotherKindAreValid_DoesNotFire() { //Arrange var fact1 = new FactType1 {TestProperty = "Invalid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 2", JoinProperty = fact1.TestProperty}; var fact3 = new FactType2 {TestProperty = "Invalid Value 3", JoinProperty = fact1.TestProperty}; var fact4 = new FactType2 {TestProperty = "Valid Value 4", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); Session.Insert(fact4); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Fire_MatchingFactOfTypeOneNotAllMatchingOfTypeTwo_DoesNotFire() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 3", JoinProperty = fact1.TestProperty}; var fact3 = new FactType2 {TestProperty = "Invalid Value 4", JoinProperty = fact1.TestProperty}; var fact4 = new FactType2 {TestProperty = "Valid Value 5", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); Session.Insert(fact4); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Fire_MatchingMainFactAndBothPartsOfOrGroup_FiresTwice() { //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 = "Invalid Value 3", JoinProperty = fact1.TestProperty}; var fact4 = new FactType3 {TestProperty = "Valid Value 4", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); Session.Insert(fact4); //Act Session.Fire(); //Assert AssertFiredTwice(); }
public void Fire_MatchingFactsInsertedThenRetracted_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(fact2); Session.Retract(fact3); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Fire_MatchingFactsInvalidFactOfTypeTwoInsertedRetracted_FiresOnce() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value 3", JoinProperty = fact1.TestProperty}; var fact3 = new FactType2 {TestProperty = "Invalid Value 4", JoinProperty = fact1.TestProperty}; var fact4 = new FactType2 {TestProperty = "Valid Value 5", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); Session.Insert(fact4); Session.Retract(fact3); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_InvalidNotPatternFactsInsertedThenUpdated_DoesNotFire() { //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 = "Invalid Value 3", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); fact2.TestProperty = "Valid Value 2"; Session.Update(fact2); fact3.TestProperty = "Valid Value 3"; Session.Update(fact3); //Act Session.Fire(); //Assert AssertDidNotFire(); }
public void Fire_FactOfOneKindIsValidAndTwoOfAnotherKindAreAssertedThenOneRetracted_FiresOnceWithOneFactInCollection() { //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); Session.Insert(fact2); Session.Insert(fact3); Session.Retract(fact3); //Act Session.Fire(); //Assert AssertFiredOnce(); Assert.AreEqual(1, GetFiredFact<IEnumerable<FactType2>>().Count()); }
public void Fire_TwoFactsOfOneKindAndAggregatedFactsMatchingOneOfTheFacts_FiresOnceWithTwoFactsAndOnceWithEmptyCollection() { //Arrange var fact11 = new FactType1 {TestProperty = "Valid Value 1"}; var fact12 = new FactType1 {TestProperty = "Valid Value 2"}; var fact21 = new FactType2 {TestProperty = "Valid Value 3", JoinProperty = fact11.TestProperty}; var fact22 = new FactType2 {TestProperty = "Valid Value 4", JoinProperty = fact11.TestProperty}; Session.Insert(fact11); Session.Insert(fact12); Session.Insert(fact21); Session.Insert(fact22); //Act Session.Fire(); //Assert AssertFiredTwice(); Assert.AreEqual(2, GetFiredFact<IEnumerable<FactType2>>(0).Count()); Assert.AreEqual(0, GetFiredFact<IEnumerable<FactType2>>(1).Count()); }
public void Fire_OneMatchingFactOfOneKindAndTwoOfAnother_FiresOnceWithTwoFactsInCollection() { //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 = null}; var fact4 = new FactType2 {TestProperty = "Invalid Value 4", JoinProperty = fact1.TestProperty}; var fact5 = new FactType2 {TestProperty = "Valid Value 5", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); Session.Insert(fact4); Session.Insert(fact5); //Act Session.Fire(); //Assert AssertFiredOnce(); Assert.AreEqual(2, GetFiredFact<IEnumerable<FactType2>>().Count()); }
public void Fire_OneMatchingFactOfOneKindAndTwoOfAnotherThenFireThenAnotherMatchingFactThenFire_FiresOnceWithTwoFactsInCollectionThenFiresAgainWithThreeFacts() { //Arrange var fact1 = new FactType1 {TestProperty = "Valid Value 1"}; var fact21 = new FactType2 {TestProperty = "Valid Value 21", JoinProperty = fact1.TestProperty}; var fact22 = new FactType2 {TestProperty = "Valid Value 22", JoinProperty = fact1.TestProperty}; var fact23 = new FactType2 {TestProperty = "Valid Value 23", JoinProperty = fact1.TestProperty}; Session.Insert(fact1); Session.Insert(fact21); Session.Insert(fact22); //Act Session.Fire(); var actualCount1 = GetFiredFact<IEnumerable<FactType2>>().Count(); Session.Insert(fact23); Session.Fire(); var actualCount2 = GetFiredFact<IEnumerable<FactType2>>().Count(); //Assert AssertFiredTwice(); Assert.AreEqual(2, actualCount1); Assert.AreEqual(3, actualCount2); }
public void Fire_TwoMatchingFactsAndOneFactExists_FiresOnce() { //Arrange var fact11 = new FactType1 { TestProperty = "Valid Value 1" }; var fact12 = new FactType1 { TestProperty = "Valid Value 2" }; var fact21 = new FactType2 { TestProperty = "Valid Value 3", JoinProperty = fact11.TestProperty}; Session.Insert(fact11); Session.Insert(fact12); Session.Insert(fact21); //Act Session.Fire(); //Assert AssertFiredOnce(); }
public void Fire_FactOfOneKindIsInvalidThenUpdatedToValidAndTwoOfAnotherKindAreValid_FiresTwiceWithOneFactInEachGroup() { //Arrange var fact1 = new FactType1 {TestProperty = "Invalid Value 1"}; var fact2 = new FactType2 {TestProperty = "Valid Value Group 1", JoinProperty = "Valid Value 1"}; var fact3 = new FactType2 {TestProperty = "Invalid Value", JoinProperty = "Valid Value 1"}; var fact4 = new FactType2 {TestProperty = "Valid Value Group 2", JoinProperty = "Valid Value 1"}; Session.Insert(fact1); Session.Insert(fact2); Session.Insert(fact3); Session.Insert(fact4); fact1.TestProperty = "Valid Value 1"; Session.Update(fact1); //Act Session.Fire(); //Assert AssertFiredTwice(); Assert.AreEqual(1, GetFiredFact<IGrouping<string, FactType2>>(0).Count()); Assert.AreEqual(1, GetFiredFact<IGrouping<string, FactType2>>(1).Count()); }