示例#1
0
        public void ReturnZippedResult()
        {
            this.BuildClientSettingsProps();

            this.RegisterType <RpcResultHandler>();

            var messageId = Fixture.Create <long>();

            var result = new TPong();

            var tgZipPacked = new TgZipPacked
            {
                PackedData = Fixture.CreateMany <byte>(8).ToArray()
            };
            var request = new TRpcResult
            {
                ReqMsgId = messageId,
                Result   = Serializer.Serialize(tgZipPacked).ToArray()
            };

            this.Resolve <Mock <IUnzippedService> >()
            .Setup(service => service.UnzipPackage(tgZipPacked))
            .Returns(() => result);

            var mRequestService = this.Resolve <Mock <IRequestService> >()
                                  .BuildReturnResult(messageId, result);

            var requestEncoder = this.Resolve <RpcResultHandler>();

            var channel = new EmbeddedChannel(requestEncoder);

            // ---

            channel.WriteInbound(request);

            // ---

            Assert.Null(channel.ReadOutbound <object>());

            channel.Flush();
            Assert.IsType <TMsgsAck>(channel.ReadOutbound <TMsgsAck>());

            mRequestService.Verify(service => service.ReturnResult(messageId, result), Times.Once);
        }
示例#2
0
        public void SendAfterInit()
        {
            this.RegisterType <TopHandlerAdapter>();

            var mSettings = this.BuildClientSettingsProps();

            var authKey = mSettings.Object.ClientSession.AuthKey;

            var resultTaskSource = new TaskCompletionSource <object>();

            var request  = new RequestPing();
            var response = new TPong();

            var config = new TConfig
            {
                DcOptions = new TVector <IDcOption>()
            };

            this.Resolve <Mock <IRequestService> >()
            .BuildGetAllRequestToReply(request)
            .BuildRegisterRequest <RequestInvokeWithLayer>(Task.FromResult((object)config));

            var handlerAdapter = this.Resolve <TopHandlerAdapter>();

            // ---

            mSettings.Object.ClientSession.AuthKey = null;

            var channel = new EmbeddedChannel(handlerAdapter);

            mSettings.Object.ClientSession.AuthKey = authKey;

            channel.Pipeline.FireUserEventTriggered(ESystemNotification.HandshakeComplete);

            resultTaskSource.SetResult(response);

            // ---
            Assert.NotNull(channel.ReadOutbound <RequestInvokeWithLayer>());

            Assert.Equal(request, channel.ReadOutbound <RequestPing>());
        }