Пример #1
0
        public static void TestClientRequestMsg_AddRange_AfterHeader1OneByte_True()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[HEADER_SIZE];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            data[DATA_SIZE_MARKER_LOC + 3] = 1;
            msg.AddRange(data);

            Assert.IsTrue(msg.AddRange(new byte[] { 0 }));
        }
Пример #2
0
        public static void TestClientRequestMsg_AddRange_PartialHeaderCompleted_True()
        {
            var msg   = new ClientRequestMsg();
            var data1 = new byte[HEADER_SIZE - 1];

            data1[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data1, UUID_TAG_LOCATION, UUID_LEN);
            msg.AddRange(data1);

            var data2 = new byte[1];

            data2[0] = 0;
            Assert.IsTrue(msg.AddRange(data2));
        }
Пример #3
0
        public static void TestClientRequestMsg_Data_MultiAddRange_Correct()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[HEADER_SIZE];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            data[DATA_SIZE_MARKER_LOC]     = 0;
            data[DATA_SIZE_MARKER_LOC + 1] = 0;
            data[DATA_SIZE_MARKER_LOC + 2] = 0;
            data[DATA_SIZE_MARKER_LOC + 3] = 4;
            msg.AddRange(data);

            msg.AddRange(new byte[] { 250, 251, 252, 253 });

            Assert.AreEqual(new byte[] { 250, 251, 252, 253 }, msg.Data);
        }
Пример #4
0
        public static void TestClientRequestMsg_AddRangeCompleteHeaderNoData_True()
        {
            var msg  = new ClientRequestMsg();
            var data = new byte[HEADER_SIZE];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);

            Assert.IsTrue(msg.AddRange(data));
        }
Пример #5
0
        public static void TestClientRequestMsg_AddRange_WrongHeaderId100_AssetProtocolError()
        {
            var msg  = new ClientRequestMsg();
            var data = new byte[HEADER_SIZE];

            data[REQUEST_TYPE_LOC] = 100;             // Anything not in range of RequestType.
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);

            Assert.Throws <InWorldz.Whip.Client.AssetProtocolError>(() => msg.AddRange(data));
        }
Пример #6
0
        public static void TestClientRequestMsg_AddRange_PartialHeader_DoesntThrow()
        {
            var msg  = new ClientRequestMsg();
            var data = new byte[HEADER_SIZE - 1];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);

            Assert.DoesNotThrow(() => msg.AddRange(data));
        }
Пример #7
0
        public static void TestClientRequestMsg_GetHeaderSummary_TypeSTORED_ASSET_IDS_GET_ContainsSTORED_ASSET_IDS_GET()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[REQUEST_TYPE_LOC + 1];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.STORED_ASSET_IDS_GET;
            msg.AddRange(data);

            Assert.That(msg.GetHeaderSummary(), Contains.Substring("STORED_ASSET_IDS_GET"));
        }
Пример #8
0
        public static void TestClientRequestMsg_GetHeaderSummary_TypeTEST_DoesntThrow()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[REQUEST_TYPE_LOC + 1];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            msg.AddRange(data);

            Assert.DoesNotThrow(() => msg.GetHeaderSummary());
        }
Пример #9
0
        public static void TestClientRequestMsg_IsReady_TypeSent_False()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[REQUEST_TYPE_LOC + 1];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            msg.AddRange(data);

            Assert.IsFalse(msg.IsReady);
        }
Пример #10
0
        public static void TestClientRequestMsg_Type_BarelyAdded_CorrectSTORED_ASSET_IDS_GET()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[REQUEST_TYPE_LOC + 1];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.STORED_ASSET_IDS_GET;
            msg.AddRange(data);

            Assert.AreEqual(RequestType.STORED_ASSET_IDS_GET, msg.Type);
        }
Пример #11
0
        public static void TestClientRequestMsg_GetHeaderSummary_TypeAndUUID_DoesntThrow()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[REQUEST_TYPE_LOC + UUID_TAG_LOCATION + UUID_LEN];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            msg.AddRange(data);

            Assert.DoesNotThrow(() => msg.GetHeaderSummary());
        }
Пример #12
0
        public static void TestClientRequestMsg_IsReady_TypeAndUUIDSent_False()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[REQUEST_TYPE_LOC + UUID_TAG_LOCATION + UUID_LEN];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            msg.AddRange(data);

            Assert.IsFalse(msg.IsReady);
        }
Пример #13
0
        public static void TestClientRequestMsg_GetHeaderSummary_TypeAndUUID_ContainsUUID()
        {
            var msg = new ClientRequestMsg();

            var assetId = Guid.NewGuid();

            var data = new byte[REQUEST_TYPE_LOC + UUID_TAG_LOCATION + UUID_LEN];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(assetId.ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            msg.AddRange(data);

            Assert.That(msg.GetHeaderSummary(), Contains.Substring(assetId.ToString("D")));
        }
Пример #14
0
        public static void TestClientRequestMsg_AddRangeCompleteHeaderNegativeDate_DoesntThrow()
        {
            var msg  = new ClientRequestMsg();
            var data = new byte[HEADER_SIZE];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            data[DATA_SIZE_MARKER_LOC]     = 0xFF;
            data[DATA_SIZE_MARKER_LOC + 1] = 0xFF;
            data[DATA_SIZE_MARKER_LOC + 2] = 0xFF;
            data[DATA_SIZE_MARKER_LOC + 3] = 0xFF;

            Assert.DoesNotThrow(() => msg.AddRange(data));
        }
Пример #15
0
        public static void TestClientRequestMsg_AssetId_BarelyAdded_Correct()
        {
            var msg = new ClientRequestMsg();

            var assetId = Guid.NewGuid();

            var data = new byte[REQUEST_TYPE_LOC + UUID_TAG_LOCATION + UUID_LEN];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(assetId.ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            msg.AddRange(data);

            Assert.AreEqual(assetId, msg.AssetId);
        }
Пример #16
0
        public static void TestClientRequestMsg_Data_Negative_Empty()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[HEADER_SIZE + 123];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            data[DATA_SIZE_MARKER_LOC]     = 0xFF;
            data[DATA_SIZE_MARKER_LOC + 1] = 0xFF;
            data[DATA_SIZE_MARKER_LOC + 2] = 0xFF;
            data[DATA_SIZE_MARKER_LOC + 3] = 0xFF;
            msg.AddRange(data);

            Assert.IsEmpty(msg.Data);
        }
Пример #17
0
        public static void TestClientRequestMsg_GetHeaderSummary_TypeAndUUIDAndDataLength123_Contains123()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[HEADER_SIZE + 123];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            data[DATA_SIZE_MARKER_LOC]     = 0;
            data[DATA_SIZE_MARKER_LOC + 1] = 0;
            data[DATA_SIZE_MARKER_LOC + 2] = 0;
            data[DATA_SIZE_MARKER_LOC + 3] = 123;
            msg.AddRange(data);

            Assert.That(msg.GetHeaderSummary(), Contains.Substring("123"));
        }
Пример #18
0
        public static void TestClientRequestMsg_IsReady_FullHeaderSentData123_True()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[HEADER_SIZE + 123];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            data[DATA_SIZE_MARKER_LOC]     = 0;
            data[DATA_SIZE_MARKER_LOC + 1] = 0;
            data[DATA_SIZE_MARKER_LOC + 2] = 0;
            data[DATA_SIZE_MARKER_LOC + 3] = 123;
            msg.AddRange(data);

            Assert.IsTrue(msg.IsReady);
        }
Пример #19
0
        public static void TestClientRequestMsg_Data_SentMoreThanExpected_OnlyExpected()
        {
            var msg = new ClientRequestMsg();

            var data = new byte[HEADER_SIZE + 123];

            data[REQUEST_TYPE_LOC] = (byte)RequestType.TEST;
            Buffer.BlockCopy(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString("N")), 0, data, UUID_TAG_LOCATION, UUID_LEN);
            data[DATA_SIZE_MARKER_LOC]     = 0;
            data[DATA_SIZE_MARKER_LOC + 1] = 0;
            data[DATA_SIZE_MARKER_LOC + 2] = 0;
            data[DATA_SIZE_MARKER_LOC + 3] = 3;
            data[HEADER_SIZE]     = 250;
            data[HEADER_SIZE + 1] = 251;
            data[HEADER_SIZE + 2] = 252;
            data[HEADER_SIZE + 3] = 253;
            msg.AddRange(data);

            Assert.AreEqual(new byte[] { 250, 251, 252 }, msg.Data);
        }
Пример #20
0
        public static void TestClientRequestMsg_AddRange_Empty_DoesntThrow()
        {
            var msg = new ClientRequestMsg();

            Assert.DoesNotThrow(() => msg.AddRange(new byte[] { }));
        }
Пример #21
0
        public static void TestClientRequestMsg_AddRange_Null_ArgumentNullException()
        {
            var msg = new ClientRequestMsg();

            Assert.Throws <ArgumentNullException>(() => msg.AddRange(null));
        }