public void GetExecutionStrategyGeneric_NullFilter_ShouldReturnNull() { // Prepare var delegateActionReferenceMock = new Mock <IDelegateReference>(); delegateActionReferenceMock.Setup(x => x.Delegate).Returns((Action <int>) delegate { }); var delegateFilterReferenceMock = new Mock <IDelegateReference>(); delegateFilterReferenceMock.Setup(x => x.Delegate).Returns((Predicate <int>) delegate { return(false); }); var eventSubscription = new EventSubscription <int>(delegateActionReferenceMock.Object, delegateFilterReferenceMock.Object); Action <object[]>?publishAction; // Act publishAction = eventSubscription.GetExecutionStrategy(); // Assert Assert.NotNull(publishAction); // Act delegateFilterReferenceMock.Setup(x => x.Delegate).Returns(null); publishAction = eventSubscription.GetExecutionStrategy(); // Assert Assert.Null(publishAction); }
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]); }
public void GetPublishActionReturnsNullIfActionIsNullNonGeneric() { var actionDelegateReference = new MockDelegateReference((Action) delegate { }); var eventSubscription = new EventSubscription(actionDelegateReference); var publishAction = eventSubscription.GetExecutionStrategy(); Assert.NotNull(publishAction); actionDelegateReference.Target = null; publishAction = eventSubscription.GetExecutionStrategy(); Assert.Null(publishAction); }
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); }
public void GetExecutionStrategy_Should_Return_Null_If_Action_Is_Null() { 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.NotNull(publishAction); actionDelegate.SetupGet(d => d.Target).Returns(null); publishAction = eventSubscription.GetExecutionStrategy(); Assert.Null(publishAction); }
public void GetActionNonGeneric_NullAction_ShouldReturnNull() { // Prepare var delegateActionReferenceMock = new Mock <IDelegateReference>(); delegateActionReferenceMock.Setup(x => x.Delegate).Returns((Action) delegate { }); var eventSubscription = new EventSubscription(delegateActionReferenceMock.Object); Action <object[]>?publishAction; // Act publishAction = eventSubscription.GetExecutionStrategy(); // Assert Assert.NotNull(publishAction); // Act delegateActionReferenceMock.Setup(x => x.Delegate).Returns(null); publishAction = eventSubscription.GetExecutionStrategy(); // Assert Assert.Null(publishAction); }
public void GetExecutionStrategy_WithAction_ReturnsNotNull() { // arrange Action <object> action = o => {}; Predicate <object> filter = o => true; var target = new EventSubscription <object>(action, filter); // act Action <object> actual = target.GetExecutionStrategy(); //assert Assert.NotNull(actual); }
public void GetExecutionStrategyGeneric_FilterReturnsFalse_ShouldNotExecute() { // Prepare var actionExecuted = false; var delegateActionReferenceMock = new Mock <IDelegateReference>(); delegateActionReferenceMock.Setup(x => x.Delegate).Returns((Action <int>)(obj => actionExecuted = true)); var delegateFilterReferenceMock = new Mock <IDelegateReference>(); delegateFilterReferenceMock.Setup(x => x.Delegate).Returns((Predicate <int>) delegate { return(false); }); var eventSubscription = new EventSubscription <int>(delegateActionReferenceMock.Object, delegateFilterReferenceMock.Object); var publishAction = eventSubscription.GetExecutionStrategy(); // Act publishAction?.Invoke(new object[] { null ! });
public void GetExecutionStrategy_WithFilterReturnsFalse_WillNotExecuteOriginalAction() { // arrange bool executed = false; Action <object> action = o => executed = true; Predicate <object> filter = o => false; var target = new EventSubscription <object>(action, filter); // act Action <object> actual = target.GetExecutionStrategy(); actual(new object()); //assert Assert.False(executed); }
public void GetExecutionStrategy_Does_Not_Execute_Action_If_Filter_Returns_False() { 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.False(actionExecuted); }
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); }
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); }
public void Strategy_Should_Passe_Argument_To_Delegates() { 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.Equal("TestString", passedArgumentToAction); Assert.Equal("TestString", passedArgumentToFilter); }
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); }
public void GetExecutionStrategyGeneric_PassArgument_ShouldPassArgumentToDelegates() { // Prepare string?passedArgumentToAction = null; string?passedArgumentToFilter = null; var delegateActionReferenceMock = new Mock <IDelegateReference>(); delegateActionReferenceMock.Setup(x => x.Delegate).Returns((Action <string>)(obj => { passedArgumentToAction = obj; })); var delegateFilterReferenceMock = new Mock <IDelegateReference>(); delegateFilterReferenceMock.Setup(x => x.Delegate).Returns((Predicate <string>)(obj => { passedArgumentToFilter = obj; return(true); })); var eventSubscription = new EventSubscription <string>(delegateActionReferenceMock.Object, delegateFilterReferenceMock.Object); var publishAction = eventSubscription.GetExecutionStrategy(); // Act publishAction?.Invoke(new[] { "TestString" }); // Assert Assert.Equal("TestString", passedArgumentToAction); Assert.Equal("TestString", passedArgumentToFilter); }
public void GetExecutionStrategy_Should_Return_Delegate_That_Executes_The_Filter_And_Then_The_Action() { 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.NotNull(publishAction); publishAction.Invoke(null); Assert.Equal(2, executedDelegates.Count); Assert.Equal("Filter", executedDelegates[0]); Assert.Equal("Action", executedDelegates[1]); }
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")); }
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); }
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); }
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); }
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]); }
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); }
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); }
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")); }