示例#1
0
 public void ZyanClientDoesntImmediatelyConnect()
 {
     // Assert.DoesNotThrow
     using (var client = new ZyanClient(ServerUrl))
     {
     }
 }
示例#2
0
        public async Task AddRateTest(int msgQty)
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    var reply = await proxy.Add(1, 2);

                    var result = new long[3];

                    for (var i = 0; i < 3; i++)
                    {
                        var watch = Stopwatch.StartNew();

                        for (var k = 0; k < msgQty; k++)
                        {
                            reply = await proxy.Add(1, 2);
                        }

                        watch.Stop();

                        Assert.Equal(3, reply);

                        result[i] = watch.ElapsedMilliseconds;
                    }

                    _output.WriteLine($"{msgQty} messages: {string.Join(" ms, ", result)} ms");
                }
            }
        }
示例#3
0
 public void ZyanServerCanBeConnectedTo()
 {
     using (var server = new ZyanServer(ServerUrl))
         using (var client = new ZyanClient(ServerUrl))
         {
             Assert.True(client.IsConnected);
         }
 }
示例#4
0
 public void ZyanClientCanCreateProxies()
 {
     // Assert.DoesNotThrow
     using (var client = new ZyanClient(ServerUrl))
     {
         var proxy = client.CreateProxy <ISampleSyncService>();
         Assert.NotNull(proxy);
     }
 }
示例#5
0
        public async Task ZyanClientCanCallAsyncTaskMethod()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    // Assert.DoesNotThrow
                    await proxy.PerformShortOperation();
                }
            }
        }
示例#6
0
        public void ZyanClientCanCallVoidMethodSynchronously()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleSyncService, SampleSyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleSyncService>();

                    // Assert.DoesNotThrow
                    proxy.Void();
                }
            }
        }
示例#7
0
        public void ZyanClientCanCallMethodSynchronouslyAndGetTheStringResult()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleSyncService, SampleSyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleSyncService>();

                    // Assert.DoesNotThrow
                    var result = proxy.GetVersion();
                    Assert.Equal(SampleSyncService.Version, result);
                }
            }
        }
示例#8
0
        public void ZyanClientCanCallMethodSynchronouslyAndGetTheDateResult()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleSyncService, SampleSyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleSyncService>();

                    // Assert.DoesNotThrow
                    var result = proxy.GetDate(2017, 09, 17);
                    Assert.Equal(new DateTime(2017, 09, 17), result);
                }
            }
        }
示例#9
0
        public async Task ZyanClientCanCallAsyncTaskStringMethodWithParameters()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    // Assert.DoesNotThrow
                    var result = await proxy.Concatenate("Get", "Uninitialized", "Object");

                    Assert.Equal("GetUninitializedObject", result);
                }
            }
        }
示例#10
0
        public async Task ZyanClientCanCallAsyncTaskDateTimeMethodWithParameters()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    // Assert.DoesNotThrow
                    var result = await proxy.Construct(2017, 09, 19);

                    Assert.Equal(new DateTime(2017, 09, 19), result);
                }
            }
        }
示例#11
0
        public async Task ZyanClientCanCallAsyncTaskIntMethodWithParameters()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    // Assert.DoesNotThrow
                    var result = await proxy.Add(12300, 45);

                    Assert.Equal(12345, result);
                }
            }
        }
示例#12
0
        public void ZyanClientCanCallVoidMethodSynchronouslyAndItsActuallyExecutedOnServer()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleSyncService, SampleSyncService>(Reuse.Singleton);
                var sync = server.Resolve <ISampleSyncService>() as SampleSyncService;
                Assert.False(sync.VoidExecuted);

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleSyncService>();

                    // Assert.DoesNotThrow
                    proxy.Void();
                    Assert.True(sync.VoidExecuted);
                }
            }
        }
示例#13
0
        public void ZyanClientCanCallMethodSynchronouslyAndCatchTheException()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleSyncService, SampleSyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleSyncService>();

                    var ex = Assert.Throws <NotImplementedException>(() =>
                    {
                        proxy.ThrowException();
                    });

                    Assert.Equal(nameof(ISampleSyncService), ex.Message);
                }
            }
        }
示例#14
0
        public void ZyanClientCanAssignRemotePropertySynchronously()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                // preserving property value between calls requires the Singleton reuse
                server.Register <ISampleSyncService, SampleSyncService>(Reuse.Singleton);

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleSyncService>();

                    // Assert.DoesNotThrow
                    proxy.Platform = nameof(ZyanClientCanAssignRemotePropertySynchronously);
                    var result = proxy.Platform;

                    Assert.Equal(nameof(ZyanClientCanAssignRemotePropertySynchronously), result);
                }
            }
        }
示例#15
0
        public async Task ZyanClientCanCallLongAsyncTaskMethodAndItsActuallyExecuted()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>(Reuse.Singleton);
                var async = server.Resolve <ISampleAsyncService>() as SampleAsyncService;
                Assert.False(async.LongOperationPerformed);

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    // Assert.DoesNotThrow
                    await proxy.PerformLongOperation();

                    Assert.True(async.LongOperationPerformed);
                }
            }
        }
示例#16
0
        public async Task ZyanClientCanCallAsyncTaskMethodAndCatchTheException()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    var ex = await Assert.ThrowsAsync <NotImplementedException>(async() =>
                    {
                        await proxy.ThrowException();
                    });

                    Assert.Equal(nameof(ISampleAsyncService), ex.Message);
                }
            }
        }
示例#17
0
        public async Task ZyanClientCanReadRemotePropertyAsynchronously()
        {
            using (var server = new ZyanServer(ServerUrl))
            {
                server.Register <ISampleAsyncService, SampleAsyncService>();

                using (var client = new ZyanClient(ServerUrl))
                {
                    var proxy = client.CreateProxy <ISampleAsyncService>();

                    // Assert.DoesNotThrow
                    var nowBefore = DateTimeOffset.Now;
                    var nowRemote = await proxy.Now;
                    var nowAfter  = DateTimeOffset.Now;

                    Assert.True(nowBefore <= nowRemote);
                    Assert.True(nowRemote <= nowAfter);
                }
            }
        }