Esempio n. 1
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");
                }
            }
        }
Esempio n. 2
0
        public void ZyanServerCanRegisterAndResolveComponents()
        {
            using (var server = new ZyanServer())
            {
                server.Register <ISampleSyncService, SampleSyncService>();
                var component = server.Resolve <ISampleSyncService>();

                Assert.NotNull(component);
                Assert.IsType <SampleSyncService>(component);
            }
        }
Esempio n. 3
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();
                }
            }
        }
Esempio n. 4
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();
                }
            }
        }
Esempio n. 5
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);
                }
            }
        }
Esempio n. 6
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);
                }
            }
        }
Esempio n. 7
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);
                }
            }
        }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
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);
                }
            }
        }
Esempio n. 10
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);
                }
            }
        }
Esempio n. 11
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);
                }
            }
        }
Esempio n. 12
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);
                }
            }
        }
Esempio n. 13
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);
                }
            }
        }
Esempio n. 14
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);
                }
            }
        }
Esempio n. 15
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);
                }
            }
        }