public void GivenCyclicDependency_FiresUpdateFailedEvent() { //Arrange bool eventFired = false; var alfa = new Alfa(); var beta = new Beta(alfa); var nodeA = new PropertyNode(nameof(alfa.A), alfa); var nodeB = new PropertyNode(nameof(alfa.B), alfa); var nodeD = new PropertyNode(nameof(beta.D), beta); var reactor = new Reactor("R1"); reactor.CreateDependency(nodeA, nodeB); reactor.CreateDependency(nodeB, nodeD); reactor.CreateDependency(nodeD, nodeA); reactor.UpdateFailed += delegate { eventFired = true; }; //Act reactor.PerformUpdate(); //Assert Assert.IsTrue(eventFired); }
public void CreateDependency_GivenPredecessorAndSuccessorAreSame_ThrowsException() { //Arrange var obj = new Alfa(); var node = new PropertyNode(nameof(obj.A), obj); var reactor = new Reactor("R1"); //Act reactor.CreateDependency(node, node); }
public void UpdateFailed_NoSubscribers_DoesntFireEvent() { //Arrange bool eventFired = false; var alfa = new AlfaException(); var nodeA = new PropertyNode(nameof(alfa.A), alfa); var nodeB = new PropertyNode(nameof(alfa.B), alfa); var reactor = new Reactor("R1"); reactor.CreateDependency(nodeA, nodeB); //Act reactor.PerformUpdate(); //Assert Assert.IsFalse(eventFired); }
public void PerformUpdate_GivenCompleteUpdateRequested_PerformsCorrectUpdate() { //Arrange var alfa = new Alfa(); var beta = new Beta(alfa); var gama = new Gama(alfa, beta); var nodeA = new PropertyNode(nameof(alfa.A), alfa); var nodeB = new PropertyNode(nameof(alfa.B), alfa); var nodeC = new PropertyNode(nameof(beta.C), beta); var nodeD = new PropertyNode(nameof(beta.D), beta); var nodeE = new PropertyNode(nameof(gama.E), gama); var nodeF = new PropertyNode(nameof(gama.F), gama); var reactor = new Reactor("R1"); reactor.CreateDependency(nodeA, nodeE); reactor.CreateDependency(nodeA, nodeB); reactor.CreateDependency(nodeA, nodeD); reactor.CreateDependency(nodeC, nodeD); reactor.CreateDependency(nodeB, nodeE); reactor.CreateDependency(nodeB, nodeF); reactor.CreateDependency(nodeD, nodeF); reactor.CreateDependency(nodeE, nodeF); //Act reactor.PerformUpdate(); //Assert var updateLog = reactor.LastUpdateLog; int indexA = updateLog.IndexOf(nodeA); int indexB = updateLog.IndexOf(nodeB); int indexC = updateLog.IndexOf(nodeC); int indexD = updateLog.IndexOf(nodeD); int indexE = updateLog.IndexOf(nodeE); int indexF = updateLog.IndexOf(nodeF); Assert.IsTrue(updateLog.Count == 6); Assert.IsTrue(indexF > indexB && indexF > indexD && indexF > indexE); Assert.IsTrue(indexE > indexB && indexE > indexA); Assert.IsTrue(indexB > indexA); Assert.IsTrue(indexD > indexA && indexD > indexC); }
public void RemoveDependency_GivenValidDependency_DependencyRemoved() { //Arrange var obj = new Alfa(); var nodeA = new PropertyNode(nameof(obj.A), obj); var nodeB = new PropertyNode(nameof(obj.B), obj); var reactor = new Reactor("R1"); reactor.CreateDependency(nodeA, nodeB); //Act reactor.RemoveDependency(nodeA, nodeB); //Assert var predecessor = reactor.GetNode(nodeA.Identifier); var successor = reactor.GetNode(nodeB.Identifier); Assert.IsTrue(predecessor.Successors.Contains(successor) == false && successor.Predecessors.Contains(predecessor) == false); }
public void CreateDependency_GivenValidPredecessorAndSuccessor_DependencyCreated() { //Arrange var obj = new Alfa(); var nodeA = new PropertyNode(nameof(obj.A), obj); var nodeB = new PropertyNode(nameof(obj.B), obj); var reactor = new Reactor("R1"); //Act reactor.CreateDependency(nodeA, nodeB); //Assert var predecessor = reactor.GetNode(nodeA.Identifier); var successor = reactor.GetNode(nodeB.Identifier); Assert.IsTrue(predecessor != null && successor != null && predecessor.Successors.Contains(successor) && successor.Predecessors.Contains(predecessor)); }
public void GivenUpdateFails1_FiresUpdateFailedEvent() { //Arrange bool eventFired = false; var alfa = new AlfaException(); var nodeA = new PropertyNode(nameof(alfa.A), alfa); var nodeB = new PropertyNode(nameof(alfa.B), alfa); var reactor = new Reactor("R1"); reactor.CreateDependency(nodeA, nodeB); reactor.UpdateFailed += delegate { eventFired = true; }; //Act reactor.PerformUpdate(nodeA); //Assert Assert.IsTrue(eventFired); }