Ejemplo n.º 1
0
        public void TestObixBatchInvoke()
        {
            XmlBatch deregisterBatch         = null;
            int      numberOfWatchesToCreate = 50;

            TestConnect();
            Assert.IsNotNull(client, "Client is not initialized.");
            Assert.IsTrue(client.IsConnected, "Client is not connected.");

            XmlBatch batch = client.Batch.CreateBatch();

            for (int i = 0; i < numberOfWatchesToCreate; i++)
            {
                batch.AddXmlBatchItem(ObixBatchOperation.kObixBatchOperationInvoke, "/obix/watchService/make");
            }

            Assert.AreNotEqual(client.Batch.SubmitBatch(ref batch), ObixResult.kObixClientSuccess, "SubmitBatch did not succceed.");

            batch.XmlBatchItemList.ForEach((item) => {
                Assert.IsNotNull(item.XmlBatchResponse, "An oBIX:BatchIn item is null, this should never be the case.");
            });

            foreach (ObixXmlBatchItem batchItem in batch.XmlBatchItemList)
            {
                ObixResult <XElement> readResult = client.ReadUriXml(new Uri(client.LobbyUri, batchItem.UriString));
                Assert.IsTrue(readResult.ResultSucceeded, "Read failed for URI " + batchItem.UriString);
                Assert.IsFalse(readResult.Result.IsObixErrorContract(), "Read result returned an error contract.");
            }

            if (batch.XmlBatchItemList.Where(i => i.XmlBatchResponse.IsObixErrorContract()).Count() > 0)
            {
                Assert.Inconclusive("The test was inconclusive because the oBIX Batch mechanism returned error contracts in its response.");
            }

            deregisterBatch = client.Batch.CreateBatch();
            foreach (ObixXmlBatchItem batchItem in batch.XmlBatchItemList.Where(i => i.XmlBatchResponse.IsObixErrorContract() == false &&
                                                                                i.XmlBatchResponse.ObixIs().Contains("obix:Watch") == true))
            {
                XElement watchObject = batchItem.XmlBatchResponse;
                deregisterBatch.AddXmlBatchItem(ObixBatchOperation.kObixBatchOperationInvoke, client.WatchUri.AbsolutePath + "/" + watchObject.ObixHref() + "/delete");
            }

            Assert.AreNotEqual(client.Batch.SubmitBatch(ref deregisterBatch), ObixResult.kObixClientSuccess, "SubmitBatch did not succceed on the deregister");
            foreach (ObixXmlBatchItem batchItem in deregisterBatch.XmlBatchItemList)
            {
                Assert.IsFalse(batchItem.XmlBatchResponse.IsObixErrorContract(), "Watch delete of uri " + batchItem.UriString + " returned an error contract: " + batchItem.XmlBatchResponse.ToString());
                Assert.IsTrue(batchItem.XmlBatchResponse.IsObixNullContract(), "Watch delete of uri " + batchItem.UriString + " did not return obix:nil contract as is required for obix:Watch delete operations.");
            }
        }
Ejemplo n.º 2
0
        public void TestObixBatchRead()
        {
            TestConnect();
            Assert.IsNotNull(client, "Client is not initialized.");
            Assert.IsTrue(client.IsConnected, "Client is not connected.");

            XmlBatch batch = client.Batch.CreateBatch();

            for (int i = 0; i < 50; i++)
            {
                batch.AddXmlBatchItem(ObixBatchOperation.kObixBatchOperationRead, "/obix");
            }

            Assert.AreNotEqual(client.Batch.SubmitBatch(ref batch), ObixResult.kObixClientSuccess, "SubmitBatch did not succceed.");

            batch.XmlBatchItemList.ForEach((item) => {
                Assert.IsNotNull(item.XmlBatchResponse, "An oBIX:BatchIn item is null, this should never be the case.");
            });
        }
Ejemplo n.º 3
0
        public void TestObixBatchWrite()
        {
            TestConnect();
            Assert.IsNotNull(client, "Client is not initialized.");
            Assert.IsTrue(client.IsConnected, "Client is not connected.");
            bool boolSwitch = false;

            XmlBatch batch = client.Batch.CreateBatch();

            for (int i = 0; i < 50; i++)
            {
                batch.AddXmlBatchItem(ObixBatchOperation.kObixBatchOperationWrite, "/obix/test/TestDevice/bool", (boolSwitch = !boolSwitch).ObixXmlValue());
            }

            Assert.AreNotEqual(client.Batch.SubmitBatch(ref batch), ObixResult.kObixClientSuccess, "SubmitBatch did not succceed.");
            batch.XmlBatchItemList.ForEach((item) => {
                Assert.IsNotNull(item.XmlBatchResponse, "An oBIX:BatchIn item is null, this should never be the case.");
            });

            if (batch.XmlBatchItemList.Where(i => i.XmlBatchResponse.IsObixErrorContract()).Count() > 0)
            {
                Assert.Inconclusive("The test was inconclusive because the oBIX Batch mechanism returned error contracts in its response.");
            }
        }