本文整理汇总了C#中EventSubscription.GetExecutionStrategy方法的典型用法代码示例。如果您正苦于以下问题:C# EventSubscription.GetExecutionStrategy方法的具体用法?C# EventSubscription.GetExecutionStrategy怎么用?C# EventSubscription.GetExecutionStrategy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventSubscription
的用法示例。
在下文中一共展示了EventSubscription.GetExecutionStrategy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExecutionStrategyDoesNotExecuteActionIfFilterReturnsFalse
public void GetExecutionStrategyDoesNotExecuteActionIfFilterReturnsFalse()
{
bool actionExecuted = false;
var actionDelegate = new Mock<IDelegateReference>();
actionDelegate.SetupGet(d => d.Target).Returns((Action<int>)delegate { actionExecuted = true; });
var filterDelegate = new Mock<IDelegateReference>();
filterDelegate.SetupGet(d => d.Target).Returns((Predicate<int>)delegate { return false; });
var eventSubscription = new EventSubscription<int>(actionDelegate.Object, filterDelegate.Object);
var publishAction = eventSubscription.GetExecutionStrategy();
publishAction.Invoke(new object[] { null });
Assert.That(actionExecuted, Is.False);
}
示例2: GetExecutionStrategyShouldReturnDelegateThatExecutesTheFilterAndThenTheAction
public void GetExecutionStrategyShouldReturnDelegateThatExecutesTheFilterAndThenTheAction()
{
var executedDelegates = new List<string>();
var actionDelegate = new Mock<IDelegateReference>();
actionDelegate.SetupGet(d => d.Target).Returns((Action<object>) delegate { executedDelegates.Add("Action"); });
var filterDelegate = new Mock<IDelegateReference>();
filterDelegate.SetupGet(d => d.Target).Returns((Predicate<object>) delegate { executedDelegates.Add("Filter"); return true; });
var eventSubscription = new EventSubscription<object>(actionDelegate.Object, filterDelegate.Object);
var publishAction = eventSubscription.GetExecutionStrategy();
Assert.That(publishAction, Is.Not.Null);
publishAction.Invoke(null);
Assert.That(executedDelegates.Count, Is.EqualTo(2));
Assert.That(executedDelegates[0], Is.EqualTo("Filter"));
Assert.That(executedDelegates[1], Is.EqualTo("Action"));
}
示例3: StrategyPassesArgumentToDelegates
public void StrategyPassesArgumentToDelegates()
{
string passedArgumentToAction = null;
string passedArgumentToFilter = null;
var actionDelegateReference = new MockDelegateReference((Action<string>)(obj => passedArgumentToAction = obj));
var filterDelegateReference = new MockDelegateReference((Predicate<string>)(obj =>
{
passedArgumentToFilter = obj;
return true;
}));
var eventSubscription = new EventSubscription<string>(actionDelegateReference, filterDelegateReference);
var publishAction = eventSubscription.GetExecutionStrategy();
publishAction.Invoke(new[] { "TestString" });
Assert.AreEqual("TestString", passedArgumentToAction);
Assert.AreEqual("TestString", passedArgumentToFilter);
}
示例4: GetPublishActionDoesNotExecuteActionIfFilterReturnsFalse
public void GetPublishActionDoesNotExecuteActionIfFilterReturnsFalse()
{
bool actionExecuted = false;
var actionDelegateReference = new MockDelegateReference()
{
Target = (Action<int>)delegate { actionExecuted = true; }
};
var filterDelegateReference = new MockDelegateReference((Predicate<int>)delegate
{
return false;
});
var eventSubscription = new EventSubscription<int>(actionDelegateReference, filterDelegateReference);
var publishAction = eventSubscription.GetExecutionStrategy();
publishAction.Invoke(new object[] { null });
Assert.IsFalse(actionExecuted);
}
示例5: GetPublishActionReturnsNullIfFilterIsNull
public void GetPublishActionReturnsNullIfFilterIsNull()
{
var actionDelegateReference = new MockDelegateReference((Action<object>)delegate { });
var filterDelegateReference = new MockDelegateReference((Predicate<object>)delegate { return true; });
var eventSubscription = new EventSubscription<object>(actionDelegateReference, filterDelegateReference);
var publishAction = eventSubscription.GetExecutionStrategy();
Assert.IsNotNull(publishAction);
filterDelegateReference.Target = null;
publishAction = eventSubscription.GetExecutionStrategy();
Assert.IsNull(publishAction);
}
示例6: GetPublishActionReturnsDelegateThatExecutesTheFilterAndThenTheAction
public void GetPublishActionReturnsDelegateThatExecutesTheFilterAndThenTheAction()
{
var executedDelegates = new List<string>();
var actionDelegateReference =
new MockDelegateReference((Action<object>)delegate { executedDelegates.Add("Action"); });
var filterDelegateReference = new MockDelegateReference((Predicate<object>)delegate
{
executedDelegates.Add(
"Filter");
return true;
});
var eventSubscription = new EventSubscription<object>(actionDelegateReference, filterDelegateReference);
var publishAction = eventSubscription.GetExecutionStrategy();
Assert.IsNotNull(publishAction);
publishAction.Invoke(null);
Assert.AreEqual(2, executedDelegates.Count);
Assert.AreEqual("Filter", executedDelegates[0]);
Assert.AreEqual("Action", executedDelegates[1]);
}
示例7: GetPublishActionReturnsNullIfActionIsNull
public void GetPublishActionReturnsNullIfActionIsNull()
{
var actionDelegateReference = new MockDelegateReference((Action<object>)delegate { });
var filterDelegateReference = new MockDelegateReference((Predicate<object>)delegate { return true; });
var eventSubscription = new EventSubscription<object>(actionDelegateReference, filterDelegateReference, null, EventCommunicatorsRelationship.All);
var publishAction = eventSubscription.GetExecutionStrategy();
Assert.NotNull(publishAction);
actionDelegateReference.Target = null;
publishAction = eventSubscription.GetExecutionStrategy();
Assert.Null(publishAction);
}
示例8: GetExecutionStrategyShouldReturnNullIfActionIsNull
public void GetExecutionStrategyShouldReturnNullIfActionIsNull()
{
var actionDelegate = new Mock<IDelegateReference>();
actionDelegate.SetupGet(d => d.Target).Returns((Action<object>)delegate { });
var filterDelegate = new Mock<IDelegateReference>();
filterDelegate.SetupGet(d => d.Target).Returns((Predicate<object>)delegate { return true; });
var eventSubscription = new EventSubscription<object>(actionDelegate.Object, filterDelegate.Object);
var publishAction = eventSubscription.GetExecutionStrategy();
Assert.That(publishAction, Is.Not.Null);
actionDelegate.SetupGet(d => d.Target).Returns(null);
publishAction = eventSubscription.GetExecutionStrategy();
Assert.That(publishAction, Is.Null);
}
示例9: StrategyShouldPassArgumentToDelegates
public void StrategyShouldPassArgumentToDelegates()
{
string passedArgumentToAction = null;
string passedArgumentToFilter = null;
var actionDelegate = new Mock<IDelegateReference>();
actionDelegate.SetupGet(d => d.Target).Returns((Action<string>)(obj => passedArgumentToAction = obj));
var filterDelegate = new Mock<IDelegateReference>();
filterDelegate.SetupGet(d => d.Target).Returns((Predicate<string>)(obj => { passedArgumentToFilter = obj; return true; }));
var eventSubscription = new EventSubscription<string>(actionDelegate.Object, filterDelegate.Object);
var publishAction = eventSubscription.GetExecutionStrategy();
publishAction.Invoke(new[] { "TestString" });
Assert.That(passedArgumentToAction, Is.EqualTo("TestString"));
Assert.That(passedArgumentToFilter, Is.EqualTo("TestString"));
}