public void Should_update_byref_param_if_any() { // Arrange var coordinator = Substitute.For <IRpcClientCoordinator>(); coordinator.Send(Arg.Any <RpcRequest>()) .Returns(new RpcResponse { ChangedParams = new Dictionary <string, object> { { "message", new SomeMessage { Money = "$1000" } } } }); var interceptor = new RpcClientInterceptor(coordinator); var service = RpcFactory.CreateClient <ISomeService>(interceptor); // Action var message = new SomeMessage(); service.SaveNotAsync(ref message); Assert.AreEqual("$1000", message.Money); }
public void Should_set_out_value_and_return_value() { // Arrange var coordinator = Substitute.For <IRpcClientCoordinator>(); coordinator.Send(Arg.Any <RpcRequest>()) .Returns(new RpcResponse { ReturnValue = new List <SomeMessage> { new SomeMessage() }, ChangedParams = new Dictionary <string, object> { { "totalCount", (long)1000 /* long value will be converted to proper int value */ } } }); var interceptor = new RpcClientInterceptor(coordinator); var service = RpcFactory.CreateClient <ISomeService>(interceptor); int totalCount; // Assert var result = service.Get(1, 200, out totalCount); // Assert Assert.AreEqual(1, result.Count()); Assert.AreEqual(1000, totalCount); }
public void DynamicRpcCall() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); int k = (int)anRpcClient.CallRemoteMethod("Sum", 1, 2); Assert.AreEqual(3, k); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
/// <summary> /// 启动RPC服务器 /// </summary> /// <returns></returns> public static bool StartRpcServer(string remoteIp, int remotePort, string localIp, int localPort) { _remoteIp = remoteIp; _remotePort = remotePort; _localIp = localIp; _localPort = localPort; System.Reflection.Assembly.Load("Sys.Safety.WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); int rpcModel = Basic.Framework.Configuration.ConfigurationManager.FileConfiguration.GetInt("RpcModel", 1); if (rpcModel == 1) { _rpcModel = RpcModel.WebApiModel; } else if (rpcModel == 2) { _rpcModel = RpcModel.gRPCModel; } _client = RpcFactory.CreateRpcClient(_rpcModel, _remoteIp, _remotePort); _server = RpcFactory.CreateRpcServer(_rpcModel); _server.RegistCallback(OnRpcMessageArrived); _server.Start(_localIp, _localPort); return(true); }
public virtual void RpcTimeout() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); anRpcFactory.RpcTimeout = TimeSpan.FromSeconds(1); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; Assert.Throws <TimeoutException>(() => aServiceProxy.Timeout()); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
protected RpcClientTesting() { this.nodes = NodeBuilderFactory.CreateNodeBuilder(GetType()); try { this.nodes.ConfigParameters.Add("autocommit", "0"); this.nodes.ConfigParameters.Add("dandelion", "0"); this.nodes.ConfigParameters.Add("exodus", "1"); Node = this.nodes.CreateNode(true); Client = Node.CreateRPCClient(); Factory = new RpcFactory( this.nodes.Network, Node.RPCUri, RPCCredentialString.Parse(Node.GetRPCAuth()), new TransactionEncoder(ExodusEncoders) ); this.subject = new Lazy <RpcClient>(CreateSubject, LazyThreadSafetyMode.ExecutionAndPublication); // lgtm[cs/virtual-call-in-constructor] } catch { this.nodes.Dispose(); throw; } }
public void RpcCallError() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; Assert.Throws <RpcException>(() => aServiceProxy.Fail()); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
static void Main(string[] args) { Global.DefaultSerializer = new JsonSerializer(); Global.DefaultWatcher.IsDebugEnable = false; PrintHelp(); ISomeService realService = new DummyImplementation(); IRpcServerCoordinator server = RpcFactory.CreateServer(realService, serverId: "UnitTest"); server.Start(); string outValue; var client = RpcFactory.CreateClient <ISomeService>(); client.TryParse(out outValue); Console.WriteLine(); Console.WriteLine(); Global.DefaultWatcher.InfoFormat("Method TryParse was executed remotely, out value is {0}", outValue); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Global.DefaultWatcher.InfoFormat("... change the method to something else to continue to test"); Console.ReadKey(); }
public void Should_set_time_to_live_in_the_request() { // Arrange DefaultMethodFilter.CheckedMethodCaches.Clear(); var coordinator = Substitute.For <IRpcClientCoordinator>(); coordinator.Send(Arg.Any <RpcRequest>()) .Returns(new RpcResponse { ChangedParams = new Dictionary <string, object> { { "result", "out string" } } }); var interceptor = new RpcClientInterceptor(coordinator); var service = RpcFactory.CreateClient <ISomeService>(interceptor); // Assert string outValue; service.TryParse(out outValue); // Assert coordinator.Received(1).Send(Arg.Is <RpcRequest>(arg => arg.UtcExpiryTime != null)); Assert.AreEqual("out string", outValue); }
public void RpcCall_NullArgument() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; string k = aServiceProxy.CreateString(null); Assert.AreEqual(null, k); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void SubscribeBeforeAttachOutputChannel() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { IHello aServiceProxy = anRpcClient.Proxy; AutoResetEvent aClientConnected = new AutoResetEvent(false); anRpcClient.ConnectionOpened += (x, y) => { aClientConnected.Set(); }; AutoResetEvent anEventReceived = new AutoResetEvent(false); Action <object, EventArgs> anEventHandler = (x, y) => { anEventReceived.Set(); }; // Subscribe before the connection is open. aServiceProxy.Close += anEventHandler.Invoke; // Open the connection. anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); // Wait until the client is connected. aClientConnected.WaitOne(); // Raise the event in the service. aService.RaiseClose(); Assert.IsTrue(anEventReceived.WaitOne()); // Unsubscribe. aServiceProxy.Close -= anEventHandler.Invoke; // Try to raise again. aService.RaiseClose(); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void PerClientInstanceService() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreatePerClientInstanceService <IHello>(() => new HelloService()); IRpcClient <IHello> anRpcClient1 = anRpcFactory.CreateClient <IHello>(); IRpcClient <IHello> anRpcClient2 = anRpcFactory.CreateClient <IHello>(); try { ManualResetEvent aClient2Connected = new ManualResetEvent(false); string aService1IdFromEvent = null; anRpcClient1.Proxy.Open += (x, y) => { aService1IdFromEvent = y.InstanceId; }; string aService2IdFromEvent = null; anRpcClient2.Proxy.Open += (x, y) => { aService2IdFromEvent = y.InstanceId; aClient2Connected.Set(); }; anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient1.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); anRpcClient2.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); aClient2Connected.WaitOne(1000); string aServiceId1 = anRpcClient1.Proxy.GetInstanceId(); string aServiceId2 = anRpcClient2.Proxy.GetInstanceId(); Assert.IsFalse(string.IsNullOrEmpty(aServiceId1)); Assert.IsFalse(string.IsNullOrEmpty(aService1IdFromEvent)); Assert.IsFalse(string.IsNullOrEmpty(aServiceId2)); Assert.IsFalse(string.IsNullOrEmpty(aService2IdFromEvent)); Assert.AreEqual(aServiceId1, aService1IdFromEvent); Assert.AreEqual(aServiceId2, aService2IdFromEvent); Assert.AreNotEqual(aServiceId1, aServiceId2); } finally { if (anRpcClient1.IsDuplexOutputChannelAttached) { anRpcClient1.DetachDuplexOutputChannel(); } if (anRpcClient2.IsDuplexOutputChannelAttached) { anRpcClient2.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void Can_provide_request_queue_name() { // Action var server = RpcFactory.CreateServer(Substitute.For <ISomeService>(), "RequestQueue") as BurrowRpcServerCoordinator <ISomeService>; // Assert Assert.IsNotNull(server); }
public void Can_accept_null_params() { // Action var server = RpcFactory.CreateServer(Substitute.For <ISomeService>()) as BurrowRpcServerCoordinator <ISomeService>; // Assert Assert.IsNotNull(server); }
public void RpcNonGenericEvent_10000() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; int aCounter = 0; AutoResetEvent anEventReceived = new AutoResetEvent(false); Action <object, EventArgs> anEventHandler = (x, y) => { ++aCounter; if (aCounter == 10000) { anEventReceived.Set(); } }; // Subscribe. aServiceProxy.Close += anEventHandler.Invoke; Stopwatch aStopWatch = new Stopwatch(); aStopWatch.Start(); // Raise the event in the service. for (int i = 0; i < 10000; ++i) { aService.RaiseClose(); } Assert.IsTrue(anEventReceived.WaitOne()); aStopWatch.Stop(); Console.WriteLine("Remote event. Elapsed time = " + aStopWatch.Elapsed); // Unsubscribe. aServiceProxy.Close -= anEventHandler.Invoke; } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void Can_accept_null_params() { // Arrange InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>(); // Action RpcFactory.CreateClient <ISomeService>(); }
public void RpcCall_10000() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(new HelloService()); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; Stopwatch aStopWatch = new Stopwatch(); aStopWatch.Start(); //EneterTrace.StartProfiler(); for (int i = 0; i < 10000; ++i) { aServiceProxy.Sum(1, 2); } //EneterTrace.StopProfiler(); aStopWatch.Stop(); Console.WriteLine("Rpc call. Elapsed time = " + aStopWatch.Elapsed); HelloService aService = new HelloService(); Stopwatch aStopWatch2 = new Stopwatch(); aStopWatch2.Start(); for (int i = 0; i < 10000; ++i) { aService.Sum(1, 2); } aStopWatch2.Stop(); Console.WriteLine("Local call. Elapsed time = " + aStopWatch2.Elapsed); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void Should_throw_exception_if_response_is_null() { // Arrange var coordinator = Substitute.For <IRpcClientCoordinator>(); var interceptor = new RpcClientInterceptor(coordinator); var service = RpcFactory.CreateClient <ISomeService>(interceptor); int totalCount; // Assert service.Get(1, 200, out totalCount); }
public void DynamicRpcGenericEvent() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); AutoResetEvent anEventReceived = new AutoResetEvent(false); string aReceivedEvent = ""; EventHandler <OpenArgs> anEventHandler = (x, y) => { aReceivedEvent = y.Name; anEventReceived.Set(); }; // Subscribe. anRpcClient.SubscribeRemoteEvent("Open", anEventHandler); // Raise the event in the service. OpenArgs anOpenArgs = new OpenArgs() { Name = "Hello" }; aService.RaiseOpen(anOpenArgs); Assert.IsTrue(anEventReceived.WaitOne()); Assert.AreEqual("Hello", aReceivedEvent); // Unsubscribe. anRpcClient.UnsubscribeRemoteEvent("Open", anEventHandler); // Try to raise again. aService.RaiseOpen(anOpenArgs); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public PropertyIssuer(RpcFactory factory) { this.factory = factory; Ecosystem = Ecosystem.Main; Type = PropertyType.Indivisible; Category = "Company"; SubCategory = "Private"; Name = "Satang Corporation"; Description = "Provides cryptocurrency solutions."; Url = "https://satang.com"; }
public void RpcGenericEvent() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); IHello aServiceProxy = anRpcClient.Proxy; AutoResetEvent anEventReceived = new AutoResetEvent(false); Action <object, OpenArgs> anEventHandler = (x, y) => { anEventReceived.Set(); }; // Subscribe. aServiceProxy.Open += anEventHandler.Invoke; // Raise the event in the service. OpenArgs anOpenArgs = new OpenArgs() { Name = "Hello" }; aService.RaiseOpen(anOpenArgs); Assert.IsTrue(anEventReceived.WaitOne()); // Unsubscribe. aServiceProxy.Open -= anEventHandler.Invoke; // Try to raise again. aService.RaiseOpen(anOpenArgs); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
public void init() { try { IRpcFactory rpcFactory = new RpcFactory(); RpcObj = rpcFactory.CreateClient<ILeiloeiro>(); TcpMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + IP + ":" + Porta + "/");//ip local e porta do servidor RpcObj.AttachDuplexOutputChannel(anOutputChannel); } catch (Exception ex) { throw new Exception("Erro: É necessario iniciar o servidor - " + ex.Message); } }
public void DynamicRpcNonGenericEvent() { RpcFactory anRpcFactory = new RpcFactory(mySerializer); HelloService aService = new HelloService(); IRpcService <IHello> anRpcService = anRpcFactory.CreateSingleInstanceService <IHello>(aService); IRpcClient <IHello> anRpcClient = anRpcFactory.CreateClient <IHello>(); try { anRpcService.AttachDuplexInputChannel(myMessaging.CreateDuplexInputChannel(myChannelId)); anRpcClient.AttachDuplexOutputChannel(myMessaging.CreateDuplexOutputChannel(myChannelId)); AutoResetEvent anEventReceived = new AutoResetEvent(false); EventHandler <EventArgs> anEventHandler = (x, y) => { anEventReceived.Set(); }; // Subscribe. anRpcClient.SubscribeRemoteEvent <EventArgs>("Close", anEventHandler); // Raise the event in the service. aService.RaiseClose(); Assert.IsTrue(anEventReceived.WaitOne()); // Unsubscribe. anRpcClient.UnsubscribeRemoteEvent("Close", anEventHandler); // Try to raise again. aService.RaiseClose(); Assert.IsFalse(anEventReceived.WaitOne(1000)); } finally { if (anRpcClient.IsDuplexOutputChannelAttached) { anRpcClient.DetachDuplexOutputChannel(); } if (anRpcService.IsDuplexInputChannelAttached) { anRpcService.DetachDuplexInputChannel(); } } }
private IRpcClient<ILeiloeiro> myRpcClient; //declara o Rpc client #endregion Fields #region Constructors public Form1() { InitializeComponent(); tbIP.Text = "127.0.0.1"; tbPorta.Text = "38445"; IRpcFactory anRpcFactory = new RpcFactory(); myRpcClient = anRpcFactory.CreateClient<ILeiloeiro>(); txtCliente.Enabled = false; txtCod.Enabled = false; txtValor.Enabled = false; SumButton.Enabled = false; button1.Enabled = false; ResultLabel.Text = ""; label5.Text = ""; }
public TalkFlow() { var talk = new Talk(); IRpcFactory factory = new RpcFactory(); IRpcService <ITalk> service = factory.CreateSingleInstanceService <ITalk>(talk); IMessagingSystemFactory messaging = new TcpMessagingSystemFactory(); IDuplexInputChannel inputChannel = messaging.CreateDuplexInputChannel("tcp://127.0.0.1:8045/"); service.AttachDuplexInputChannel(inputChannel); Console.WriteLine("Service started. Press ENTER to stop."); Console.ReadLine(); service.DetachDuplexInputChannel(); }
public TalkFlow() { IRpcFactory factory = new RpcFactory(); var client = factory.CreateClient <ITalk>(); TcpMessagingSystemFactory messaging = new TcpMessagingSystemFactory(); IDuplexOutputChannel anOutputChannel = messaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8045/"); client.AttachDuplexOutputChannel(anOutputChannel); string sentence = ""; while ((sentence = Console.ReadLine()) != "stop") { client.Proxy.Talk("Client A", sentence); } }
public void Should_send_async_if_method_is_async() { // Arrange var coordinator = Substitute.For <IRpcClientCoordinator>(); coordinator.Send(Arg.Any <RpcRequest>()) .Returns(new RpcResponse()); var interceptor = new RpcClientInterceptor(coordinator); var service = RpcFactory.CreateClient <ISomeService>(interceptor); // Assert var msg = new SomeMessage(); service.Save(ref msg); // Assert coordinator.Received(1).SendAsync(Arg.Is <RpcRequest>(arg => arg.UtcExpiryTime == null)); }
public void Should_throw_exception_if_resonse_has_exception() { // Arrange var coordinator = Substitute.For <IRpcClientCoordinator>(); coordinator.Send(Arg.Any <RpcRequest>()) .Returns(new RpcResponse { Exception = new Exception() }); var interceptor = new RpcClientInterceptor(coordinator); var service = RpcFactory.CreateClient <ISomeService>(interceptor); // Assert string outValue; service.TryParse(out outValue); }
public void Should_throw_exception_if_missing_out_value_in_response_object() { // Arrange var coordinator = Substitute.For <IRpcClientCoordinator>(); coordinator.Send(Arg.Any <RpcRequest>()) .Returns(new RpcResponse { ReturnValue = new List <SomeMessage> { new SomeMessage() } }); var interceptor = new RpcClientInterceptor(coordinator); var service = RpcFactory.CreateClient <ISomeService>(interceptor); int totalCount; // Assert service.Get(1, 200, out totalCount); }
public void Should_use_DefaulRpcRouteFinder_and_create_durable_queue_even_if_not_provide_serverId() { // Arrange var model = Substitute.For <IModel>(); InternalDependencies.RpcQueueHelper .When(x => x.CreateQueues(Arg.Any <string>(), Arg.Any <Action <IModel> >())) .Do(callInfo => callInfo.Arg <Action <IModel> >()(model)); // Action var server = RpcFactory.CreateServer(Substitute.For <ISomeService>(), "RequestQueue") as BurrowRpcServerCoordinator <ISomeService>; Assert.IsNotNull(server); server.Start(); // Assert model.Received(1).QueueDeclare("RequestQueue", true, false, false, Arg.Any <IDictionary <string, object> >()); }
public RpcFactoryTests() { this.nodes = NodeBuilderFactory.CreateNodeBuilder(GetType()); try { var node = this.nodes.CreateNode(true); this.network = node.Network; this.server = node.RPCUri; this.credential = RPCCredentialString.Parse(node.GetRPCAuth()); this.exodusEncoder = new Mock <ITransactionEncoder>(); this.subject = new RpcFactory(this.network, this.server, this.credential, this.exodusEncoder.Object); } catch { this.nodes.Dispose(); throw; } }
public void Should_use_DefaulRpcRouteFinder_and_declare_durable_request_queue() { // Arrange var model = Substitute.For <IModel>(); InternalDependencies.RpcQueueHelper .When(x => x.CreateQueues(Arg.Any <string>(), Arg.Any <Action <IModel> >())) .Do(callInfo => callInfo.Arg <Action <IModel> >()(model)); // Action var server = RpcFactory.CreateServer(Substitute.For <ISomeService>(), "RequestQueue", serverId: "ServerId") as BurrowRpcServerCoordinator <ISomeService>; Assert.IsNotNull(server); server.Start(); // Assert model.Received().QueueDeclare("RequestQueue", true, false, false, Arg.Any <IDictionary <string, object> >()); model.DidNotReceiveWithAnyArgs().ExchangeDeclare("", "", false, false, null); tunnel.Received(1).SubscribeAsync("ServerId", Arg.Any <Action <RpcRequest> >()); }