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"); } } }
public void ZyanServerCanRegisterAndResolveComponents() { using (var server = new ZyanServer()) { server.Register <ISampleSyncService, SampleSyncService>(); var component = server.Resolve <ISampleSyncService>(); Assert.NotNull(component); Assert.IsType <SampleSyncService>(component); } }
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(); } } }
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(); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }
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); } } }