Example #1
0
        //TODO: Do this in a cleaner way
        public BackupItem getBackupItem(int i)
        {
            List <BackupItem> items = new List <BackupItem>();
            //BackupItems
            BackupItem item1 = new BackupItem();

            item1.d = "12566132";
            item1.s = 442;
            item1.t = new DateTime(2015, 5, 11, 2, 4, 22, 295);
            item1.c = false;
            BackupItem item2 = new BackupItem();

            item2.d = "534235721";
            item2.s = 442;
            item2.t = new DateTime(2015, 5, 11, 2, 4, 28, 216);
            item2.c = false;
            BackupItem item3 = new BackupItem();

            item3.d = "892535";
            item3.s = 442;
            item3.t = new DateTime(2015, 5, 11, 2, 4, 25, 142);
            item3.c = false;

            items.Add(item1);
            items.Add(item2);
            items.Add(item3);

            return(items[i - 1]);
        }
Example #2
0
        // Invalid Single Backup Item
        public void InvalidSingleBackupItem()
        {
            BackupItem failItem = new BackupItem();

            BackupItem[] failItems = new BackupItem[1];
            failItems[0] = failItem;

            DeviceBackupJSON failJson = new DeviceBackupJSON();

            failJson.i = validSerial;
            failJson.s = 5;
            failJson.b = failItems;

            DeviceBackup failOperation = new DeviceBackup(testServer, failJson);
            Test         failingTest   = new Test(failOperation);

            failingTest.setTestName("InvalidSingleBackupItem");

            List <Test> tests = new List <Test>();

            tests.Add(failingTest);
            AsyncContext.Run(async() => await Program.buildTests(tests));

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Example #3
0
        // Multiple valid backup items with simple and dyn code
        public void ValidBackupItemsSimDyn()
        {
            BackupItem[] items = new BackupItem[2];
            items[0]   = new BackupItem();
            items[0].d = "~20/12345|";
            items[0].s = 442;
            items[0].t = new DateTime(2015, 5, 11, 2, 4, 22, 295);
            items[0].c = false;

            items[1] = getBackupItem(1);

            DeviceBackupJSON serialJson = new DeviceBackupJSON();

            serialJson.s = 6;
            serialJson.b = items;
            serialJson.i = validSerial;

            DeviceBackup serialOperation = new DeviceBackup(testServer, serialJson);

            Test serialTest = new Test(serialOperation);

            serialTest.setTestName("ValidBackupItemsSimDyn");

            List <Test> tests = new List <Test>();

            tests.Add(serialTest);
            AsyncContext.Run(async() => await Program.buildTests(tests));

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Example #4
0
        // No Backup Items
        public void NoBackupItems()
        {
            BackupItem[] items = new BackupItem[0];

            DeviceBackupJSON emptyJson = new DeviceBackupJSON();

            emptyJson.i = validSerial;
            emptyJson.s = 8;
            emptyJson.b = items;

            DeviceBackup emptyOperation = new DeviceBackup(testServer, emptyJson);
            Test         emptyTest      = new Test(emptyOperation);

            emptyTest.setTestName("NoBackupItems");


            List <Test> tests = new List <Test>();

            tests.Add(emptyTest);
            AsyncContext.Run(async() => await Program.buildTests(tests));

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Example #5
0
        // Input with Null Serial Number
        public void NullSerial()
        {
            BackupItem[] items = new BackupItem[3];
            items[0] = getBackupItem(1);
            items[1] = getBackupItem(2);
            items[2] = getBackupItem(3);

            DeviceBackupJSON serialJson = new DeviceBackupJSON();

            serialJson.s = 6;
            serialJson.b = items;
            serialJson.i = null;

            DeviceBackup serialOperation = new DeviceBackup(testServer, serialJson);

            Test serialTest = new Test(serialOperation);

            serialTest.setTestName("NullSerial");

            List <Test> tests = new List <Test>();

            tests.Add(serialTest);
            AsyncContext.Run(async() => await Program.buildTests(tests));

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Example #6
0
        // Valid Single Backup Item
        public void ValidSingleBackupItem()
        {
            BackupItem[] items = new BackupItem[1];
            items[0] = getBackupItem(1);

            //BackupJSon
            DeviceBackupJSON json = new DeviceBackupJSON();

            json.i = validSerial;
            json.s = 4;
            json.b = items;

            //BackupOperation
            DeviceBackup operation = new DeviceBackup(testServer, json);

            //Test
            Test backupTest = new Test(operation);

            backupTest.setTestName("ValidSingleBackupItem");
            List <Test> tests = new List <Test>();

            tests.Add(backupTest);
            AsyncContext.Run(async() => await Program.buildTests(tests));

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
        //TODO: Do this in a cleaner way
        public static BackupItem getBackupItem(int i)
        {
            List<BackupItem> items = new List<BackupItem>();
            //BackupItems
            BackupItem item1 = new BackupItem();
            item1.d = "12566132";
            item1.s = 442;
            item1.t = new DateTime(2015, 5, 11, 2, 4, 22, 295);
            item1.c = false;
            BackupItem item2 = new BackupItem();
            item2.d = "534235721";
            item2.s = 442;
            item2.t = new DateTime(2015, 5, 11, 2, 4, 28, 216);
            item2.c = false;
            BackupItem item3 = new BackupItem();
            item3.d = "892535";
            item3.s = 442;
            item3.t = new DateTime(2015, 5, 11, 2, 4, 25, 142);
            item3.c = false;

            items.Add(item1);
            items.Add(item2);
            items.Add(item3);

            return items[i - 1];
        }
        public void AsyncHTTPDeviceBackup()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPAsync);
            results = new StreamWriter(stream);

            BackupItem[] items = new BackupItem[1];
            items[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);

            //BackupJSon
            DeviceBackupJSON json = new DeviceBackupJSON();
            json.i = TestGlobals.validSerial;
            json.s = 4;
            json.b = items;

            //BackupOperation
            DeviceBackup operation = new DeviceBackup(TestGlobals.testServer, json);

            //Test
            Test backupTest = new Test(operation);
            backupTest.setTestName("ValidSingleBackupItem");
            backupTest.setExpectedResult ("201");
            backupTest.setType ("performance");
            // Construct started tasks
            Task<double>[] tasks = new Task<double>[TestGlobals.maxReps];
            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Threading.Thread.Sleep(TestGlobals.delay);
                tasks[i] = new HTTPCalls().runTest(backupTest, HTTPOperation.POST);
                Console.WriteLine("Test starting:" + i.ToString());
            }
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("All tests initialized, waiting on them to run as async");
            Console.WriteLine("------------------------------------------------------");
            Task.WaitAll(tasks);

            foreach (Task<double> nextResult in tasks)
            {
                results.WriteLine("Test Time," + nextResult.Result);
            }
            results.Close();
        }
        public void AsyncHTTPDeviceBackup()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPAsync);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: AsyncHTTPDeviceBackup");
            log.WriteLine ("Current Time: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
            log.WriteLine ("Test Run times: " + TestGlobals.maxReps);
            log.WriteLine ("Server: " + TestGlobals.testServer);

            BackupItem[] items = new BackupItem[1];
            items[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);

            //BackupJSon

            // Construct started tasks
            Task<double>[] tasks = new Task<double>[TestGlobals.maxReps];

            DateTime[] testStarted = new DateTime [TestGlobals.maxReps];
            JObject[] bkPosted = new JObject[TestGlobals.maxReps];

            for (int i = 0; i < TestGlobals.maxReps; i++)
            {

                DeviceBackupJSON json = new DeviceBackupJSON();
                json.i = TestGlobals.validSerial;
                json.s = i;
                json.b = items;

                //BackupOperation
                DeviceBackup operation = new DeviceBackup(TestGlobals.testServer, json);

                //Test
                Test backupTest = new Test(operation);
                backupTest.setTestName("ValidSingleBackupItem");
                backupTest.setExpectedResult ("201");
                backupTest.setType ("performance");

                System.Threading.Thread.Sleep(TestGlobals.delay);
                tasks[i] = new HTTPCalls().runTest(backupTest, HTTPOperation.POST);
                testStarted [i] = HTTPCalls.started;
                JObject Json = JObject.FromObject(json);
                bkPosted[i] = Json;

                Console.WriteLine("Test starting:" + i.ToString());
            }
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("All tests initialized, waiting on them to run as async");
            Console.WriteLine("------------------------------------------------------");
            Task.WaitAll(tasks);

            int seq = 0;
            foreach (Task<double> nextResult in tasks)
            {
                results.WriteLine("Test Time," + nextResult.Result);

                log.WriteLine ("Test " + seq + " Started at " + testStarted[seq].ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
                log.WriteLine ("Json Posted:");
                log.WriteLine (bkPosted[seq].ToString ());
                log.WriteLine ("Test Lasted: " + nextResult.Result + "ms");
                seq++;
                if (seq < 99)
                {
                    log.WriteLine ();
                }

            }

            DateTime ended = DateTime.Now;
            TimeSpan lasted = ended - started;

            log.WriteLine ("Test Ended: AsyncHTTPDeviceBackup");
            log.WriteLine ("Current Time: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
            log.WriteLine ("Test lasted: " + lasted);
            log.WriteLine ("\n\n");

            results.Close();
        }
        public void ValidSingleBackupItem()
        {
            BackupItem[] items = new BackupItem[1];
            items[0] = getBackupItem(1);

            //BackupJSon
            DeviceBackupJSON json = new DeviceBackupJSON();
            json.i = TestGlobals.validSerial;
            json.s = 4;
            json.b = items;

            Uri uri = new Uri(TestGlobals.testServer, "/api/DeviceBackup/");

            results.WriteLine(DateTime.Now);

            AsyncContext.Run(async () => await new HTTPSCalls().RunPostAsync(uri, json));
            string statusCode = HTTPSCalls.result.Key.Property("StatusCode").Value.ToString();

            results.WriteLine("Json posted:");
            results.WriteLine(json.ToString());
            results.WriteLine("Server: " + TestGlobals.testServer);
            results.WriteLine("Expected result: 201");
            results.WriteLine("Actual result: " + statusCode);
            results.WriteLine("Test result: " + HTTPSCalls.result.Key.ToString());
            results.WriteLine();

            Assert.AreEqual("201", statusCode);
        }
        public void ValidBackupItemsSimDyn()
        {
            BackupItem[] items = new BackupItem[2];
            items[0] = new BackupItem();
            items[0].d = "~20/12345|";
            items[0].s = 442;
            items[0].t = new DateTime(2015, 5, 11, 2, 4, 22, 295);
            items[0].c = false;

            items[1] = getBackupItem(1);

            DeviceBackupJSON serialJson = new DeviceBackupJSON();
            serialJson.s = 6;
            serialJson.b = items;
            serialJson.i = TestGlobals.validSerial;

            Uri uri = new Uri(TestGlobals.testServer, "/api/DeviceBackup/");

            results.WriteLine(DateTime.Now);

            AsyncContext.Run(async () => await new HTTPSCalls().RunPostAsync(uri, serialJson));
            string statusCode = HTTPSCalls.result.Key.Property("StatusCode").Value.ToString();

            results.WriteLine("Json posted:");
            results.WriteLine(serialJson.ToString());
            results.WriteLine("Server: " + TestGlobals.testServer);
            results.WriteLine("Expected result: " + "201");
            results.WriteLine("Actual result: " + statusCode);
            results.WriteLine("Test result: " + HTTPSCalls.result.Key.ToString());
            results.WriteLine();

            Assert.AreEqual("201", statusCode);
        }
        public void SyncHTTPSDeviceBackup()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPSSync);
            results = new StreamWriter(stream);

            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
                BackupItem[] items = new BackupItem[1];
                items[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);

                //BackupJSon
                DeviceBackupJSON json = new DeviceBackupJSON();
                json.i = TestGlobals.validSerial;
                json.s = 4;
                json.b = items;

                //BackupOperation
                DeviceBackup operation = new DeviceBackup(TestGlobals.testServer, json);

                //Test
                Test backupTest = new Test(operation);
                backupTest.setTestName("ValidSingleBackupItem");
                backupTest.setExpectedResult ("201");
                backupTest.setType ("performance");

                timer.Start();
                AsyncContext.Run(async () => await new HTTPSCalls().runTest(backupTest, HTTPOperation.POST));
                timer.Stop();
                double time = timer.Elapsed.TotalMilliseconds;
                results.WriteLine("Test Time," + time);
                System.Threading.Thread.Sleep(TestGlobals.delay);
                //Verify Server didn't throw up
            }
            results.Close();
        }
        public void SyncHTTPSDeviceBackup()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPSSync);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: SyncHTTPSDeviceBackup");
            log.WriteLine ("Current Time: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
            log.WriteLine ("Test Run times: " + TestGlobals.maxReps);
            log.WriteLine ("Server: " + TestGlobals.testServer);

            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
                BackupItem[] items = new BackupItem[1];
                items[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);

                //BackupJSon
                DeviceBackupJSON json = new DeviceBackupJSON();
                json.i = TestGlobals.validSerial;
                json.s = i;
                json.b = items;

                //BackupOperation
                DeviceBackup operation = new DeviceBackup(TestGlobals.testServer, json);

                //Test
                Test backupTest = new Test(operation);
                backupTest.setTestName("ValidSingleBackupItem");
                backupTest.setExpectedResult ("201");
                backupTest.setType ("performance");

                log.WriteLine ("Test " + i + " Started at " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
                timer.Start();
                AsyncContext.Run(async () => await new HTTPSCalls().runTest(backupTest, HTTPOperation.POST));
                timer.Stop();

                JObject posted = JObject.FromObject (json);
                log.WriteLine ("Json Posted:");
                log.WriteLine (posted.ToString ());

                double time = timer.Elapsed.TotalMilliseconds;
                results.WriteLine("Test Time," + time);
                log.WriteLine ("Test Lasted: " + time + "ms");

                if (i < 99)
                {
                    log.WriteLine ();
                }

                System.Threading.Thread.Sleep(TestGlobals.delay);
                //Verify Server didn't throw up
            }

            DateTime ended = DateTime.Now;
            TimeSpan lasted = ended - started;

            log.WriteLine ("Test Ended: SyncHTTPSDeviceBackup");
            log.WriteLine ("Current Time: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
            log.WriteLine ("Test lasted: " + lasted);
            log.WriteLine ("\n\n");

            results.Close();
        }
        public void MultiClientDeviceBackup()
        {
            FileStream stream;
            stream = File.Create(outputFileMultiClientDeviceBackup);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: MultiClientDeviceBackup");
            log.WriteLine ("Current Time: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
            log.WriteLine ("Server: " + TestGlobals.testServer);

            BackupItem[] items = new BackupItem[1];
            items[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);

            BackupItem[] items2 = new BackupItem[1];
            items2[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);

            // Construct started tasks
            Task<double>[,] tasks = new Task<double>[TestGlobals.maxReps, 2];
            DateTime[] testStarted1 = new DateTime[TestGlobals.maxReps];
            DateTime[] testStarted2 = new DateTime[TestGlobals.maxReps];
            JObject[] bkPosted1 = new JObject[TestGlobals.maxReps];
            JObject[] bkPosted2 = new JObject[TestGlobals.maxReps];

            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Threading.Thread.Sleep(TestGlobals.delay);

                // client 1
                DeviceBackupJSON json = new DeviceBackupJSON();
                json.i = TestGlobals.validSerial;
                json.s = i;
                json.b = items;
                DeviceBackup operation1 = new DeviceBackup(TestGlobals.testServer, json);

                Test backupTest1 = new Test(operation1);
                backupTest1.setTestName("ValidSingleBackupItem");
                backupTest1.setExpectedResult ("201");
                backupTest1.setType ("performance");

                tasks[i, 0] = new HTTPCalls().runTest(backupTest1, HTTPOperation.POST);
                testStarted1[i] = HTTPCalls.started;
                JObject Json = JObject.FromObject(json);
                bkPosted1[i] = Json;

                // client 2
                DeviceBackupJSON json2 = new DeviceBackupJSON();
                json2.i = TestGlobals.validSerial;
                json2.s = i;
                json2.b = items;
                DeviceBackup operation2 = new DeviceBackup(TestGlobals.testServer, json);

                Test backupTest2 = new Test(operation2);
                backupTest2.setTestName("ValidSingleBackupItem");
                backupTest2.setExpectedResult ("201");
                backupTest2.setType ("performance");

                tasks[i, 1] = new HTTPCalls().runTest(backupTest2, HTTPOperation.POST);
                Console.WriteLine("Test starting:" + i.ToString());
                testStarted2[i] = HTTPCalls.started;
                JObject Json2 = JObject.FromObject(json2);
                bkPosted2[i] = Json2;

                Task.WaitAll(tasks[i, 0], tasks[i, 1]);
            }

            log.WriteLine ("Client 1:");
            for(int i = 0; i < TestGlobals.maxReps; i++)
            {
                results.WriteLine ("Test Time," + tasks[i, 0].Result);

                log.WriteLine ("Client 1 Test " + i + " Started at " + testStarted1 [i].ToString ("yyyy-MM-dd hh:mm:ss.ffffff"));
                log.WriteLine ("Json Posted:");
                log.WriteLine (bkPosted1 [i].ToString ());
                log.WriteLine ("Test Lasted: " + tasks[i, 0].Result + "ms");
                log.WriteLine ();
            }

            log.WriteLine ("Client 2:");
            for(int i = 0; i < TestGlobals.maxReps; i++)
            {
                results.WriteLine ("Test Time," + tasks[i, 1].Result);

                log.WriteLine ("Client 2 Test " + i + " Started at " + testStarted2 [i].ToString ("yyyy-MM-dd hh:mm:ss.ffffff"));
                log.WriteLine ("Json Posted:");
                log.WriteLine (bkPosted2 [i].ToString ());
                log.WriteLine ("Test Lasted: " + tasks[i, 1].Result + "ms");
                if (i < 99)
                {
                    log.WriteLine ();
                }
            }

            DateTime ended = DateTime.Now;
            TimeSpan lasted = ended - started;

            log.WriteLine ("Test Ended: MultiClientDeviceBackup");
            log.WriteLine ("Current Time: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.ffffff"));
            log.WriteLine ("Test lasted: " + lasted);
            log.WriteLine ("\n\n");

            results.Close();
        }
        public void ValidSingleBackupItem()
        {
            BackupItem[] items = new BackupItem[1];
            items[0] = getBackupItem(1);

            //BackupJSon
            DeviceBackupJSON json = new DeviceBackupJSON();
            json.i = TestGlobals.validSerial;
            json.s = 4;
            json.b = items;

            //BackupOperation
            DeviceBackup operation = new DeviceBackup(TestGlobals.testServer, json);

            //Test
            Test backupTest = new Test(operation);
            backupTest.setTestName("ValidSingleBackupItem");
            backupTest.setExpectedResult ("201");

            results.WriteLine (DateTime.Now);
            results.WriteLine ("current test: " + backupTest.ToString () + " " + backupTest.getTestName ());

            AsyncContext.Run(async () => await new HTTPSCalls().runTest(backupTest, HTTPOperation.POST));
            string statusCode = HTTPSCalls.result.Key.Property("StatusCode").Value.ToString();

            results.WriteLine("Json posted:");
            results.WriteLine (operation.getJson().ToString());
            results.WriteLine ("Server: " + TestGlobals.testServer);
            results.WriteLine ("Expected result: " + backupTest.getActualResult());
            results.WriteLine ("Actual result: " + statusCode);
            results.WriteLine ("Test result: " + backupTest.result ());
            results.WriteLine ();

            Assert.AreEqual("201", statusCode);
        }
        public void ValidBackupItemsSimDyn()
        {
            BackupItem[] items = new BackupItem[2];
            items[0] = new BackupItem();
            items[0].d = "~20/12345|";
            items[0].s = 442;
            items[0].t = new DateTime(2015, 5, 11, 2, 4, 22, 295);
            items[0].c = false;

            items[1] = getBackupItem(1);

            DeviceBackupJSON serialJson = new DeviceBackupJSON();
            serialJson.s = 6;
            serialJson.b = items;
            serialJson.i = TestGlobals.validSerial;

            DeviceBackup operation = new DeviceBackup(TestGlobals.testServer, serialJson);

            Test backupTest = new Test(operation);
            backupTest.setTestName("ValidBackupItemSimDyn");
            backupTest.setExpectedResult ("201");

            results.WriteLine (DateTime.Now);
            results.WriteLine ("current test: " + backupTest.ToString () + " " + backupTest.getTestName ());

            AsyncContext.Run(async () => await new HTTPSCalls().runTest(backupTest, HTTPOperation.POST));
            string statusCode = HTTPSCalls.result.Key.Property("StatusCode").Value.ToString();

            results.WriteLine("Json posted:");
            results.WriteLine (operation.getJson().ToString());
            results.WriteLine ("Server: " + TestGlobals.testServer);
            results.WriteLine ("Expected result: " + backupTest.getActualResult());
            results.WriteLine ("Actual result: " + statusCode);
            results.WriteLine ("Test result: " + backupTest.result ());
            results.WriteLine ();

            Assert.AreEqual("201", statusCode);
        }
        public void NullSerial()
        {
            BackupItem[] items = new BackupItem[3];
            items[0] = getBackupItem(1);
            items[1] = getBackupItem(2);
            items[2] = getBackupItem(3);

            DeviceBackupJSON serialJson = new DeviceBackupJSON();
            serialJson.s = 6;
            serialJson.b = items;
            serialJson.i = null;

            DeviceBackup operation = new DeviceBackup(TestGlobals.testServer, serialJson);

            Test backupTest = new Test(operation);
            backupTest.setTestName("NullSerial");
            backupTest.setExpectedResult ("400");

            results.WriteLine (DateTime.Now);
            results.WriteLine ("current test: " + backupTest.ToString () + " " + backupTest.getTestName ());

            AsyncContext.Run(async () => await new HTTPSCalls().runTest(backupTest, HTTPOperation.POST));
            string statusCode = HTTPSCalls.result.Key.Property("StatusCode").Value.ToString();

            results.WriteLine("Json posted:");
            results.WriteLine (operation.getJson().ToString());
            results.WriteLine ("Server: " + TestGlobals.testServer);
            results.WriteLine ("Expected result: " + backupTest.getActualResult());
            results.WriteLine ("Actual result: " + statusCode);
            results.WriteLine ("Test result: " + backupTest.result ());
            results.WriteLine ();

            Assert.AreEqual("400", statusCode);
        }
        public void NullSerial()
        {
            BackupItem[] items = new BackupItem[3];
            items[0] = getBackupItem(1);
            items[1] = getBackupItem(2);
            items[2] = getBackupItem(3);

            DeviceBackupJSON serialJson = new DeviceBackupJSON();
            serialJson.s = 6;
            serialJson.b = items;
            serialJson.i = null;

            Uri uri = new Uri(TestGlobals.testServer, "/api/DeviceBackup/");

            results.WriteLine(DateTime.Now);

            AsyncContext.Run(async () => await new HTTPSCalls().RunPostAsync(uri, serialJson));
            string statusCode = HTTPSCalls.result.Key.Property("StatusCode").Value.ToString();

            results.WriteLine("Json posted:");
            results.WriteLine(serialJson.ToString());
            results.WriteLine("Server: " + TestGlobals.testServer);
            results.WriteLine("Expected result: 400");
            results.WriteLine("Actual result: " + statusCode);
            results.WriteLine("Test result: " + HTTPSCalls.result.Key.ToString());
            results.WriteLine();

            Assert.AreEqual("400", statusCode);
        }
        public void multiClientDeviceBackup()
        {
            FileStream stream;
            stream = File.Create(outputFileMultiClientDeviceBackup);
            results = new StreamWriter(stream);

            BackupItem[] items = new BackupItem[1];
            items[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);
            DeviceBackupJSON json = new DeviceBackupJSON();
            json.i = TestGlobals.validSerial;
            json.s = 4;
            json.b = items;
            DeviceBackup operation1 = new DeviceBackup(TestGlobals.testServer, json);

            Test backupTest1 = new Test(operation1);
            backupTest1.setTestName("ValidSingleBackupItem");
            backupTest1.setExpectedResult ("201");
            backupTest1.setType ("performance");

            BackupItem[] items2 = new BackupItem[1];
            items2[0] = InterceptorTests.DeviceBackupTest.getBackupItem(1);
            DeviceBackupJSON json2 = new DeviceBackupJSON();
            json2.i = TestGlobals.validSerial;
            json2.s = 4;
            json2.b = items;
            DeviceBackup operation2 = new DeviceBackup(TestGlobals.testServer, json);

            Test backupTest2 = new Test(operation2);
            backupTest2.setTestName("ValidSingleBackupItem");
            backupTest2.setExpectedResult ("201");
            backupTest2.setType ("performance");

            // Construct started tasks
            Task<double>[,] tasks = new Task<double>[TestGlobals.maxReps, 2];
            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Threading.Thread.Sleep(TestGlobals.delay);
                tasks[i, 0] = new HTTPCalls().runTest(backupTest1, HTTPOperation.POST);
                tasks[i, 1] = new HTTPCalls().runTest(backupTest2, HTTPOperation.POST);
                Console.WriteLine("Test starting:" + i.ToString());
                Task.WaitAll(tasks[i, 0], tasks[i, 1]);
            }

            foreach (Task<double> nextResult in tasks)
            {
                results.WriteLine("Test Time," + nextResult.Result);
            }

            results.Close();
        }