Exemplo n.º 1
0
            public void Requests_Null_Method_Call()
            {
                var messenger = Substitute.For <IBinaryMessenger>();
                var channel   = new MethodChannel(TEST_CHANNEL_NAME, StandardMethodCodec.Instance, messenger);

                Assert.ThrowsAsync <ArgumentNullException>(() => channel.InvokeMethodAsync(null));
            }
Exemplo n.º 2
0
            public async void Requests_Correct_MethodCall_And_Returns_Success_Envelope()
            {
                var messenger = Substitute.For <IBinaryMessenger>();
                var codec     = StandardMethodCodec.Instance;
                var channel   = new MethodChannel(TEST_CHANNEL_NAME, codec, messenger);
                var call      = new MethodCall(TEST_METHOD_NAME, new int[] { 1, 2, 5 });

                byte[] encodedCall = codec.EncodeMethodCall(call);
                messenger.SendAsync(TEST_CHANNEL_NAME, Arg.Any <byte[]>())
                .Returns(codec.EncodeSuccessEnvelope("TEST_RESULT"));

                var result = await channel.InvokeMethodAsync(call.Method, call.Arguments) as string;

                await messenger.Received().SendAsync(Arg.Is <string>(x => x == TEST_CHANNEL_NAME),
                                                     Arg.Is <byte[]>(x => x.SequenceEqual(encodedCall)));

                Assert.Equal("TEST_RESULT", result);
            }
Exemplo n.º 3
0
            public async void Requests_Correct_MethodCall_And_Returns_Error_Envelope()
            {
                var messenger = Substitute.For <IBinaryMessenger>();
                var codec     = StandardMethodCodec.Instance;
                var channel   = new MethodChannel(TEST_CHANNEL_NAME, codec, messenger);
                var call      = new MethodCall(TEST_METHOD_NAME, new int[] { 1, 2, 5 });

                messenger.SendAsync(TEST_CHANNEL_NAME, Arg.Any <byte[]>())
                .Returns(codec.EncodeErrorEnvelope("E0001", "TEST_ERROR", "TEST_ERROR_DETAILS"));

                var ex = await Assert.ThrowsAsync <FlutterException>(() =>
                {
                    return(channel.InvokeMethodAsync(call.Method, call.Arguments));
                });

                Assert.Equal("E0001", ex.Code);
                Assert.Equal("TEST_ERROR", ex.Message);
                Assert.Equal("TEST_ERROR_DETAILS", ex.Details as string);
            }