Beispiel #1
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());
            }
        }
Beispiel #2
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());
            }
        }
Beispiel #3
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());
            }
        }
Beispiel #4
0
        // Bad Serial
        public void InvalidSerialSimple()
        {
            DeviceScanJSON testJson = new DeviceScanJSON();

            testJson.i = "BAD SERIAL";
            testJson.d = "1289472198573";
            testJson.b = null;
            testJson.s = 4;
            DeviceScan testDScan = new DeviceScan(testServer, testJson);

            Test scanTest = new Test(testDScan);

            scanTest.setTestName("InvalidSerialSimple");


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

            tests.Add(scanTest);

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Beispiel #5
0
        // Invalid Single Scan
        public void InvalidSingleScanSimple()
        {
            //TODO: Given when then comments
            // var getThing = appconfig.get(invalidScanData);

            DeviceScanJSON testJson = new DeviceScanJSON();

            testJson.i = validSerial;
            testJson.d = "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm";
            testJson.b = null;
            testJson.s = 4;
            DeviceScan testDScan = new DeviceScan(testServer, testJson);

            Test scanTest = new Test(testDScan);

            scanTest.setTestName("InvalidSingleScanSimple");


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

            tests.Add(scanTest);

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Beispiel #6
0
        // No Serial (Null)
        public void NullSerialDyn()
        {
            DeviceScanJSON testJson = new DeviceScanJSON();

            testJson.i = null;
            testJson.d = "~20/90210|";
            testJson.b = null;
            testJson.s = 4;
            DeviceScan testDScan = new DeviceScan(testServer, testJson);

            Test scanTest = new Test(testDScan);

            scanTest.setTestName("NullSerialDyn");


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

            tests.Add(scanTest);

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Beispiel #7
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());
            }
        }
Beispiel #8
0
        // List of Valid Scans
        public void LOValidScansDyn()
        {
            DeviceScanJSON testJson = new DeviceScanJSON();

            testJson.i = validSerial;
            testJson.d = null;
            string[] scanData = new string[4];
            scanData[0] = "~20/0|";
            scanData[1] = "~20/1|";
            scanData[2] = "~20/2|";
            scanData[3] = "~20/3|";
            testJson.b  = scanData;
            testJson.s  = 4;
            DeviceScan testDScan = new DeviceScan(testServer, testJson);

            Test scanTest = new Test(testDScan);

            scanTest.setTestName("LOValidScansDyn");


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

            tests.Add(scanTest);

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Beispiel #9
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());
            }
        }
Beispiel #10
0
        // Mixed of Valid and Invalid Scans
        public void ValInvalScansSimDyn()
        {
            DeviceScanJSON testJson = new DeviceScanJSON();

            testJson.i = validSerial;
            testJson.d = null;
            string[] scanData = new string[4];
            scanData [0] = "~20/0|";
            scanData [1] = "123456789";
            scanData [2] = "~20/noendingbar";
            scanData [3] = "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm";;
            testJson.b   = scanData;
            testJson.s   = 4;
            DeviceScan testDScan = new DeviceScan(testServer, testJson);

            Test scanTest = new Test(testDScan);

            scanTest.setTestName("ValInvalScansSimDyn");


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

            tests.Add(scanTest);

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
        //[Test()]
        // No Serial (Empty Sting)
        public void EmptySerialDyn()
        {
            DeviceScanJSON testJson = new DeviceScanJSON ();
            testJson.i = "";
            testJson.d = "~20/90210|";
            testJson.b = null;
            testJson.s = 4;
            DeviceScan testDScan = new DeviceScan (TestGlobals.testServer, testJson);

            Test scanTest = new Test (testDScan);
            scanTest.setTestName("EmptySerialDyn");
            scanTest.setExpectedResult ("400");

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

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

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

            Assert.AreEqual("400", statusCode);
        }
        public void AsyncHTTPSICmd()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPSAsync);
            results = new StreamWriter(stream);
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

            ICmd validICmd = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
            Test validTest = new Test(validICmd);
            validTest.setTestName("ValidSerial");
            validTest.setExpectedResult ("200");
            validTest.setType ("performance");
            List<Test> tests = new List<Test>();
            tests.Add(validTest);

            // 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 HTTPSCalls().runTest(validTest, HTTPOperation.GET);
                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();
        }
        //[Test()]
        public void AlertDataStore()
        {
            DeviceStatusJSON status = new DeviceStatusJSON();
            status.bkupURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceBackup";
            status.callHomeTimeoutData = null;
            status.callHomeTimeoutMode = "0";
            status.capture = "1";
            status.captureMode = "1";
            status.cmdChkInt = "1";
            status.cmdURL = "http://cozumotesttls.cloudapp.net:80/api/iCmd";
            string[] err = new string[1];
            err[0] = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")+ "///900///bypassmode";
            status.Ssid = "43B81B4F768D0549AB4F178022DEB384";
            status.wpaPSK = "wifipassword";
            status.errorLog = err;
            status.dynCodeFormat = err;
            status.intSerial = TestGlobals.validSerial;
            status.reportURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceStatus";
            status.requestTimeoutValue = "8000";
            status.revId = "52987";
            status.scanURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceScan";
            status.seqNum = "87";
            status.startURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceSetting";

            DeviceStatus operation = new DeviceStatus(TestGlobals.testServer, status);
            Test statusTest = new Test(operation);
            statusTest.setTestName("AlertDataStore");
            statusTest.setExpectedResult ("201");

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

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

            results.WriteLine("Json posted:");
            results.WriteLine(statusTest.getOperation().getJson().ToString());
            results.WriteLine("Server returned:");
            results.WriteLine(HTTPSCalls.result.Key.ToString());
            results.WriteLine(HTTPSCalls.result.Value.ToString());
            results.WriteLine ("Server: " + TestGlobals.testServer);
            results.WriteLine ("Expected result: " + statusTest.getActualResult());
            results.WriteLine ("Actual result: " + statusCode);
            results.WriteLine ("Test result: " + statusTest.result ());
            results.WriteLine ();

            Assert.AreEqual("201", statusCode);
        }
Beispiel #14
0
        public void ValidSerial()
        {
            DeviceStatusJSON status = new DeviceStatusJSON();

            status.bkupURL             = "http://cozumotesttls.cloudapp.net:80/api/DeviceBackup";
            status.callHomeTimeoutData = "";
            status.callHomeTimeoutMode = "0";
            status.capture             = "1";
            status.captureMode         = "1";
            status.cmdChkInt           = "1";
            status.cmdURL = "http://cozumotesttls.cloudapp.net:80/api/iCmd";
            string[] err = new string[3];
            err[0] = "asdf";
            err[1] = "wasd";
            err[2] = "qwerty";
            status.dynCodeFormat       = err;
            status.errorLog            = err;
            status.intSerial           = validSerial;
            status.reportURL           = "http://cozumotesttls.cloudapp.net:80/api/DeviceStatus";
            status.requestTimeoutValue = "8000";
            status.revId    = "52987";
            status.scanURL  = "http://cozumotesttls.cloudapp.net:80/api/DeviceScan";
            status.seqNum   = "87";
            status.startURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceSetting";

            DeviceStatus operation  = new DeviceStatus(server, status);
            Test         statusTest = new Test(operation);

            statusTest.setTestName("ValidSerial");


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

            //for (int i = 0; i < 1000; i++)
            //{
            tests.Add(statusTest);
            //}

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Beispiel #15
0
        public void InvalidSerial()
        {
            //Invalid
            ICmd invalidICmd = new ICmd(testServer, invalidSerial);
            Test invalidTest = new Test(invalidICmd);

            invalidTest.setTestName("BadSerial");

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

            tests.Add(invalidTest);

            AsyncContext.Run(async() => await Program.buildTests(tests));
            foreach (Test nextTest in Program.getTests())
            {
                Console.WriteLine(nextTest.getOperation().getUri());
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
        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();
        }
Beispiel #17
0
        // No Serial
        public void NoSerial()
        {
            DeviceSetting dSetting3 = new DeviceSetting(testServer, null);

            Test NoSerial = new Test(dSetting3);

            NoSerial.setTestName("NoSerial");


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

            tests.Add(NoSerial);

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
        public void AsyncHTTPDeviceScan()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPAsync);
            results = new StreamWriter(stream);

            DeviceScanJSON testJson = new DeviceScanJSON();
            testJson.i = TestGlobals.validSerial;
            testJson.d = "1289472198573";
            testJson.b = null;
            testJson.s = 4;
            DeviceScan testDScan = new DeviceScan(TestGlobals.testServer, testJson);

            Test scanTest = new Test(testDScan);
            scanTest.setTestName("ValidSingleScanSimple");
            scanTest.setExpectedResult ("201");
            scanTest.setType ("performance");

            List<Test> tests = new List<Test>();
            tests.Add(scanTest);

            // 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(scanTest, 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();
        }
Beispiel #19
0
        public void MissingSerial()
        {
            ICmd missingICmd = new ICmd(TestGlobals.testServer, null);
            Test icmdTest = new Test(missingICmd);
            icmdTest.setTestName("EmptySerial");
            icmdTest.setExpectedResult ("400");

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

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

            results.WriteLine ("Server: " + TestGlobals.testServer);
            results.WriteLine ("Expected result: " + icmdTest.getActualResult());
            results.WriteLine ("Actual result: " + statusCode);
            results.WriteLine ("Test result: " + icmdTest.result ());
            results.WriteLine ();

            Assert.AreEqual("400", statusCode);
        }
Beispiel #20
0
        public void ValidSerial()
        {
            //Valid
            ICmd validICmd = new ICmd(testServer, validSerial);

            Test validTest = new Test(validICmd);

            validTest.setTestName("ValidSerial");


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

            tests.Add(validTest);

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

            foreach (Test nextTest in Program.getTests())
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
Beispiel #21
0
        public void MissingSerial()
        {
            //Missing
            ICmd missingICmd = new ICmd(testServer, null);
            Test missingTest = new Test(missingICmd);

            missingTest.setTestName("EmptySerial");


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

            tests.Add(missingTest);

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

            foreach (Test nextTest in Program.getTests())
            {
                Console.WriteLine(nextTest.getOperation().getUri());
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
        public void NoSerial()
        {
            DeviceSetting dSetting3 = new DeviceSetting(TestGlobals.testServer, null);

            Test deviceSetting = new Test(dSetting3);
            deviceSetting.setTestName("NoSerial");
            deviceSetting.setExpectedResult ("400");

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

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

            results.WriteLine ("Server: " + TestGlobals.testServer);
            results.WriteLine ("Expected result: " + deviceSetting.getActualResult());
            results.WriteLine ("Actual result: " + statusCode);
            results.WriteLine ("Test result: " + deviceSetting.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;

            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 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 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 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();
        }
        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 multiClientScans()
        {
            FileStream stream;
            stream = File.Create(outputFileMultiClientScans);
            results = new StreamWriter(stream);

            DeviceScanJSON testJson1 = new DeviceScanJSON();
            testJson1.i = TestGlobals.validSerial;
            testJson1.d = "1289472198573";
            testJson1.b = null;
            testJson1.s = 4;
            DeviceScan Scan1 = new DeviceScan(TestGlobals.testServer, testJson1);

            Test scanTest1 = new Test(Scan1);
            scanTest1.setTestName("ValidSingleScanSimple");
            scanTest1.setExpectedResult ("201");
            scanTest1.setType ("performance");

            DeviceScanJSON testJson2 = new DeviceScanJSON();
            testJson2.i = TestGlobals.validSerial;
            testJson2.d = "1289472198573";
            testJson2.b = null;
            testJson2.s = 4;
            DeviceScan Scan2 = new DeviceScan(TestGlobals.testServer, testJson2);

            Test scanTest2 = new Test(Scan2);
            scanTest2.setTestName("ValidSingleScanSimple");
            scanTest2.setExpectedResult ("201");
            scanTest2.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(scanTest1, HTTPOperation.POST);
                tasks[i, 1] = new HTTPCalls().runTest(scanTest2, 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();
        }
        public void SyncHTTPSICmd()
        {
            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();
                ICmd validICmd = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
                Test validTest = new Test(validICmd);
                validTest.setTestName("ValidSerial");
                validTest.setExpectedResult ("200");
                validTest.setType ("performance");
                List<Test> tests = new List<Test>();
                tests.Add(validTest);

                timer.Start();
                AsyncContext.Run(async () => await new HTTPSCalls().runTest(validTest, HTTPOperation.GET));
                timer.Stop();
                double time = timer.Elapsed.TotalMilliseconds;
                results.WriteLine("Test Time," + time);
                //Verify Server didn't throw up
            }
            results.Close();
        }
        public void MultiClientStatus()
        {
            FileStream stream;
            stream = File.Create(outputFileMultiClientStatus);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

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

            // 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[] statusPosted1 = new JObject[TestGlobals.maxReps];
            JObject[] statusPosted2 = new JObject[TestGlobals.maxReps];

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

                // client 1
                status.seqNum = i.ToString();
                DeviceStatus operation1 = new DeviceStatus(TestGlobals.testServer, status);

                Test statusTest1 = new Test(operation1);
                statusTest1.setTestName("ValidSerial");
                statusTest1.setExpectedResult ("201");
                statusTest1.setType ("performance");

                tasks[i, 0] = new HTTPCalls().runTest(statusTest1, HTTPOperation.POST);
                testStarted1[i] = HTTPCalls.started;
                JObject Json1 = JObject.FromObject(status);
                statusPosted1[i] = Json1;

                // client 2
                status.seqNum = i.ToString();
                DeviceStatus operation2 = new DeviceStatus(TestGlobals.testServer, status);

                Test statusTest2 = new Test(operation2);
                statusTest2.setTestName("ValidSerial");
                statusTest2.setExpectedResult ("201");
                statusTest2.setType ("performance");

                tasks[i, 1] = new HTTPCalls().runTest(statusTest2, HTTPOperation.POST);
                testStarted2[i] = HTTPCalls.started;
                JObject Json2 = JObject.FromObject(status);
                statusPosted2[i] = Json2;

                Console.WriteLine("Test starting:" + i.ToString());
                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 (statusPosted1 [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 (statusPosted2 [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: MultiClientDeviceStatus");
            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 SyncHTTPSDeviceStatus()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPSSync);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: SyncHTTPSDeviceStatus");
            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();

                status.seqNum = i.ToString();

                DeviceStatus operation = new DeviceStatus(TestGlobals.testServer, status);

                Test statusTest = new Test(operation);
                statusTest.setTestName("ValidSerial");
                statusTest.setExpectedResult ("201");
                statusTest.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(statusTest, HTTPOperation.POST));
                timer.Stop();

                JObject posted = JObject.FromObject (status);
                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: SyncHTTPSDeviceStatus");
            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 AsyncHTTPICmd()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPAsync);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: AsyncHTTPICmd");
            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);

            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

            ICmd validICmd = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
            Test validTest = new Test(validICmd);
            validTest.setTestName("ValidSerial");
            validTest.setExpectedResult ("200");
            validTest.setType ("performance");
            List<Test> tests = new List<Test>();
            tests.Add(validTest);

            // Construct started tasks
            Task<double>[] tasks = new Task<double>[TestGlobals.maxReps];
            DateTime[] testStarted = new DateTime [TestGlobals.maxReps];
            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Threading.Thread.Sleep(TestGlobals.delay);
                tasks[i] = new HTTPCalls().runTest(validTest, HTTPOperation.GET);
                testStarted [i] = HTTPCalls.started;
                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 ("Test Lasted: " + nextResult.Result + "ms");
                seq++;
                if (seq < 99)
                {
                    log.WriteLine ();
                }

            }

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

            log.WriteLine ("Test Ended: AsyncHTTPICmd");
            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 SyncHTTPSICmd()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPSSync);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: SyncHTTPSICmd");
            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();
                ICmd validICmd = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
                Test validTest = new Test(validICmd);
                validTest.setTestName("ValidSerial");
                validTest.setExpectedResult ("200");
                validTest.setType ("performance");
                List<Test> tests = new List<Test>();
                tests.Add(validTest);

                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(validTest, HTTPOperation.GET));
                timer.Stop();
                double time = timer.Elapsed.TotalMilliseconds;
                results.WriteLine("Test Time," + time);
                log.WriteLine ("Test Lasted: " + time + "ms");

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

                //Verify Server didn't throw up
            }

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

            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 MultiClientICmd()
        {
            FileStream stream;
            stream = File.Create(outputFileMultiClientICmd);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

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

            ICmd validICmd1 = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
            Test validTest1 = new Test(validICmd1);
            validTest1.setTestName("ValidSerial");
            validTest1.setExpectedResult ("200");
            validTest1.setType ("performance");

            ICmd validICmd2 = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
            Test validTest2 = new Test(validICmd2);
            validTest2.setTestName("ValidSerial");
            validTest2.setExpectedResult ("200");
            validTest2.setType ("performance");

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

            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Threading.Thread.Sleep(TestGlobals.delay);
                // client 1
                tasks[i, 0] = new HTTPCalls().runTest(validTest1, HTTPOperation.GET);
                testStarted1[i] = HTTPCalls.started;

                // client 2
                tasks[i, 1] = new HTTPCalls().runTest(validTest2, HTTPOperation.GET);
                testStarted2[i] = HTTPCalls.started;
                Console.WriteLine("Test starting:" + i.ToString());
                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 ("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 ("Test Lasted: " + tasks[i, 1].Result + "ms");
                if (i < 99)
                {
                    log.WriteLine ();
                }
            }

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

            log.WriteLine ("Test Ended: MultiClientICmd");
            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 AsyncHTTPDeviceScan()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPAsync);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: AsyncHTTPDeviceScan");
            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);

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

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

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

                DeviceScanJSON testJson = new DeviceScanJSON();
                testJson.i = TestGlobals.validSerial;
                testJson.d = "1289472198573";
                testJson.b = null;
                testJson.s = i;
                DeviceScan testDScan = new DeviceScan(TestGlobals.testServer, testJson);

                Test scanTest = new Test(testDScan);
                scanTest.setTestName("ValidSingleScanSimple");
                scanTest.setExpectedResult ("201");
                scanTest.setType ("performance");

                List<Test> tests = new List<Test>();
                tests.Add(scanTest);

                tasks[i] = new HTTPCalls().runTest(scanTest, HTTPOperation.POST);
                testStarted [i] = HTTPCalls.started;
                JObject Json = JObject.FromObject(testJson);
                scanPosted[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 (scanPosted[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: AsyncHTTPDeviceScan");
            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 SyncHTTPSDeviceScan()
        {
            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();
                DeviceScanJSON testJson = new DeviceScanJSON();
                testJson.i = TestGlobals.validSerial;
                testJson.d = "1289472198573";
                testJson.b = null;
                testJson.s = 4;
                DeviceScan testDScan = new DeviceScan(TestGlobals.testServer, testJson);

                Test scanTest = new Test(testDScan);
                scanTest.setTestName("ValidSingleScanSimple");
                scanTest.setExpectedResult ("201");
                scanTest.setType ("performance");

                timer.Start();
                AsyncContext.Run(async () => await new HTTPSCalls().runTest(scanTest, 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 SyncHTTPDeviceBackup()
        {
            FileStream stream;
            stream = File.Create(outputFileHTTPSync);
            results = new StreamWriter(stream);

            DateTime started = DateTime.Now;

            log.WriteLine ("Test Started: SyncHTTPDeviceBackup");
            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 HTTPCalls().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: SyncHTTPDeviceBackup");
            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 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();
        }
        //TODO: Identify invalid scan
        /*
        [Test()]
        // Mixed of Valid/Invalid Scans
        public void ValInvalScansDyn()
        {
            DeviceScanJSON testJson = new DeviceScanJSON ();
            testJson.i = validSerial;
            testJson.d = null;
            string[] scanData = new string[4];
            scanData [0] = "~20/0|";
            scanData [1] = "~20/noendingbar";
            scanData [2] = "~20/2|";
            scanData [3] = "~20/3|";
            testJson.b = scanData;
            testJson.s = 4;
            DeviceScan testDScan = new DeviceScan (testServer, testJson);

            Test scanTest = new Test (testDScan);
            scanTest.setTestName("ValInvalScansDyn");

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

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

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

            Assert.AreEqual("201", statusCode);

        }

        */
        // Combined
        //[Test()]
        // List of Valid Simple and Dynamic Code Scans
        public void ValidScansSimDyn()
        {
            DeviceScanJSON testJson = new DeviceScanJSON ();
            testJson.i = TestGlobals.validSerial;
            testJson.d = null;
            string[] scanData = new string[4];
            scanData [0] = "~20/0|";
            scanData [1] = "123456789";
            scanData [2] = "~20/2|";
            scanData [3] = "987654321";
            testJson.b = scanData;
            testJson.s = 4;
            DeviceScan testDScan = new DeviceScan (TestGlobals.testServer, testJson);

            Test scanTest = new Test (testDScan);
            scanTest.setTestName("ValidScansSimDyn");
            scanTest.setExpectedResult ("201");

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

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

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

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

            ICmd validICmd1 = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
            Test validTest1 = new Test(validICmd1);
            validTest1.setTestName("ValidSerial");
            validTest1.setExpectedResult ("200");
            validTest1.setType ("performance");

            ICmd validICmd2 = new ICmd(TestGlobals.testServer, TestGlobals.validSerial);
            Test validTest2 = new Test(validICmd2);
            validTest2.setTestName("ValidSerial");
            validTest2.setExpectedResult ("200");
            validTest2.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(validTest1, HTTPOperation.GET);
                tasks[i, 1] = new HTTPCalls().runTest(validTest2, HTTPOperation.GET);
                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();
        }
        //[Test()]
        public void NullSerial()
        {
            DeviceStatusJSON status = new DeviceStatusJSON();
            status.bkupURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceBackup";
            status.callHomeTimeoutData = null;
            status.callHomeTimeoutMode = "0";
            status.capture = "1";
            status.captureMode = "1";
            status.cmdChkInt = "1";
            status.cmdURL = "http://cozumotesttls.cloudapp.net:80/api/iCmd";
            string[] err = new string[3];
            err[0] = "asdf";
            err[1] = "wasd";
            err[2] = "qwerty";
            status.errorLog = err;
            status.reportURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceStatus";
            status.requestTimeoutValue = "8000";
            status.revId = "52987";
            status.scanURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceScan";
            status.seqNum = "87";
            status.startURL = "http://cozumotesttls.cloudapp.net:80/api/DeviceSetting";

            DeviceStatus operation = new DeviceStatus(TestGlobals.testServer, status);
            Test statusTest = new Test(operation);
            statusTest.setTestName("NullSerial");
            statusTest.setExpectedResult ("400");

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

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

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

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

            for (int i = 0; i < TestGlobals.maxReps; i++)
            {
                System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

                DeviceStatus operation = new DeviceStatus(TestGlobals.testServer, status);

                Test statusTest = new Test(operation);
                statusTest.setTestName("ValidSerial");
                statusTest.setExpectedResult ("201");
                statusTest.setType ("performance");

                timer.Start();
                AsyncContext.Run(async () => await new HTTPCalls().runTest(statusTest, 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 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();
        }