Пример #1
0
        public void MethodOne_Unhandled()
        {
            OneClient svc = new OneClient();

            svc.ActivityId  = Guid.NewGuid();
            svc.AccessToken = "my.jwt.token";

            try
            {
                svc.MethodOne(new Zn.Sample.OneSvc.MethodOneRequest()
                {
                    Value = 15
                });

                Assert.Fail("Expected exception.");
            }
            catch (ServiceFaultException ex)
            {
                // Zinc.WebServices.ZincException
                Assert.AreEqual("ZnSample.Zinc", ex.Actor);
                Assert.AreEqual(4006, ex.Code);

                // System.Exception
                Assert.IsTrue(ex.InnerException != null, "Expected inner exception.");
                Assert.IsTrue(ex.InnerException is ActorException, "Inner exception must be ActorException.");
                ActorException iex = (ActorException)ex.InnerException;
                Assert.AreEqual("ZnSample", iex.Actor);
                Assert.AreEqual(991, iex.Code);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected named exception, instead got: " + ex.GetType().FullName);
            }
        }
Пример #2
0
        public void Async()
        {
            OneClient svc = new OneClient();

            svc.ActivityId  = Guid.NewGuid();
            svc.AccessToken = "my.jwt.token";

            try
            {
                var response = svc.MethodOneAsync(new Zn.Sample.OneSvc.MethodOneRequest()
                {
                    Value = 10
                }).GetAwaiter().GetResult();

                Assert.Fail("Expected exception.");
            }
            catch (ServiceException ex)
            {
                Assert.AreEqual("Invoke_NotJson", ex.Message);
                Assert.AreEqual("ZnClient.Sample", ex.Actor);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected named exception, instead got: " + ex.GetType().FullName);
            }
        }
Пример #3
0
        public void MethodFake_Ok()
        {
            OneClient svc = new OneClient();

            svc.ActivityId  = Guid.NewGuid();
            svc.AccessToken = "my.jwt.token";

            try
            {
                var response = svc.MethodFake(new Zn.Sample.OneSvc.MethodOneRequest()
                {
                    Value = 10
                });

                Assert.Fail("Expected exception.");
            }
            catch (ServiceException ex)
            {
                Assert.AreEqual("Invoke_MethodNotFound", ex.Message);
                Assert.AreEqual(4003, ex.Code);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected named exception, instead got: " + ex.GetType().FullName);
            }
        }
Пример #4
0
        public void MethodOn_RemoteException()
        {
            OneClient svc = new OneClient();

            svc.ActivityId  = Guid.NewGuid();
            svc.AccessToken = "my.jwt.token";

            try
            {
                svc.MethodOneAsync(new Zn.Sample.OneSvc.MethodOneRequest()
                {
                    Value = 110
                }).GetAwaiter().GetResult();

                Assert.Fail("Expected exception.");
            }
            catch (ServiceFaultException ex)
            {
                // Zn.Sample.SampleException
                Assert.AreEqual("ZnSample", ex.Actor);
                Assert.AreEqual(10001, ex.Code);

                // Zn.Sample.SampleException
                Assert.IsTrue(ex.InnerException != null, "Expected inner exception.");
                Assert.IsTrue(ex.InnerException is ActorException, "Inner exception must be ActorException.");
                ActorException iex = (ActorException)ex.InnerException;
                Assert.AreEqual("ZnSample", iex.Actor);
                Assert.AreEqual(10000, iex.Code);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected named exception, instead got: " + ex.GetType().FullName);
            }
        }
Пример #5
0
        /// <summary />
        public async Task <MethodTwoResponse> InnerRun(MethodTwoRequest request)
        {
            /*
             *
             */
            var ssvc = new SampleSvcClient();
            var beer = await ssvc.PingAsync();


            /*
             *
             */
            var outValue = -1;

            if (request.InValue >= 0)
            {
                var svc = new OneClient();
                svc.ActivityId = this.Context.ActivityId;

                var t1 = svc.MethodOneAsync(new OneSvc.MethodOneRequest()
                {
                    Value = request.InValue,
                });

                var t2 = svc.MethodOneAsync(new OneSvc.MethodOneRequest()
                {
                    Value = request.InValue + 5,
                });


                /*
                 *
                 */
                await Task.WhenAll(t1, t2);

                outValue = t1.Result.Value + t2.Result.Value;
            }


            /*
             *
             */
            return(new MethodTwoResponse()
            {
                OutValue = outValue,
                OutDate = request.InDate,
                OutTime = request.InTime,
                OutDateTime = request.InDateTime,
                OutDuration = request.InDuration,
                BinaryValue = Encoding.UTF8.GetBytes("hello world"),
                ActivityId = this.Context.ActivityId,
                AccessToken = this.Context.AccessToken,
                ExecutionId = this.Context.ExecutionId,
                OutEnum = request.InEnum,
            });
        }
Пример #6
0
        public void MethodOne_Ok()
        {
            OneClient svc = new OneClient();

            svc.ActivityId  = Guid.NewGuid();
            svc.AccessToken = "my.jwt.token";

            var response = svc.MethodOne(new Zn.Sample.OneSvc.MethodOneRequest()
            {
                Value = 10
            });

            Assert.AreEqual(100, response.Value);
        }
Пример #7
0
        /// <summary />
        public static async Task MainAsync(int value, int count)
        {
            var svc = new OneClient();

            svc.ActivityId = Guid.NewGuid();

            Console.WriteLine("URL=" + svc.ServiceUrl);

            for (int i = 0; i < count; i++)
            {
                DateTime start = DateTime.UtcNow;

                var t1 = svc.MethodOneAsync(new OneSvc.MethodOneRequest()
                {
                    Value = value,
                });

                var t2 = svc.MethodOneAsync(new OneSvc.MethodOneRequest()
                {
                    Value = value + 5,
                });

                var t3 = svc.MethodOneAsync(new OneSvc.MethodOneRequest()
                {
                    Value = value + 3,
                });


                /*
                 *
                 */
                try
                {
                    await Task.WhenAll(t1, t2, t3);

                    Console.Write("OK ");
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerExceptions.All(x => x is ServiceFaultException) == true)
                    {
                        Console.Write("ER ");
                    }
                    else
                    {
                        Console.Write("EX ");
                    }
                }
                catch (ServiceFaultException)
                {
                    Console.Write("ER ");
                }
                catch (Exception ex)
                {
                    Console.Write("EX ");
                    Console.WriteLine(ex.ToString());
                }

                DateTime end = DateTime.UtcNow;
                TimeSpan ts  = end - start;
                Console.WriteLine("{0} {1:000.000}ms", i, ts.TotalMilliseconds);
            }
        }
Пример #8
0
        /// <summary />
        public static void MainSync(int value, int count)
        {
            var svc = new OneClient();

            svc.ActivityId = Guid.NewGuid();

            Console.WriteLine("URL=" + svc.ServiceUrl);

            for (int i = 0; i < count; i++)
            {
                DateTime start = DateTime.UtcNow;


                try
                {
                    var t1 = svc.MethodOne(new OneSvc.MethodOneRequest()
                    {
                        Value = value,
                    });
                    Console.Write("OK ");
                }
                catch (ServiceFaultException)
                {
                    Console.Write("ER ");
                }
                catch (Exception)
                {
                    Console.Write("EX ");
                }


                try
                {
                    var t2 = svc.MethodOne(new OneSvc.MethodOneRequest()
                    {
                        Value = value + 5,
                    });
                    Console.Write("OK ");
                }
                catch (ServiceFaultException)
                {
                    Console.Write("ER ");
                }
                catch (Exception)
                {
                    Console.Write("EX ");
                }


                try
                {
                    var t3 = svc.MethodOne(new OneSvc.MethodOneRequest()
                    {
                        Value = value + 3,
                    });
                    Console.Write("OK ");
                }
                catch (ServiceFaultException)
                {
                    Console.Write("ER ");
                }
                catch (Exception)
                {
                    Console.Write("EX ");
                }

                DateTime end = DateTime.UtcNow;
                TimeSpan ts  = end - start;
                Console.WriteLine("{0} {1:000.000}ms", i, ts.TotalMilliseconds);
            }
        }