Esempio n. 1
0
        //[TestMethod]
        public async Task ICmdTest()
        {
            //Valid
            ICmd validICmd = new ICmd(testServer, ValidSerialNumbers.getAll()[0]);
            //Invalid
            ICmd invalidICmd = new ICmd(testServer, "No beef like dead beef");
            //Missing
            ICmd missingICmd = new ICmd(testServer, null);

            Test validTest   = new Test(validICmd);
            Test invalidTest = new Test(invalidICmd);
            Test missingTest = new Test(missingICmd);

            /*
             * DeviceScanJSON testJson = new DeviceScanJSON ();
             * testJson.i = ValidSerialNumbers.getAll()[1];
             * testJson.d = "ayyy lmao";
             * testJson.s = 4;
             * DeviceScan testDScan = new DeviceScan(testServer, testJson);
             * Test ayyyTest = new Test(testDScan);
             */

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

            tests.Add(validTest);
            tests.Add(invalidTest);
            tests.Add(missingTest);

            await Program.buildTests(tests);

            foreach (Test nextTest in Program.tests)
            {
                Assert.AreEqual(nextTest.getExpectedResult(), nextTest.getActualResult());
            }
        }
        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();
        }
Esempio n. 3
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());
            }
        }
Esempio n. 4
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());
            }
        }
Esempio n. 5
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());
            }
        }
Esempio n. 6
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);
        }
        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 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();
        }
        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();
        }