public EventCommunicatorsRelationship RecognizeRelationship(EventCommunicatorAddress other) { if(other == null) throw new ArgumentNullException("other"); return recognizeRelationship(other); }
/// <summary> /// Calls all the execution strategies exposed by the list of <see cref="IEventSubscription"/>. /// </summary> /// <param name="publisherAddress">Specfied publisher address, can be null</param> /// <param name="arguments">The arguments that will be passed to the listeners.</param> /// <remarks>Before executing the strategies, this class will prune all the subscribers from the /// list that return a <see langword="null" /> <see cref="Action{T}"/> when calling the /// <see cref="IEventSubscription.GetExecutionStrategy"/> method.</remarks> protected virtual void InternalPublish(EventCommunicatorAddress publisherAddress, EventCommunicatorsRelationship publishTo, params object[] arguments) { List<Action<object[]>> executionStrategies = pruneAndReturnStrategies(publisherAddress, publishTo); foreach (var executionStrategy in executionStrategies) { executionStrategy(arguments); } }
public void ChildCommunicatorAddressCreated() { var communicatorParent = new MockParentEventCommunicator(); var communicatorChild = new MockChildEventCommunicator(communicatorParent); var addressChild = new EventCommunicatorAddress(communicatorChild); Assert.False(string.IsNullOrEmpty(addressChild.AddressString)); }
public static string CreateStringAddress(EventCommunicatorAddress address) { var builder = new StringBuilder(); for (var currNode = address._innerAddress.First; currNode != null; currNode = currNode.Next) { builder.Append(currNode.Value); if (currNode.Next != null) builder.Append("@"); } return builder.ToString(); }
public void GetRelationshipBetweenChildAndChild() { var communicatorParent = new MockParentEventCommunicator(); var communicatorChild1 = new MockChildEventCommunicator(communicatorParent); var communicatorChild2 = new MockChildEventCommunicator(communicatorParent); var addressChild1 = new EventCommunicatorAddress(communicatorChild1); var addressChild2 = new EventCommunicatorAddress(communicatorChild2); var relationshipChild2ToChild1 = addressChild1.RecognizeRelationship(addressChild2); var relationshipChild1ToChild2 = addressChild2.RecognizeRelationship(addressChild1); Assert.Equal(EventCommunicatorsRelationship.Sibling, relationshipChild2ToChild1); Assert.Equal(EventCommunicatorsRelationship.Sibling, relationshipChild1ToChild2); }
public void GetRelationshipBetweenChildAndThreeLevelChildSameBranch() { var communicatorParent = new MockParentEventCommunicator(); var communicatorChild1 = new MockChildEventCommunicator(communicatorParent); var communicatorChild2 = new MockChildEventCommunicator(communicatorParent); var communicatorChild2Child = new MockChildEventCommunicator(communicatorChild2); var communicatorChild2ChildChild = new MockChildEventCommunicator(communicatorChild2Child); var addressChild1 = new EventCommunicatorAddress(communicatorChild2); var addressChild2 = new EventCommunicatorAddress(communicatorChild2ChildChild); var relationshipChild2ToChild1 = addressChild1.RecognizeRelationship(addressChild2); var relationshipChild1ToChild2 = addressChild2.RecognizeRelationship(addressChild1); Assert.Equal(EventCommunicatorsRelationship.Child, relationshipChild2ToChild1); Assert.Equal(EventCommunicatorsRelationship.Parent, relationshipChild1ToChild2); }
public Action<object[]> GetExecutionStrategy(EventCommunicatorAddress publisherAddress, EventCommunicatorsRelationship publishTo) { return GetExecutionStrategy(); }
private bool isSiblingRel(EventCommunicatorAddress other) { if (this.CanRemoveLast != other.CanRemoveLast) return false; var thisClone = this.Clone(); var otherClone = other.Clone(); return thisClone.RemoveLastOrNothing().AddressString.Equals(otherClone.RemoveLastOrNothing().AddressString); }
private bool isSameRel(EventCommunicatorAddress other) { return this.AddressString.Equals(other.AddressString); }
public void GetRelationshipBetweenNullCommunicator() { var communicator = new MockParentEventCommunicator(); var address = new EventCommunicatorAddress(communicator); Assert.Throws<ArgumentNullException>(() => { var tmp = address.RecognizeRelationship(null); }); }
private bool isChild(EventCommunicatorAddress other) { return other.AddressString.Contains(this.AddressString); }
public void ParentCommunicatorAddressCreated() { var communicator = new MockParentEventCommunicator(); var address = new EventCommunicatorAddress(communicator); Assert.False(string.IsNullOrEmpty(address.AddressString)); }
public void GoodPerformance() { var communicatorParent = new MockParentEventCommunicator(); var communicatorChild2 = new MockChildEventCommunicator(communicatorParent); var communicatorChild2Child = new MockChildEventCommunicator(communicatorChild2); var communicatorChild2ChildChild = new MockChildEventCommunicator(communicatorChild2Child); var rootAddr = new EventCommunicatorAddress(communicatorParent); var sw = Stopwatch.StartNew(); for (int i = 0; i < 10000; i++) { var addr = new EventCommunicatorAddress(communicatorChild2ChildChild); var relToRoot = addr.RecognizeRelationship(rootAddr); var relFromRoot = rootAddr.RecognizeRelationship(addr); } sw.Stop(); Assert.True(sw.ElapsedMilliseconds < 150); }
public void GetRelationshipBetweenSameCommunicators() { var communicator = new MockParentEventCommunicator(); var address = new EventCommunicatorAddress(communicator); var relationship = address.RecognizeRelationship(address); Assert.Equal(EventCommunicatorsRelationship.Same, relationship); }
public void GetRelationshipBetweenParentAndChildClosest() { var communicatorParent = new MockParentEventCommunicator(); var communicatorChild = new MockChildEventCommunicator(communicatorParent); var addressParent = new EventCommunicatorAddress(communicatorParent); var addressChild = new EventCommunicatorAddress(communicatorChild); var relationshipChildToParent = addressParent.RecognizeRelationship(addressChild); var relationshipParentToChild = addressChild.RecognizeRelationship(addressParent); Assert.Equal(EventCommunicatorsRelationship.ClosestChild | EventCommunicatorsRelationship.Child, relationshipChildToParent); Assert.Equal(EventCommunicatorsRelationship.Parent | EventCommunicatorsRelationship.ClosestParent, relationshipParentToChild); }
private List<Action<object[]>> pruneAndReturnStrategies(EventCommunicatorAddress publisherAddress, EventCommunicatorsRelationship publishTo) { var returnList = new List<Action<object[]>>(); lock (Subscriptions) { for (var i = Subscriptions.Count - 1; i >= 0; i--) { Action<object[]> listItem = _subscriptions[i].GetExecutionStrategy(publisherAddress, publishTo); if (listItem == null) { // Prune from main list. Log? _subscriptions.RemoveAt(i); } else { returnList.Add(listItem); } } } return returnList; }
private bool isClosestParentRel(EventCommunicatorAddress other) { var thisClone = this.Clone(); return other.AddressString.Equals(thisClone.RemoveLastOrNothing().AddressString); }
public void RemoveLast() { var communicator = new MockParentEventCommunicator(); var child = new MockChildEventCommunicator(communicator); var address = new EventCommunicatorAddress(child); var addrString = address.AddressString; address.RemoveLast(); Assert.NotEqual(addrString, address.AddressString); }
public void GetRelationshipBetweenNotRelatedCommunicators() { var communicatorParent1 = new MockParentEventCommunicator(); var communicatorParent2 = new MockParentEventCommunicator(); var addressParent1 = new EventCommunicatorAddress(communicatorParent1); var addressParent2 = new EventCommunicatorAddress(communicatorParent2); var relationshipParent2ToParent1 = addressParent1.RecognizeRelationship(addressParent2); var relationshipParent1ToParent2 = addressParent2.RecognizeRelationship(addressParent1); Assert.Equal(EventCommunicatorsRelationship.Other, relationshipParent2ToParent1); Assert.Equal(EventCommunicatorsRelationship.Other, relationshipParent1ToParent2); }
private bool isClosestChild(EventCommunicatorAddress other) { var otherClone = other.Clone(); return this.AddressString.Equals(otherClone.RemoveLastOrNothing().AddressString); }
public void RemoveLastOrNothingChild() { var communicatorParent = new MockParentEventCommunicator(); var communicatorChild = new MockChildEventCommunicator(communicatorParent); var addressChild = new EventCommunicatorAddress(communicatorChild); var countBefore = addressChild.Count; addressChild.RemoveLastOrNothing(); var countAfter = addressChild.Count; Assert.Equal(2, countBefore); Assert.Equal(1, countAfter); }
private bool isParentRel(EventCommunicatorAddress otherClone) { return this.AddressString.Contains(otherClone.AddressString); }
public void RemoveLastOrNothingParent() { var communicator = new MockParentEventCommunicator(); var address = new EventCommunicatorAddress(communicator); var countBefore = address.Count; address.RemoveLastOrNothing(); var countAfter = address.Count; Assert.Equal(1, countBefore); Assert.Equal(countBefore, countAfter); }
private bool isSiblingChildRel(EventCommunicatorAddress other) { var thisClone = this.Clone(); return other.AddressString.Contains(thisClone.RemoveLastOrNothing().AddressString); }
public void RemoveLastShouldThrowsException() { var communicator = new MockParentEventCommunicator(); var address = new EventCommunicatorAddress(communicator); Assert.Throws<EventAggregatorException>(() => { address.RemoveLast(); }); }
private EventCommunicatorsRelationship recognizeRelationship(EventCommunicatorAddress other) { var relationship = EventCommunicatorsRelationship.All; if(isSameRel(other)) relationship = EventCommunicatorsRelationship.Same; else if (isClosestParentRel(other)) relationship = EventCommunicatorsRelationship.ClosestParent | EventCommunicatorsRelationship.Parent; else if (isParentRel(other)) relationship = EventCommunicatorsRelationship.Parent; else if (isClosestChild(other)) relationship = EventCommunicatorsRelationship.ClosestChild | EventCommunicatorsRelationship.Child; else if (isChild(other)) relationship = EventCommunicatorsRelationship.Child; else if(isSiblingRel(other)) relationship = EventCommunicatorsRelationship.Sibling; else if (isSiblingChildRel(other)) relationship = EventCommunicatorsRelationship.SiblingChild; else relationship = EventCommunicatorsRelationship.Other; return relationship; }
public void ToStringShouldReturnsAddress() { var communicator = new MockParentEventCommunicator(); var addr = new EventCommunicatorAddress(communicator); Assert.Equal(addr.AddressString, addr.ToString()); }
public void ValidationShouldWork() { var communicator = new MockParentEventCommunicator(); communicator.CommunicatorIdInternal = Guid.Empty; Assert.Throws<EventAggregatorException>(() => { var tmp = new EventCommunicatorAddress(null); }); Assert.Throws<EventAggregatorException>(() => { var tmp = new EventCommunicatorAddress(communicator); }); }
public void GetRelationshipBetweenChildAndTwoLevelChildOtherBranch() { var communicatorParent1 = new MockParentEventCommunicator(); var communicatorParent2 = new MockParentEventCommunicator(); var communicatorChild1 = new MockChildEventCommunicator(communicatorParent1); var communicatorChild2 = new MockChildEventCommunicator(communicatorParent2); var communicatorChild2Child = new MockChildEventCommunicator(communicatorChild2); var addressChild1 = new EventCommunicatorAddress(communicatorChild1); var addressChild2 = new EventCommunicatorAddress(communicatorChild2Child); var relationshipChild2ToChild1 = addressChild1.RecognizeRelationship(addressChild2); var relationshipChild1ToChild2 = addressChild2.RecognizeRelationship(addressChild1); Assert.Equal(EventCommunicatorsRelationship.Other, relationshipChild2ToChild1); Assert.Equal(EventCommunicatorsRelationship.Other, relationshipChild1ToChild2); }