public void Initialize() { AspectHelper.CodeGenerated += (sender, args) => Console.WriteLine(args.GeneratedCode); this.target = AspectHelper.Wrap <ITestContract>(new TestImplementation()); TestResultBag.Nullify(); }
public TestMef( [Import] ITestContract unwrapped, [Import(typeof(IAspected <ITestContract>))] ITestContract wrapped) { this.unwrapped = unwrapped; this.wrapped = wrapped; }
public void Send_Receive_Message() { using (IBus bus = new RabbitMQBus()) { using (IChannelFactory <ITestContract> channelFactory = new MessageBus.Core.Proxy.ChannelFactory <ITestContract>(bus)) { ISubscriptionFactory <ITestContract> subscriptionFactory = new SubscriptionFactory <ITestContract>(bus, c => c.SetReceiveSelfPublish()); string actual = ""; ManualResetEvent ev = new ManualResetEvent(false); using (ISubscriptionSelector <ITestContract> selector = subscriptionFactory.Subscribe()) { selector.Subscribe <string>(contract => contract.Foo, s => { actual = s; ev.Set(); }); ITestContract channel = channelFactory.CreateChannel(); channel.Foo("boo"); ev.WaitOne(TimeSpan.FromSeconds(5)); actual.Should().Be("boo"); } } } }
public void Create_EnsureIsChannel() { ProxyFactory factory = Create(); Mock <IClientPipeline> pipeline = new Mock <IClientPipeline>(); ITestContract proxy = factory.CreateProxy <ITestContract>(pipeline.Object); Assert.True(proxy is IProxy); }
public void Server_ReturnsNull_EnsureNullReceivedOnClient() { ITestContract client = CreateChannel(); Mock <ITestContract> server = Server(); server.Setup(v => v.ComplexFunction()).Returns((CompositeType)null); Assert.Null(client.ComplexFunction()); }
public void Create_EnsureDerivesFromContractProxy() { Mock <IClientPipeline> pipeline = new Mock <IClientPipeline>(); ProxyFactory factory = Create(); ITestContract proxy = factory.CreateProxy <ITestContract>(pipeline.Object); Assert.True(proxy is ProxyBase); }
public void Server_ReturnsNumber_EnsureSameValueOnClient() { ITestContract client = CreateChannel(); Mock <ITestContract> server = Server(); int value = 99; server.Setup(v => v.SimpleFunction2()).Returns(value); Assert.Equal(value, client.SimpleFunction2()); }
public void AddTest() { IServiceCollection services = new ServiceCollection(); services.AddTransient <ITestContract, TestService1>(); IServiceProvider provider = services.BuildServiceProvider(); ITestContract contract = provider.GetService <ITestContract>(); Assert.NotNull(contract); }
public void ProxyBuilder_UseContractInitalization_CalledBeforeBuildDone() { var channel = new TestChannel(); ITestContract initializationArgument = null; var proxyConnection = TntBuilder.UseContract <ITestContract>() .UseContractInitalization((i, c) => initializationArgument = i) .UseChannel(channel) .Build(); Assert.IsNotNull(initializationArgument); Assert.AreEqual(proxyConnection.Contract, initializationArgument); }
public void Client_NullArgument_Ok() { Mock <ITestContract> server = Server(); server.Setup(v => v.MethodWithNullableArguments(null)).Verifiable(); ITestContract client = CreateChannel(); client.MethodWithNullableArguments(null); server.Verify(); }
/// <summary> /// /// </summary> public void Merge(ITestContract itc) { if (itc == null) { throw new ArgumentNullException(); } if (itc.SecurityLevel == TestCaseSecurityLevel.FullTrust) { this.SecurityLevel = TestCaseSecurityLevel.FullTrust; } if (!String.IsNullOrEmpty(itc.Area)) { this.Area = itc.Area; } if (!String.IsNullOrEmpty(itc.Title)) { if (String.IsNullOrEmpty(this.Title)) { this.Title = itc.Title; } else { this.Title += "_" + itc.Title; } } if (itc.Disabled) { this.Disabled = true; } if (itc.Priority > this.Priority) { this.Priority = itc.Priority; } if (itc.Timeout != 0) { this.Timeout = itc.Timeout; } Input.AddRange(itc.Input); Output.AddRange(itc.Output); SupportFiles.AddRange(itc.SupportFiles); }
public void Client_ComplexParameters_EnsureSameOnServer() { ITestContract client = CreateChannel(); Mock <ITestContract> server = Server(); CompositeType arg1 = CompositeType.CreateRandom(); server.Setup(v => v.SimpleMethodWithComplexParameter(arg1)).Callback <CompositeType>(serverArg => { Assert.NotSame(serverArg, arg1); Assert.Equal(serverArg, arg1); }); client.SimpleMethodWithComplexParameter(arg1); }
public WebAppHandler(string p, TextBox preview, string webPlayer) { string address = "net.pipe://localhost/flyinglawnmower/obsnp"; NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); EndpointAddress ep = new EndpointAddress(address); channel = ChannelFactory <ITestContract> .CreateChannel(binding, ep); path = p; bStop = false; isPluginOpen = true; this.preview = preview; this.webPlayer = webPlayer; }
public void Connect() { try { string address = "net.pipe://localhost/IPCTest"; NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); EndpointAddress ep = new EndpointAddress(address); channel = ChannelFactory <ITestContract> .CreateChannel(binding, ep); } catch (Exception e) { return; } }
public void Setup() { var services = new ServiceCollection() .AddMicroClient(opt => { opt.AddJsonCoder() .AddHttpProtocol() .AddTcpProtocol() .AddConsul("http://192.168.0.231:8500"); }); _provider = services.BuildServiceProvider(); var proxy = _provider.GetService <IProxyFactory>(); _contract = proxy.Create <ITestContract>(); }
public void Server_ThrowsWithInner_EnsureInnerReceivedOnClient() { ITestContract client = CreateChannel(); Mock <ITestContract> server = Server(); server.Setup(v => v.SimpleMethod()).Throws(new CustomException("test message", new CustomException())); try { client.SimpleMethod(); } catch (CustomException e) { Assert.NotNull(e.InnerException as CustomException); } }
static void Main(string[] args) { string address = "net.pipe://localhost/gorillacoding/IPCTest"; NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); EndpointAddress ep = new EndpointAddress(address); ITestContract channel = ChannelFactory <ITestContract> .CreateChannel(binding, ep); // TODO: Check connected. Console.WriteLine("Client Connected"); Console.WriteLine(" 2 + 2 = {0}", channel.Add(2, 2)); Console.WriteLine(" 256 - 89 = {0}", channel.Subtract(256, 89)); Console.ReadLine(); }
public async Task ExecuteAsyncMethod_EnsureChannelCalled() { ProxyFactory factory = Create(); Mock <IClientPipeline> pipeline = new Mock <IClientPipeline>(); pipeline.Setup(p => p.Instance).Returns(ctxt => { ctxt.ActionResult = "some value"; Assert.Equal(AsyncMethod, ctxt.Action.Action); return(Task.FromResult(0)); }); ITestContract proxy = factory.CreateProxy <ITestContract>(pipeline.Object); await proxy.AsyncMethod(); pipeline.Verify(); }
// Program.cs static void Main(string[] args) { string address = "net.pipe://localhost/selector/12345"; NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); EndpointAddress ep = new EndpointAddress(address); CallbackHandler callbackHandler = new CallbackHandler(); ITestContract channel = DuplexChannelFactory <ITestContract> .CreateChannel(callbackHandler, binding, ep); Console.WriteLine("Client Connected"); Console.WriteLine(" 2 + 2 = "); channel.Add(2, 2); Console.WriteLine(" 256 - 89 ="); channel.Subtract(256, 89); Console.ReadLine(); }
public void Send_Receive_CustomSerializationMessage() { using (IBus bus = new RabbitMQBus()) { using (IChannelFactory <ITestContract> channelFactory = new MessageBus.Core.Proxy.ChannelFactory <ITestContract>(bus, c => c.UseJsonSerializerSettings(new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }))) { ISubscriptionFactory <ITestContract> subscriptionFactory = new SubscriptionFactory <ITestContract>(bus); Data actual = null; ManualResetEvent ev = new ManualResetEvent(false); Data data = new Data { Value = "boo" }; using (ISubscriptionSelector <ITestContract> selector = subscriptionFactory.Subscribe(c => c.SetReceiveSelfPublish().UseJsonSerializerSettings(new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }))) { selector.Subscribe <Data>(contract => contract.Foo, s => { actual = s; ev.Set(); }); ITestContract channel = channelFactory.CreateChannel(); channel.Foo(data); ev.WaitOne(TimeSpan.FromSeconds(5)); actual.ShouldBeEquivalentTo(data); } } } }
public void ExecuteFunction_EnsureChannelCalled() { ProxyFactory factory = Create(); Mock <IClientPipeline> pipeline = new Mock <IClientPipeline>(); pipeline.Setup(p => p.Instance).Returns(ctxt => { ctxt.ActionResult = "some value"; Assert.Equal(Function, ctxt.Action.Action); return(Task.FromResult(0)); }); ITestContract proxy = factory.CreateProxy <ITestContract>(pipeline.Object); string result = proxy.Function(); pipeline.Verify(); Assert.Equal("some value", result); }
public void ExecuteMethod_EnsureChannelCalled() { ProxyFactory factory = Create(); Mock <IClientPipeline> pipeline = new Mock <IClientPipeline>(); pipeline.Setup(p => p.Instance).Returns(ctxt => { ctxt.ActionResult = "some value"; Assert.Equal(MethodWithParameters, ctxt.Action.Action); Assert.Equal("val", ctxt.Parameters[0]); Assert.Equal(10, ctxt.Parameters[1]); Assert.Equal(CancellationToken.None, ctxt.Parameters[2]); return(Task.FromResult(0)); }); ITestContract proxy = factory.CreateProxy <ITestContract>(pipeline.Object); proxy.MethodWithParameters("val", 10, CancellationToken.None); pipeline.Verify(); }
public void Setup() { var services = new MicroBuilder() .AddMicroClient(builder => { builder.AddJsonCoder() .AddSession() .AddHttpProtocol() .AddTcpProtocol() //.AddConsul("http://192.168.0.231:8500") .AddNacos(opt => { opt.Host = "http://192.168.0.231:8848/"; opt.Tenant = "ef950bae-865b-409b-9c3b-bc113cf7bf37"; }) ; }); _provider = services.BuildServiceProvider(); var proxy = _provider.GetService <IProxyFactory>(); _contract = proxy.Create <ITestContract>(); }
private static void Execute(Action<ITestContract> action, int count, int degree, ITestContract channel, string type, string actionName) { Console.Writer.Write($"{type,-10}"); // warmup for (int i = 0; i < 10; i++) { action(channel); } Stopwatch watch = Stopwatch.StartNew(); if ( degree == 1) { for (int i = 0; i < count; i++) { action(channel); } } else { while (count > 0) { Parallel.ForEach(Enumerable.Repeat(channel, count % degree == 0 ? degree : count % degree), new ParallelOptions { MaxDegreeOfParallelism = degree }, c => { action(c); }); count -= degree; } } long elapsed = watch.ElapsedMilliseconds; Console.WriteLine($"{(elapsed + "ms").Green().Bold()}"); }
public void Connect() { try { string address = "net.pipe://localhost/IPCTest"; NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); EndpointAddress ep = new EndpointAddress(address); channel = ChannelFactory<ITestContract>.CreateChannel(binding, ep); } catch (Exception e) { return; } }
private static async Task ExecuteAsync(Func<ITestContract, Task> action, int count, int degree, ITestContract channel, string type, string actionName) { Console.Writer.Write($"{type,-10}"); // warmup for (int i = 0; i < 10; i++) { await action(channel); } Stopwatch watch = Stopwatch.StartNew(); if (degree == 1) { for (int i = 0; i < count; i++) { await action(channel); } } else { while (count > 0) { await Task.WhenAll(Enumerable.Repeat(0, count % degree == 0 ? degree : count % degree).Select(_ => action(channel))); count -= degree; } } long elapsed = watch.ElapsedMilliseconds; Console.WriteLine($"{(elapsed + "ms").Green().Bold()}"); }