public void SendRequest_Request_Null_Fails() { // Arrange _autoMockContainer .Register <IRequestService, RequestService>(); var mockUnitOfWork = _autoMockContainer .GetMock <IUnitOfWork>(); var requestEntity = new Domain.Entities.Request(); mockUnitOfWork .Setup(uow => uow.CreateEntity <Domain.Entities.Request>()) .Returns(requestEntity); _autoMockContainer .GetMock <IUnitOfWorkFactory>().Setup(uowf => uowf.Create()) .Returns(mockUnitOfWork.Object); _autoMockContainer .GetMock <IDateTimeService>() .Setup(dts => dts.GetCurrentDateAndTime()) .Returns(DateTime.Now); // Act Request request = null; Assert.ThrowsDelegate sendRequestAction = () => _autoMockContainer.Resolve <IRequestService>().CreateRequest(request); // Assert Assert.Throws <ArgumentNullException>(sendRequestAction); }
protected override void Register(AutoMockContainer container) { container.Register(new LanguageSet()); // Mock Zero Install version container.Register(new ImplementationVersion("1.0")); base.Register(container); }
protected override void Register(AutoMockContainer container) { MockHandler = new MockCommandHandler(); container.Register <ICommandHandler>(MockHandler); container.Register(new Config()); FeedCacheMock = container.GetMock <IFeedCache>(); CatalogManagerMock = container.GetMock <ICatalogManager>(); StoreMock = container.GetMock <IStore>(); PackageManagerMock = container.GetMock <IPackageManager>(); SolverMock = container.GetMock <ISolver>(); FetcherMock = container.GetMock <IFetcher>(); ExecutorMock = container.GetMock <IExecutor>(); }
public async Task Can_activate_peer_on_verack_receiving() { // Arrange var blockchain = new NullBlockchain(); AutoMockContainer.Register <IBlockchain>(blockchain); var verAckMessage = new VerAckMessage(); var version = new VersionPayload(); var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock.SetupProperty(x => x.IsReady, false); peerMock.SetupProperty(x => x.Version, version); blockchain.LastBlockHeader.Index = 1; version.CurrentBlockIndex = 1; var messageHandler = AutoMockContainer.Get <VerAckMessageHandler>(); // Act await messageHandler.Handle(verAckMessage, peerMock.Object); // Assert peerMock.Object.IsReady.Should().BeTrue(); }
public void Can_handle_handshake_different_once_error_while_connecting_to_peer() { // Arrange AutoMockContainer.Register(GetNetworkConfig("tcp://localhost:8081")); var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock.Setup(x => x.Receive <VersionMessage>()) .Returns(() => { var peerVersionMessage = new VersionMessage(); peerVersionMessage.Payload.Nonce = 0; return(Task.FromResult(peerVersionMessage)); }); var peerFactoryMock = AutoMockContainer.GetMock <IPeerFactory>(); peerFactoryMock.Setup(x => x.ConnectTo(It.IsAny <EndPoint>())).Returns(Task.FromResult(peerMock.Object)); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); Task.Delay(100).Wait(); // Asset peerMock.Verify(x => x.Send(new VerAckMessage()), Times.Never); }
public void Can_listen_for_peers_on_start() { // Arrange AutoMockContainer.Register(GetNetworkConfig()); var peerListenerMock = AutoMockContainer.GetMock <IPeerListener>(); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); // Asset peerListenerMock.Verify(x => x.Start(), Times.Once); }
public void Initialize() { var networkConfig = GetNetworkConfig(); _peerEndPoint = networkConfig.PeerEndPoints[0]; AutoMockContainer.Register(networkConfig); var blockchainContextMock = AutoMockContainer.GetMock <IBlockchainContext>(); blockchainContextMock .SetupGet(x => x.CurrentBlock) .Returns(new Block()); }
public void Can_stop_server_on_dispose() { // Arrange AutoMockContainer.Register(GetNetworkConfig()); var peerListenerMock = AutoMockContainer.GetMock <IPeerListener>(); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); server.Dispose(); // Asset peerListenerMock.Verify(x => x.Stop(), Times.AtLeastOnce); }
public void Can_handle_connection_error_while_connecting_to_peers() { // Arrange AutoMockContainer.Register(GetNetworkConfig("tcp://localhost:8081")); var peerFactoryMock = AutoMockContainer.GetMock <IPeerFactory>(); peerFactoryMock.Setup(x => x.ConnectTo(It.IsAny <EndPoint>())) .Returns(Task.FromException <IPeer>(new Exception("The network error"))); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); // Asset peerFactoryMock.Verify(x => x.ConnectTo(It.IsAny <EndPoint>()), Times.Once); }
public void Can_connect_to_peers_on_start() { // Arrange AutoMockContainer.Register(GetNetworkConfig("tcp://localhost:8081")); var peerFactoryMock = AutoMockContainer.GetMock <IPeerFactory>(); var peerMock = AutoMockContainer.GetMock <IPeer>(); peerFactoryMock.Setup(x => x.ConnectTo(It.IsAny <EndPoint>())).Returns(Task.FromResult(peerMock.Object)); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); // Asset peerFactoryMock.Verify(x => x.ConnectTo(It.IsAny <EndPoint>()), Times.Once); }
public async Task Can_send_acknowledgement_on_version_receiving() { // Arrange var server = new NullServer(); AutoMockContainer.Register <IServer>(server); var messageHandler = AutoMockContainer.Get <VersionMessageHandler>(); var versionMessage = GetPeerVersionMessage(server); var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock.SetupProperty(x => x.Version); // Act await messageHandler.Handle(versionMessage, peerMock.Object); // Assert peerMock.Verify(x => x.Send <VerAckMessage>(), Times.Once); }
public void Throw_on_the_same_nonce_on_version_receiving() { // Arrange var server = new NullServer(); AutoMockContainer.Register <IServer>(server); var versionMessage = GetPeerVersionMessage(server); versionMessage.Payload.Nonce = server.Nonce; var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock.SetupProperty(x => x.Version); var messageHandler = AutoMockContainer.Get <VersionMessageHandler>(); // Act Action a = () => messageHandler.Handle(versionMessage, peerMock.Object).Wait(); // Assert a.Should().Throw <InvalidOperationException>(); }
public async Task Can_downgrade_protocol_on_version_receiving() { // Arrange var server = new NullServer(); AutoMockContainer.Register <IServer>(server); var messageHandler = AutoMockContainer.Get <VersionMessageHandler>(); var versionMessage = GetPeerVersionMessage(server); server.ProtocolVersion = 2; versionMessage.Payload.Version = 1; var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock.SetupProperty(x => x.Version); // Act await messageHandler.Handle(versionMessage, peerMock.Object); // Assert peerMock.Verify(x => x.DowngradeProtocol(It.IsAny <uint>()), Times.Once); }
public async Task Can_send_get_block_headers_message_if_peer_block_header_height_is_different() { // Arrange var blockchain = new NullBlockchain(); AutoMockContainer.Register <IBlockchain>(blockchain); var verAckMessage = new VerAckMessage(); var version = new VersionPayload(); var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock.SetupProperty(x => x.Version, version); blockchain.LastBlockHeader.Index = 1; version.CurrentBlockIndex = 2; var messageHandler = AutoMockContainer.Get <VerAckMessageHandler>(); // Act await messageHandler.Handle(verAckMessage, peerMock.Object); // Assert peerMock.Verify(x => x.Send(It.IsAny <GetBlockHeadersMessage>()), Times.Once); }
private Nep6WalletManager GetAWalletManagerWithoutAnWallet() { AutoMockContainer.Register <IFileWrapper>(new FileWrapper()); AutoMockContainer.Register <IJsonConverter>(new JsonConverterWrapper()); return(AutoMockContainer.Create <Nep6WalletManager>()); }
/// <summary> /// Hook that can be used to register objects in the <see cref="AutoMockContainer"/> before the <see cref="Target"/> is constructed. /// </summary> protected virtual void Register(AutoMockContainer container) { container.Register <ITaskHandler>(Handler = new MockTaskHandler()); container.Register(Config = new Config()); container.Register(TrustDB = new TrustDB()); }
protected override void Register(AutoMockContainer container) { container.Register <ICommandHandler>(Handler = new MockCommandHandler()); }
/// <summary> /// Hook that can be used to register objects in the <see cref="AutoMockContainer"/> before the <see cref="Target"/> is constructed. /// </summary> protected virtual void Register(AutoMockContainer container) { container.Register <ITaskHandler>(MockHandler = new MockTaskHandler()); container.Register(new Config()); }
public void WarmSerializer() { AutoMockContainer.Register <IBinarySerializer>(new BinarySerializer(typeof(VersionMessage).Assembly)); }
/// <summary> /// Sets the default mock for the specified type. /// </summary> /// <typeparam name="TService"> /// The type of service for which the object is to be used by default. /// </typeparam> /// <param name="serviceObj"> /// An object that provides an implementation of the service. /// </param> /// <returns> /// The same object that was passed in as <see cref="serviceObj" />. /// </returns> public TService Use <TService>(TService serviceObj) { autoMockContainer.Register(serviceObj); return(serviceObj); }