public void HandleMessageShouldCreateInitializeMessagesOnlyForActiveNodes() { // Arrange _message.MessageType = MessageType.MatrixUpdateMessage; _message.Data = new Dictionary <uint, NetworkMatrix> { [0] = NetworkMatrix.Initialize(_networkMock.Object), [1] = NetworkMatrix.Initialize(_networkMock.Object), [2] = NetworkMatrix.Initialize(_networkMock.Object), [3] = NetworkMatrix.Initialize(_networkMock.Object), [4] = NetworkMatrix.Initialize(_networkMock.Object), }; _nodes[1].IsActive = false; var linkedNodeCount = Receiver.LinkedNodesId.Count; // Act _messageHandler.HandleMessage(_message); // Assert _generalMessageCreatorMock.Verify(c => c.CreateMessages(It.Is <MessageInitializer> (m => m.MessageType == MessageType.MatrixUpdateMessage)), Times.Exactly(linkedNodeCount - 1)); _generalMessageCreatorMock.Verify(c => c.AddInQueue(It.Is <Message[]> (m => m.All(m1 => m1.MessageType == MessageType.MatrixUpdateMessage)), Receiver.Id), Times.Exactly(linkedNodeCount - 1)); Assert.That(Receiver.NetworkMatrix, Is.EqualTo(((Dictionary <uint, NetworkMatrix>)_message.Data)[0])); }
public void ResetShouldRemoveAllTables() { // Arrange _network.AddNode(_node1); _node1.NetworkMatrix = NetworkMatrix.Initialize(_network); // Act _network.Reset(); // Assert Assert.IsNull(_node1.NetworkMatrix); }
private void StartCountingPriceProcess(uint currentId, uint?startId, ref NetworkMatrix matrix, ref SortedSet <uint> visitedNodes) { if (visitedNodes == null) { visitedNodes = new SortedSet <uint>(); } if (matrix == null) { matrix = NetworkMatrix.Initialize(Network); matrix.NodeIdWithCurrentPrice[currentId] = 0.0; } if (startId.HasValue && currentId == startId.Value) { foreach (var key in matrix.NodeIdWithCurrentPrice.Keys.ToArray()) { matrix.NodeIdWithCurrentPrice[key] = double.PositiveInfinity; } matrix.NodeIdWithCurrentPrice[startId.Value] = 0.0; } }