//[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 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(); }
public static Test getScan(UpcCode item, int s) { if (item == UpcCode.Laptop13Inch) { DeviceScanJSON scan1 = new DeviceScanJSON (); scan1.i = TestGlobals.demoSerial; scan1.d = "416000383720"; scan1.b = null; scan1.s = s; DeviceScan testDScan1 = new DeviceScan (TestGlobals.demoServer, scan1); Test scanTest1 = new Test (testDScan1); return scanTest1; } else if (item == UpcCode.Laptop11Inch) { DeviceScanJSON scan2 = new DeviceScanJSON (); scan2.i = TestGlobals.demoSerial; scan2.d = "416000336108"; scan2.b = null; scan2.s = s; DeviceScan testDScan2 = new DeviceScan (TestGlobals.demoServer, scan2); Test scanTest2 = new Test (testDScan2); return scanTest2; } else if (item == UpcCode.Printer) { DeviceScanJSON scan3 = new DeviceScanJSON (); scan3.i = TestGlobals.demoSerial; scan3.d = "416000837315"; scan3.b = null; scan3.s = s; DeviceScan testDScan3 = new DeviceScan (TestGlobals.demoServer, scan3); Test scanTest3 = new Test (testDScan3); return scanTest3; } else if (item == UpcCode.Warranty) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837223"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.ExternalHDD) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837360"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.Keyboard) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000338973"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.Speakers) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837988"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.Mouse) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000336894"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.LaptopCase13Inch) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837261"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.Headset) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837018"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.LaptopCase11Inch) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000338799"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.Earbuds) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837049"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.HdmiCable) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837339"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else if (item == UpcCode.UsbCable) { DeviceScanJSON scan4 = new DeviceScanJSON (); scan4.i = TestGlobals.demoSerial; scan4.d = "416000837827"; scan4.b = null; scan4.s = s; DeviceScan testDScan4 = new DeviceScan (TestGlobals.demoServer, scan4); Test scanTest4 = new Test (testDScan4); return scanTest4; } else { return null; } }
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); DateTime started = DateTime.Now; log.WriteLine ("Test Started: SyncHTTPSDeviceScan"); 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(); 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"); 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(scanTest, HTTPOperation.POST)); timer.Stop(); JObject posted = JObject.FromObject (testJson); 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: SyncHTTPSDeviceScan"); 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 MultiClientScans() { FileStream stream; stream = File.Create(outputFileMultiClientScans); results = new StreamWriter(stream); DateTime started = DateTime.Now; log.WriteLine ("Test Started: MultiClientDeviceScan"); 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[] scanPosted1 = new JObject[TestGlobals.maxReps]; JObject[] scanPosted2 = new JObject[TestGlobals.maxReps]; for (int i = 0; i < TestGlobals.maxReps; i++) { System.Threading.Thread.Sleep(TestGlobals.delay); // client 1 DeviceScanJSON testJson1 = new DeviceScanJSON(); testJson1.i = TestGlobals.validSerial; testJson1.d = "1289472198573"; testJson1.b = null; testJson1.s = i; DeviceScan Scan1 = new DeviceScan(TestGlobals.testServer, testJson1); Test scanTest1 = new Test(Scan1); scanTest1.setTestName("ValidSingleScanSimple"); scanTest1.setExpectedResult ("201"); scanTest1.setType ("performance"); tasks[i, 0] = new HTTPCalls().runTest(scanTest1, HTTPOperation.POST); testStarted1[i] = HTTPCalls.started; JObject Json1 = JObject.FromObject(testJson1); scanPosted1[i] = Json1; // client 2 DeviceScanJSON testJson2 = new DeviceScanJSON(); testJson2.i = TestGlobals.validSerial; testJson2.d = "1289472198573"; testJson2.b = null; testJson2.s = i; DeviceScan Scan2 = new DeviceScan(TestGlobals.testServer, testJson2); Test scanTest2 = new Test(Scan2); scanTest2.setTestName("ValidSingleScanSimple"); scanTest2.setExpectedResult ("201"); scanTest2.setType ("performance"); tasks[i, 1] = new HTTPCalls().runTest(scanTest2, HTTPOperation.POST); testStarted2[i] = HTTPCalls.started; JObject Json2 = JObject.FromObject(testJson2); scanPosted2[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 (scanPosted1 [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 (scanPosted2 [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: MultiClientDeviceScan"); 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 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 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(); }