Esempio n. 1
0
        private void TestPutNewComplete()
        {
            var asset = new Asset(
                Guid.NewGuid().ToString("N"),
                7,                 // Notecard
                false,
                false,
                (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds,
                "New Asset",
                "Test of a new asset",
                System.Text.Encoding.UTF8.GetBytes("Just some data.")
                );

            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.PUT, asset.Uuid, asset.Serialize().data);

            request.Send(_socket);
            // Wait until response comes back.
            while (_socket.Available <= 0)
            {
                if (_cancelTest)
                {
                    return;
                }
            }
#pragma warning disable RECS0026 // Possible unassigned object created by 'new'
            new ServerResponseMsg(_socket);
#pragma warning restore RECS0026 // Possible unassigned object created by 'new'
        }
Esempio n. 2
0
        public static Asset CreateAndPutAsset(Socket conn, byte[] assetData = null)
        {
            Contract.Requires(conn != null);

            var asset = new Asset(
                Guid.NewGuid().ToString("N"),
                7,                 // Notecard
                false,
                false,
                (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds,
                "Just junk",
                "Just junk.",
                assetData ?? new byte[] { 0x31, 0x33, 0x33, 0x37 }
                );

            var data = asset.Serialize().data;

            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.PUT, asset.Uuid, data);

            request.Send(conn);

            while (conn.Available <= 0)
            {
            }

            var response = new ServerResponseMsg(conn);

            return(response.Status == ServerResponseMsg.Result.OK ? asset : null);
        }
Esempio n. 3
0
        public static void TestOperationGETWithValidIdReturnsCorrectAsset()
        {
            var asset = CreateAndPutAsset(_socket);

            Assert.NotNull(asset, "Failure storing asset for test.");

            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, asset.Uuid);

            request.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var response       = new ServerResponseMsg(_socket);
            var resultingAsset = new Asset(response.Data);

            Assert.AreEqual(asset.Uuid, resultingAsset.Uuid, "Asset ID fails to match.");
            Assert.AreEqual(asset.Type, resultingAsset.Type, "Asset Type fails to match.");
            Assert.AreEqual(asset.Local, resultingAsset.Local, "Asset Local flag fails to match.");
            Assert.AreEqual(asset.Temporary, resultingAsset.Temporary, "Asset Temporary flag fails to match.");
            Assert.AreEqual(asset.CreateTime, resultingAsset.CreateTime, "Asset CreateTime fails to match.");
            Assert.AreEqual(asset.Name, resultingAsset.Name, "Asset Name fails to match.");
            Assert.AreEqual(asset.Description, resultingAsset.Description, "Asset Description fails to match.");
            Assert.AreEqual(asset.Data, resultingAsset.Data, "Asset Data fails to match.");
        }
Esempio n. 4
0
        public static void TestOperationPURGEWithValidIdRemovedItem()
        {
            var asset = CreateAndPutAsset(_socket);

            Assert.NotNull(asset, "Failure putting asset while prepping for test.");

            var purgeRequest = new ClientRequestMsg(ClientRequestMsg.RequestType.PURGE, asset.Uuid);

            purgeRequest.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var purgeResponse = new ServerResponseMsg(_socket);

            Assert.AreEqual(ServerResponseMsg.Result.OK, purgeResponse.Status, $"Wrong result returned for asset {asset.Uuid}.");

            var getRequest = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, asset.Uuid);

            getRequest.Send(_socket);

            Thread.Sleep(10);
            Assert.NotZero(_socket.Available, "Got nothing from the server!");

            var response = new ServerResponseMsg(_socket);

            Assert.AreEqual(ServerResponseMsg.Result.NOT_FOUND, response.Status, $"Wrong result returned for asset {asset.Uuid}.");
        }
Esempio n. 5
0
        public static void TestOperationPUTWithValidIdReturnsOk()
        {
            var asset = new Asset(
                Guid.NewGuid().ToString("N"),
                7,                 // Notecard
                false,
                false,
                (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds,
                "Just junk",
                "Just junk.",
                new byte[] { 0x31, 0x33, 0x33, 0x37 }
                );

            var data = asset.Serialize().data;

            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.PUT, asset.Uuid, data);

            request.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var response = new ServerResponseMsg(_socket);

            Assert.AreEqual(ServerResponseMsg.Result.OK, response.Status, $"Wrong result returned for asset {asset.Uuid}.");
        }
Esempio n. 6
0
        private void TestPutNewComplete2MB()
        {
            var data = new byte[2097152];

            RandomUtil.Rnd.NextBytes(data);

            var asset = new Asset(
                Guid.NewGuid().ToString("N"),
                7,                 // Notecard
                false,
                false,
                (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds,
                "2MB Asset",
                "Test of a larger asset",
                data
                );

            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.PUT, asset.Uuid, asset.Serialize().data);

            request.Send(_socket);
            // Wait until response comes back.
            while (_socket.Available <= 0)
            {
                if (_cancelTest)
                {
                    return;
                }
            }
#pragma warning disable RECS0026 // Possible unassigned object created by 'new'
            new ServerResponseMsg(_socket);
#pragma warning restore RECS0026 // Possible unassigned object created by 'new'
        }
Esempio n. 7
0
 private void RequestReceivedDelegate(ClientRequestMsg request, WHIPServer.RequestResponseDelegate responseHandler, object context)
 {
     // Queue up for processing.
     _requests.Add(new Request {
         Context         = context,
         RequestMessage  = request,
         ResponseHandler = responseHandler,
     });
 }
Esempio n. 8
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));
        }
Esempio n. 9
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));
        }
Esempio n. 10
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));
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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());
        }
Esempio n. 14
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"));
        }
Esempio n. 15
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);
        }
Esempio n. 16
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());
        }
Esempio n. 17
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 }));
        }
Esempio n. 18
0
        public static void TestOperationSTATUS_GETReturnsOk()
        {
            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.STATUS_GET, Guid.Empty.ToString("N"));

            request.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var response = new ServerResponseMsg(_socket);

            Assert.AreEqual(ServerResponseMsg.Result.OK, response.Status, $"Wrong result returned.");
        }
Esempio n. 19
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));
        }
Esempio n. 20
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")));
        }
Esempio n. 21
0
        public static void TestOperationMAINT_PURGELOCALSReturnsOk()
        {
            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.MAINT_PURGELOCALS, Guid.Empty.ToString("N"));

            request.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var response = new ServerResponseMsg(_socket);

            Assert.AreEqual(ServerResponseMsg.Result.OK, response.Status, $"Wrong result returned for purge locals.");
        }
Esempio n. 22
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);
        }
Esempio n. 23
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));
        }
Esempio n. 24
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"));
        }
Esempio n. 25
0
        public static void TestOperationSTATUS_GETHasExpectedValue()
        {
            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.STATUS_GET, Guid.Empty.ToString("N"));

            request.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var response = new ServerResponseMsg(_socket);

            var statusInfo = response.ErrorMessage;

            Assert.That(statusInfo.StartsWith("WHIP Server Status", StringComparison.InvariantCulture), $"Expected to find 'WHIP Server Status' in the following:\n{statusInfo}");
        }
Esempio n. 26
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);
        }
Esempio n. 27
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);
        }
Esempio n. 28
0
        public static void TestOperationGETWithInvalidIdReturnsError()
        {
            var assetId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, assetId);

            request.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var response = new ServerResponseMsg(_socket);

            Assert.AreEqual(ServerResponseMsg.Result.ERROR, response.Status, $"Wrong result returned for asset {assetId}.");
        }
Esempio n. 29
0
        public static void TestOperationGETWithRandomIdReturnsNotFound()
        {
            var assetId = Guid.NewGuid().ToString("N");

            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.GET, assetId);

            request.Send(_socket);

            while (_socket.Available <= 0)
            {
            }

            var response = new ServerResponseMsg(_socket);

            Assert.AreEqual(ServerResponseMsg.Result.NOT_FOUND, response.Status, $"Wrong result returned for asset {assetId}.");
        }
Esempio n. 30
0
        private void TestTestKnown()
        {
            var request = new ClientRequestMsg(ClientRequestMsg.RequestType.TEST, _knownAsset.Uuid);

            request.Send(_socket);
            // Wait until response comes back.
            while (_socket.Available <= 0)
            {
                if (_cancelTest)
                {
                    return;
                }
            }
#pragma warning disable RECS0026 // Possible unassigned object created by 'new'
            new ServerResponseMsg(_socket);
#pragma warning restore RECS0026 // Possible unassigned object created by 'new'
        }