Beispiel #1
0
        public void tempFileIsDeletedIfErrorHappens()
        {
            var tempFile    = new Mock <ITempFile>();
            var tempFactory = new Mock <ITempFileFactory>();
            var protoHdler  = new ProtocolHanlder(tempFactory.Object, storage.Object, new TransmitStartedState());


            //
            // file-start
            //
            var fileStart = new { action = "file-start", file_name = "file1.jpg", file_size = 20, type = "image", folder = "ff" };

            // file-start again !!! Error
            try
            {
                protoHdler.HandleMessage(new MessageEventArgs(JsonConvert.SerializeObject(fileStart)));

                Assert.Fail("ProtocolErrorException is expected but is not thrown");
            }
            catch (ProtocolErrorException)
            {
                // ======= verify =======
                tempFile.VerifyAll();
            }
        }
Beispiel #2
0
        public void do_not_handle_closed_ctx()
        {
            var ctx = new Mock <IProtocolHandlerContext>();

            ctx.Setup(x => x.IsClosed).Returns(true);

            var handler = new ProtocolHanlder(ctx.Object);

            handler.HandleMessage(new MessageEventArgs("12345"));
        }
Beispiel #3
0
        public void testInvalidTextCommand()
        {
            var tempFactory = new Mock <ITempFileFactory>();
            var protoHdler  = new ProtocolHanlder(tempFactory.Object, storage.Object, new Mock <AbstractProtocolState>().Object);

            //
            // Unknown command XXXXX
            //
            //var fileStart = new { action = "XXXXX", file_name = "file1.jpg", file_size = 20 };
            protoHdler.HandleMessage(new MessageEventArgs("1234567899"));
        }
Beispiel #4
0
        public void handle_update_count_cmd()
        {
            var ctx = new Mock <IProtocolHandlerContext>();

            ctx.Setup(x => x.handleUpdateCountCmd(It.Is <TextCommand>(c => c.action == "update-count" && c.transfer_count == 1000))).Verifiable();
            var handler = new ProtocolHanlder(ctx.Object);

            var cmd = new { action = "update-count", transfer_count = 1000 };

            handler.HandleMessage(new MessageEventArgs(JsonConvert.SerializeObject(cmd)));
        }
Beispiel #5
0
        public void testUnknownTxtCmd()
        {
            var tempFactory = new Mock <ITempFileFactory>();
            var protoHdler  = new ProtocolHanlder(tempFactory.Object, storage.Object, new Mock <AbstractProtocolState>().Object);

            //
            // Unknown command XXXXX
            //
            var fileStart = new { action = "XXXXX", file_name = "file1.jpg", file_size = 20 };

            protoHdler.HandleMessage(new MessageEventArgs(JsonConvert.SerializeObject(fileStart)));
        }
Beispiel #6
0
        public void protocolHandlerSendConnectMsgToProperHandler()
        {
            var connectMSg = new TextCommand {
                action = "connect", device_name = "de", device_id = "id"
            };


            var ctx = new Mock <IProtocolHandlerContext>();

            ctx.Setup(x => x.handleConnectCmd(It.Is <TextCommand>(cmd => cmd.action == "connect" && cmd.device_id == "id" && cmd.device_name == "de"))).Verifiable();
            var protoHdr = new ProtocolHanlder(ctx.Object);

            protoHdr.HandleMessage(new MessageEventArgs(JsonConvert.SerializeObject(connectMSg)));

            ctx.VerifyAll();
        }