コード例 #1
0
        public async Task CommandTest()
        {
            await using var _ = await WebHost.Serve();

            // Server commands
            var kv = WebServices.GetRequiredService <IKeyValueService <string> >();

            (await kv.Get("")).Should().BeNull();

            await kv.SetCmd(new IKeyValueService <string> .SetCommand("", "1"));

            (await kv.Get("")).Should().Be("1");

            await WebServices.Commander().Call(new IKeyValueService <string> .SetCommand("", "2"));

            (await kv.Get("")).Should().Be("2");

            // Client commands
            var kvc = ClientServices.GetRequiredService <IKeyValueServiceClient <string> >();

            (await kv.Get("")).Should().Be("2");

            await kvc.SetCmd(new IKeyValueService <string> .SetCommand("", "1"));

            await Task.Delay(100); // Remote invalidation takes some time

            (await kvc.Get("")).Should().Be("1");

            await ClientServices.Commander().Call(new IKeyValueService <string> .SetCommand("", "2"));

            await Task.Delay(100); // Remote invalidation takes some time

            (await kvc.Get("")).Should().Be("2");
        }