Esempio n. 1
0
        public void Initialize()
        {
            AspectHelper.CodeGenerated += (sender, args) => Console.WriteLine(args.GeneratedCode);
            this.target = AspectHelper.Wrap <ITestContract>(new TestImplementation());

            TestResultBag.Nullify();
        }
Esempio n. 2
0
 public TestMef(
     [Import] ITestContract unwrapped,
     [Import(typeof(IAspected <ITestContract>))] ITestContract wrapped)
 {
     this.unwrapped = unwrapped;
     this.wrapped   = wrapped;
 }
Esempio n. 3
0
        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");
                    }
                }
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public void Server_ReturnsNull_EnsureNullReceivedOnClient()
        {
            ITestContract        client = CreateChannel();
            Mock <ITestContract> server = Server();

            server.Setup(v => v.ComplexFunction()).Returns((CompositeType)null);
            Assert.Null(client.ComplexFunction());
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        public void AddTest()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddTransient <ITestContract, TestService1>();

            IServiceProvider provider = services.BuildServiceProvider();
            ITestContract    contract = provider.GetService <ITestContract>();

            Assert.NotNull(contract);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public void Client_NullArgument_Ok()
        {
            Mock <ITestContract> server = Server();

            server.Setup(v => v.MethodWithNullableArguments(null)).Verifiable();

            ITestContract client = CreateChannel();

            client.MethodWithNullableArguments(null);

            server.Verify();
        }
Esempio n. 11
0
        /// <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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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;
        }
Esempio n. 14
0
        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;
            }
        }
Esempio n. 15
0
        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>();
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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();
        }
Esempio n. 18
0
        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();
        }
Esempio n. 19
0
        // 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();
        }
Esempio n. 20
0
        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);
                    }
                }
            }
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        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();
        }
Esempio n. 23
0
        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>();
        }
Esempio n. 24
0
        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()}");
        }
Esempio n. 25
0
File: IPC.cs Progetto: TomoNag/Tomo
        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;
            }
        }
Esempio n. 26
0
        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()}");
        }