/// <summary>Creates a peer with extended puller behavior.</summary> public INetworkPeer CreatePeer(out ExtendedBlockPullerBehavior mockedBehavior, bool notSupportedVersion = false) { var peer = new Mock <INetworkPeer>(); var connection = new NetworkPeerConnection(Network.StratisMain, peer.Object, new TcpClient(), this.currentPeerId, (message, token) => Task.CompletedTask, new DateTimeProvider(), this.loggerFactory, new PayloadProvider()); this.currentPeerId++; peer.SetupGet(networkPeer => networkPeer.Connection).Returns(connection); var connectionParameters = new NetworkPeerConnectionParameters(); VersionPayload version = connectionParameters.CreateVersion(new IPEndPoint(1, 1), Network.StratisMain, new DateTimeProvider().GetTimeOffset()); if (notSupportedVersion) { version.Version = ProtocolVersion.NOBLKS_VERSION_START; } else { version.Services = NetworkPeerServices.Network; } peer.SetupGet(x => x.PeerVersion).Returns(version); peer.SetupGet(x => x.State).Returns(NetworkPeerState.HandShaked); peer.SetupGet(x => x.MessageReceived).Returns(new AsyncExecutionEvent <INetworkPeer, IncomingMessage>()); ExtendedBlockPullerBehavior behavior = this.CreateBlockPullerBehavior(); behavior.Attach(peer.Object); peer.Setup(x => x.Behavior <IBlockPullerBehavior>()).Returns(() => behavior); mockedBehavior = behavior; return(peer.Object); }
private Mock <INetworkPeer> CreatePeerMock() { var peer = new Mock <INetworkPeer>(); var connection = new NetworkPeerConnection(KnownNetworks.StratisMain, peer.Object, new TcpClient(), 0, (message, token) => Task.CompletedTask, new DateTimeProvider(), this.loggerFactory, new PayloadProvider()); peer.SetupGet(networkPeer => networkPeer.Connection).Returns(connection); var connectionParameters = new NetworkPeerConnectionParameters(); VersionPayload version = connectionParameters.CreateVersion(new IPEndPoint(1, 1), new IPEndPoint(1, 1), KnownNetworks.StratisMain, new DateTimeProvider().GetTimeOffset()); version.Services = NetworkPeerServices.Network; peer.SetupGet(x => x.PeerVersion).Returns(version); peer.SetupGet(x => x.State).Returns(NetworkPeerState.HandShaked); this.StateChanged = new AsyncExecutionEvent <INetworkPeer, NetworkPeerState>(); this.MessageReceived = new AsyncExecutionEvent <INetworkPeer, IncomingMessage>(); peer.Setup(x => x.StateChanged).Returns(() => this.StateChanged); peer.Setup(x => x.MessageReceived).Returns(() => this.MessageReceived); var connectionManagerBehaviorMock = new Mock <IConnectionManagerBehavior>(); connectionManagerBehaviorMock.Setup(x => x.Whitelisted).Returns(this.IsPeerWhitelisted); peer.Setup(x => x.Behavior <IConnectionManagerBehavior>()).Returns(() => connectionManagerBehaviorMock.Object); peer.SetupGet(x => x.PeerEndPoint).Returns(new IPEndPoint(1, 1)); return(peer); }