Exemplo n.º 1
0
        public void PropertySet_ValidationOnly_Negative_ActualNotNull()
        {
            var validatedEntity = new ValidationEntityNotNull();
            var messageCheck    = new MessageCheck("Property Set is not valid");

            messageCheck.AddPropertyLine("Not Null", "Null", "Id");
            var ex = Assert.Throws(typeof(AssertionException),
                                   () =>
                                   Assert.That(validatedEntity, Entity.Is.Valid));

            messageCheck.Check(ex);
        }
Exemplo n.º 2
0
        public void PropertySet_ValidationOnly_Negative_ActualGreaterThan()
        {
            var validatedEntity = new ValidationEntityGreaterThan();
            var messageCheck    = new MessageCheck("Property Set is not valid");

            messageCheck.AddPropertyLine("Greater than 5", "0", "Id");
            var ex = Assert.Throws(typeof(AssertionException),
                                   () =>
                                   Assert.That(validatedEntity, Entity.Is.Valid));

            Console.WriteLine(ex.Message);
            messageCheck.Check(ex);
        }
Exemplo n.º 3
0
        public void PropertySet_Compare_RecursiveReference_Negative_ActualNull_Level0()
        {
            var expected = new ObjectWithRecursiveRef {
                IntValue = 1
            };

            expected.RecursiveRef = expected;
            var actual = new ObjectWithRecursiveRef
            {
                IntValue     = 1,
                RecursiveRef = null
            };
            var messageCheck = new MessageCheck("Property Set is not equal");

            messageCheck.AddPropertyLine(typeof(ObjectWithRecursiveRef).FullName, "Null", "RecursiveRef");
            var ex = Assert.Throws(typeof(AssertionException),
                                   () =>
                                   Assert.That(actual, Entity.Is.EqualTo(expected)));

            messageCheck.Check(ex);
        }
Exemplo n.º 4
0
        public void PropertySet_ValidationOnly_Negative_ChildObjects()
        {
            var validatedEntity = new ValidationWithChild
            {
                NotNullProp = new ValidationEntityNotNull {
                    Id = null
                },
                GreaterThanProp = new ValidationEntityGreaterThan {
                    Id = 4
                }
            };
            var messageCheck = new MessageCheck("Property Set is not valid");

            messageCheck.AddPropertyLine("Greater than 5", "4", "GreaterThanProp.Id");
            messageCheck.AddPropertyLine("Not Null", "Null", "NotNullProp.Id");
            var ex = Assert.Throws(typeof(AssertionException),
                                   () =>
                                   Assert.That(validatedEntity, Entity.Is.Valid));

            Console.WriteLine(ex.Message);
            messageCheck.Check(ex);
        }
Exemplo n.º 5
0
        public void onReceivePacket(DatagramPacket dp)
        {
            byte[] dpData = dp.getData();
            int    sType  = 0;

            sType = MessageCheck.checkSType(dp);
            int remote_clientId = ByteIntConvert.toInt(dpData, 8);

            if (sType == MessageType.sType_PingMessage)
            {
                PingMessage pm = new PingMessage(dp);
                sendPingMessage2(pm.getPingId(), dp.getAddress(), dp.getPort());
                currentSpeed = pm.getDownloadSpeed() * 1024;
            }
            else if (sType == MessageType.sType_PingMessage2)
            {
                PingMessage2 pm = new PingMessage2(dp);
                lastReceivePingTime = DateTime.Now.Millisecond;
                long t = pingTable[pm.getPingId()];
                if (t != null)
                {
                    pingDelay = (int)(DateTime.Now.Millisecond - t);
                    String protocal = "";
                    if (route.isUseTcpTun())
                    {
                        protocal = "tcp";
                    }
                    else
                    {
                        protocal = "udp";
                    }
                    //MLog.println("    receive_ping222: "+pm.getPingId()+" "+new Date());
                    //MLog.println("delay_"+protocal+" "+pingDelay+"ms "+dp.getAddress().getHostAddress()+":"+dp.getPort());
                }
            }
        }
Exemplo n.º 6
0
        public void onReceivePacket(DatagramPacket dp)
        {
            DataMessage me;

            if (dp != null)
            {
                if (conn.isConnected())
                {
                    int ver   = MessageCheck.checkVer(dp);
                    int sType = MessageCheck.checkSType(dp);
                    if (ver == RUDPConfig.protocal_ver)
                    {
                        conn.live();
                        if (sType == MessageType.sType_DataMessage)
                        {
                            me = new DataMessage(dp);
                            int        timeId = me.getTimeId();
                            SendRecord record = conn.clientControl.sendRecordTable_remote[timeId];
                            if (record == null)
                            {
                                record = new SendRecord();
                                record.setTimeId(timeId);
                                conn.clientControl.sendRecordTable_remote.Add(timeId, record);
                            }
                            record.addSended(me.getData().Length);

                            if (timeId > currentRemoteTimeId)
                            {
                                currentRemoteTimeId = timeId;
                            }

                            int sequence = me.getSequence();

                            conn.sender.sendAckDelay(me.getSequence());
                            if (sequence > lastRead)
                            {
                                lock (availOb)
                                {
                                    receiveTable.Add(sequence, me);
                                    if (receiveTable.ContainsKey(lastRead + 1))
                                    {
                                        Monitor.Pulse(availOb);   //availOb.notify();//不知对不对
                                    }
                                }
                            }
                        }
                        else if (sType == MessageType.sType_AckListMessage)
                        {
                            AckListMessage alm       = new AckListMessage(dp);
                            int            lastRead3 = alm.getLastRead();
                            if (lastRead3 > lastRead2)
                            {
                                lastRead2 = lastRead3;
                            }
                            List <int> ackList = alm.getAckList();

                            for (int i = 0; i < ackList.Count; i++)
                            {
                                int sequence = ackList[i];
                                conn.sender.removeSended_Ack(sequence);
                            }
                            SendRecord rc1 = conn.clientControl.getSendRecord(alm.getR1());
                            if (rc1 != null)
                            {
                                if (alm.getS1() > rc1.getAckedSize())
                                {
                                    rc1.setAckedSize(alm.getS1());
                                }
                            }

                            SendRecord rc2 = conn.clientControl.getSendRecord(alm.getR2());
                            if (rc2 != null)
                            {
                                if (alm.getS2() > rc2.getAckedSize())
                                {
                                    rc2.setAckedSize(alm.getS2());
                                }
                            }

                            SendRecord rc3 = conn.clientControl.getSendRecord(alm.getR3());
                            if (rc3 != null)
                            {
                                if (alm.getS3() > rc3.getAckedSize())
                                {
                                    rc3.setAckedSize(alm.getS3());
                                }
                            }

                            if (checkWin())
                            {
                                conn.sender.play();
                            }
                        }
                        else if (sType == MessageType.sType_CloseMessage_Stream)
                        {
                            CloseMessage_Stream cm = new CloseMessage_Stream(dp);
                            reveivedClose = true;
                            int n = cm.getCloseOffset();
                            closeStream_Remote(n);
                        }
                        else if (sType == MessageType.sType_CloseMessage_Conn)
                        {
                            CloseMessage_Conn cm2 = new CloseMessage_Conn(dp);
                            conn.close_remote();
                        }
                        else
                        {
                            ////#MLog.println("未处理数据包 "+sType);
                        }
                    }
                }
            }
        }