Beispiel #1
0
        public async Task Properties()
        {
            var connections = await PairedConnection.CreateConnectedPairAsync();

            var conn1      = connections.Item1;
            var conn2      = connections.Item2;
            var proxy      = conn1.CreateProxy <IPropertyObject>("", PropertyObject.Path);
            var dictionary = new Dictionary <string, object> {
                { "key1", 1 }, { "key2", 2 }
            };

            conn2.RegisterObject(new PropertyObject(dictionary));

            var properties = await proxy.GetAll();

            Assert.Equal(dictionary, properties);

            var val1 = await proxy.Get("key1");

            Assert.Equal(1, val1);

            var tcs = new TaskCompletionSource <(string Name, object Value)>();
            await proxy.WatchProperties(_ => tcs.SetResult(_));

            await proxy.Set("key1", "changed");

            var val1Changed = await proxy.Get("key1");

            Assert.Equal("changed", val1Changed);

            var changes = await tcs.Task;

            Assert.Equal("key1", changes.Name);
            Assert.Equal("changed", changes.Value);
        }
Beispiel #2
0
        public async Task PassException()
        {
            var connections = await PairedConnection.CreateConnectedPairAsync();

            var conn1 = connections.Item1;
            var conn2 = connections.Item2;
            var proxy = conn1.CreateProxy <IThrow>("servicename", Throw.Path);

            conn2.RegisterObject(new Throw());
            var exception = await Assert.ThrowsAsync <DBusException>(proxy.ThrowAsync);

            Assert.Equal(Throw.ExceptionMessage, exception.ErrorMessage);
        }
Beispiel #3
0
        public async Task Method()
        {
            var connections = await PairedConnection.CreateConnectedPairAsync();

            var conn1 = connections.Item1;
            var conn2 = connections.Item2;
            var proxy = conn1.CreateProxy <IStringOperations>("servicename", StringOperations.Path);
            await conn2.RegisterObjectAsync(new StringOperations());

            var reply = await proxy.ConcatAsync("hello ", "world");

            Assert.Equal("hello world", reply);
        }
Beispiel #4
0
        public async Task SignalNoArg()
        {
            var connections = await PairedConnection.CreateConnectedPairAsync();

            var conn1 = connections.Item1;
            var conn2 = connections.Item2;
            var proxy = conn1.CreateProxy <IPingPong>("", PingPong.Path);
            var tcs   = new TaskCompletionSource <string>();
            await proxy.WatchPongNoArgAsync(() => tcs.SetResult(null));

            conn2.RegisterObject(new PingPong());
            await proxy.PingAsync("hello world");

            var reply = await tcs.Task;

            Assert.Equal(null, reply);
        }
Beispiel #5
0
        public async Task SignalWithException()
        {
            var connections = await PairedConnection.CreateConnectedPairAsync();

            var conn1 = connections.Item1;
            var conn2 = connections.Item2;
            var proxy = conn1.CreateProxy <IPingPong>("servicename", PingPong.Path);
            var tcs   = new TaskCompletionSource <string>();
            await proxy.WatchPongWithExceptionAsync(message => tcs.SetResult(message), null);

            await conn2.RegisterObjectAsync(new PingPong());

            await proxy.PingAsync("hello world");

            var reply = await tcs.Task;

            Assert.Equal("hello world", reply);
        }
Beispiel #6
0
        public async Task Properties()
        {
            var connections = await PairedConnection.CreateConnectedPairAsync();

            var conn1      = connections.Item1;
            var conn2      = connections.Item2;
            var proxy      = conn1.CreateProxy <IPropertyObject>("servicename", PropertyObject.Path);
            var dictionary = new Dictionary <string, object> {
                { "key1", 1 }, { "key2", 2 }
            };
            await conn2.RegisterObjectAsync(new PropertyObject(dictionary));

            var properties = await proxy.GetAllAsync();

            Assert.Equal(dictionary, properties);

            var val1 = await proxy.GetAsync("key1");

            Assert.Equal(1, val1);

            var tcs = new TaskCompletionSource <PropertyChanges>();
            await proxy.WatchPropertiesAsync(_ => tcs.SetResult(_));

            await proxy.SetAsync("key1", "changed");

            var val1Changed = await proxy.GetAsync("key1");

            Assert.Equal("changed", val1Changed);

            var changes = await tcs.Task;

            Assert.Equal(1, changes.Changed.Length);
            Assert.Equal("key1", changes.Changed.First().Key);
            Assert.Equal("changed", changes.Changed.First().Value);
            Assert.Equal(0, changes.Invalidated.Length);
        }