本文整理汇总了C#中NRules.IntegrationTests.TestAssets.FactType1类的典型用法代码示例。如果您正苦于以下问题:C# FactType1类的具体用法?C# FactType1怎么用?C# FactType1使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FactType1类属于NRules.IntegrationTests.TestAssets命名空间,在下文中一共展示了FactType1类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fire_LowPriorityActivatesTwiceTriggersHighPriority_HighPriorityPreemptsLowPriority
public void Fire_LowPriorityActivatesTwiceTriggersHighPriority_HighPriorityPreemptsLowPriority()
{
//Arrange
var invokedRules = new List<BaseRule>();
var mock = new Mock<Action<BaseRule>>();
mock.Setup(x => x(It.IsAny<BaseRule>())).Callback<BaseRule>(invokedRules.Add);
GetRuleInstance<PriorityLowRule>().InvocationHandler = mock.Object;
GetRuleInstance<PriorityHighRule>().InvocationHandler = mock.Object;
var fact1 = new FactType1 {TestProperty = "Valid Value 1"};
var fact2 = new FactType1 {TestProperty = "Valid Value 2"};
Session.Insert(fact1);
Session.Insert(fact2);
//Act
Session.Fire();
//Assert
//low priority activates twice
//it runs once, activates high priority rule, which preempts low priority and fires once
//low priority fires second time, which activates high priority which also fires second time
Assert.AreEqual(4, invokedRules.Count);
Assert.IsInstanceOf<PriorityLowRule>(invokedRules[0]);
Assert.IsInstanceOf<PriorityHighRule>(invokedRules[1]);
Assert.IsInstanceOf<PriorityLowRule>(invokedRules[2]);
Assert.IsInstanceOf<PriorityHighRule>(invokedRules[3]);
}
示例2: Fire_RuleFires_RaisesRuleFiringEvent
public void Fire_RuleFires_RaisesRuleFiringEvent()
{
//Arrange
var factory = CreateTarget();
var session = factory.CreateSession();
var fact = new FactType1 { TestProperty = "Valid Value" };
session.Insert(fact);
object factorySender = null;
AgendaEventArgs factoryArgs = null;
object sessionSender = null;
AgendaEventArgs sessionArgs = null;
factory.Events.RuleFiringEvent += (sender, args) =>
{
factorySender = sender;
factoryArgs = args;
};
session.Events.RuleFiringEvent += (sender, args) =>
{
sessionSender = sender;
sessionArgs = args;
};
//Act
session.Fire();
//Assert
Assert.AreSame(session, factorySender);
Assert.AreSame(session, sessionSender);
Assert.AreSame(fact, factoryArgs.Facts.Single().Value);
Assert.AreSame(fact, sessionArgs.Facts.Single().Value);
Assert.That(factoryArgs.Rule.Name.Contains("OneFactRule"));
Assert.That(sessionArgs.Rule.Name.Contains("OneFactRule"));
}
示例3: AssertFiredTimes
public void Fire_TwoFactsForOneGroupAndOneForAnotherAndOneInvalidTheInvalidUpdatedToSecondGroup_FiresWithEachFactFromEachGroup()
{
//Arrange
var fact1 = new FactType1 { TestProperty = "Valid Value Group1" };
var fact2 = new FactType1 { TestProperty = "Valid Value Group1" };
var fact3 = new FactType1 { TestProperty = "Valid Value Group2" };
var fact4 = new FactType1 { TestProperty = "Invalid Value" };
Session.Insert(fact1);
Session.Insert(fact2);
Session.Insert(fact3);
Session.Insert(fact4);
fact4.TestProperty = "Valid Value Group2";
Session.Update(fact4);
//Act
Session.Fire();
//Assert
AssertFiredTimes(4);
Assert.AreEqual(fact1, GetFiredFact<FactType1>(0));
Assert.AreEqual(fact2, GetFiredFact<FactType1>(1));
Assert.AreEqual(fact3, GetFiredFact<FactType1>(2));
Assert.AreEqual(fact4, GetFiredFact<FactType1>(3));
}
示例4: Fire_LowPriorityActivatesTwiceTriggersHighPriority_HighPriorityPreemptsLowPriority
public void Fire_LowPriorityActivatesTwiceTriggersHighPriority_HighPriorityPreemptsLowPriority()
{
//Arrange
var invokedRules = new List<string>();
Session.Events.RuleFiredEvent += (sender, args) => invokedRules.Add(args.Rule.Name);
var fact1 = new FactType1 {TestProperty = "Valid Value 1"};
var fact2 = new FactType1 {TestProperty = "Valid Value 2"};
Session.Insert(fact1);
Session.Insert(fact2);
//Act
Session.Fire();
//Assert
//low priority activates twice
//it runs once, activates high priority rule, which preempts low priority and fires once
//low priority fires second time, which activates high priority which also fires second time
Assert.AreEqual(4, invokedRules.Count);
Assert.AreEqual("NRules.IntegrationTests.TestRules.PriorityLowRule", invokedRules[0]);
Assert.AreEqual("NRules.IntegrationTests.TestRules.PriorityHighRule", invokedRules[1]);
Assert.AreEqual("NRules.IntegrationTests.TestRules.PriorityLowRule", invokedRules[2]);
Assert.AreEqual("NRules.IntegrationTests.TestRules.PriorityHighRule", invokedRules[3]);
}
示例5: Fire_DefaultResolver_Throws
public void Fire_DefaultResolver_Throws()
{
//Arrange
var fact = new FactType1 {TestProperty = "Valid Value 1"};
Session.Insert(fact);
//Act - Assert
Assert.Throws<InvalidOperationException>(() => Session.Fire());
}
示例6: Fire_DuplicateInsert_Throws
public void Fire_DuplicateInsert_Throws()
{
//Arrange
var fact = new FactType1 {TestProperty = "Valid Value 1"};
//Act - Assert
Session.Insert(fact);
Assert.Throws<ArgumentException>(() => Session.Insert(fact));
}
示例7: Fire_MatchingFact_FiresOnce
public void Fire_MatchingFact_FiresOnce()
{
//Arrange
var fact = new FactType1 {TestProperty = "Valid value"};
Session.Insert(fact);
//Act
Session.Fire();
//Assert
AssertFiredOnce();
}
示例8: Fire_ConditionDoesNotMatch_DoesNotFire
public void Fire_ConditionDoesNotMatch_DoesNotFire()
{
//Arrange
var fact = new FactType1 {TestProperty = "Invalid Value 1"};
Session.Insert(fact);
//Act
Session.Fire();
//Assert
AssertDidNotFire();
}
示例9: Fire_MatchingNotPatternFact_DoesNotFire
public void Fire_MatchingNotPatternFact_DoesNotFire()
{
//Arrange
var fact1 = new FactType1 {TestProperty = "Valid Value 1"};
Session.Insert(fact1);
//Act
Session.Fire();
//Assert
AssertDidNotFire();
}
示例10: Fire_MatchingMainFactAndNoneOfOrGroup_DoesNotFire
public void Fire_MatchingMainFactAndNoneOfOrGroup_DoesNotFire()
{
//Arrange
var fact1 = new FactType1 {TestProperty = "Valid Value 1"};
Session.Insert(fact1);
//Act
Session.Fire();
//Assert
AssertDidNotFire();
}
示例11: Fire_MatchingFactOfTypeOneNothigOfTypeTwo_FiresOnce
public void Fire_MatchingFactOfTypeOneNothigOfTypeTwo_FiresOnce()
{
//Arrange
var fact1 = new FactType1 { TestProperty = "Valid Value 1" };
Session.Insert(fact1);
//Act
Session.Fire();
//Assert
AssertFiredOnce();
}
示例12: Fire_MatchingFactAndNoFactsMatchingNotPattern_FiresOnce
public void Fire_MatchingFactAndNoFactsMatchingNotPattern_FiresOnce()
{
//Arrange
var fact1 = new FactType1 {TestProperty = "Valid Value 1"};
Session.Insert(fact1);
//Act
Session.Fire();
//Assert
AssertFiredOnce();
}
示例13: Fire_OneMatchingFact_FiresOnceWithOneFactInCollection
public void Fire_OneMatchingFact_FiresOnceWithOneFactInCollection()
{
//Arrange
var fact1 = new FactType1 {TestProperty = "Valid Value 1"};
Session.Insert(fact1);
//Act
Session.Fire();
//Assert
AssertFiredOnce();
Assert.AreEqual(1, GetFiredFact<IEnumerable<FactType1>>().Count());
}
示例14: Fire_OneMatchingFactAssertedAndRetracted_DoesNotFire
public void Fire_OneMatchingFactAssertedAndRetracted_DoesNotFire()
{
//Arrange
var fact = new FactType1 {TestProperty = "Valid Value 1"};
Session.Insert(fact);
Session.Retract(fact);
//Act
Session.Fire();
//Assert
AssertDidNotFire();
}
示例15: Fire_ErrorInActionErrorHandler_DoesNotThrow
public void Fire_ErrorInActionErrorHandler_DoesNotThrow()
{
//Arrange
Session.Events.ActionFailedEvent += (sender, args) => args.IsHandled = true;
var fact = new FactType1 { TestProperty = "Valid value" };
Session.Insert(fact);
GetRuleInstance<OneFactRule>().Action = null;
//Act - Assert
Assert.DoesNotThrow(() => Session.Fire());
}