static async Task callType(Test currentTest, HTTPOperation op) { switch (op) { case HTTPOperation.GET: result = await RunGetAsync (currentTest.getOperation ().getUri ()); currentTest.setActualResult (result.Key.GetValue ("StatusCode").ToString ()); break; case HTTPOperation.POST: result = await RunPostAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); break; case HTTPOperation.PUT: result = await RunPutAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); break; case HTTPOperation.DELETE: result = await RunDeleteAsync(currentTest.getOperation().getUri()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); break; default: Console.WriteLine("Unrecognized HTTP Operation!"); Console.WriteLine(currentTest.ToString()); break; } }
//Do test, output results to file. public static async Task runTest(Test currentTest) { //Get start time int startTime = seconds; Console.WriteLine("Test starting"); //Do tests await testType(currentTest); Console.WriteLine("Test ending"); //Get end time int endTime = seconds; int timeDelta = endTime - startTime; if (results != null) { //Output results //Test results.WriteLine("Summary:"); results.WriteLine("Current test: " + currentTest.ToString() + " " + currentTest.getTestName()); //clm(); try { results.WriteLine("Input JSON:"); results.WriteLine(currentTest.getOperation().getJson().ToString()); } catch (Exception) { results.WriteLine("No JSON attached to this operation"); } results.WriteLine("Input URI: " + currentTest.getOperation().getUri()); //Expected value results.WriteLine("Expected result: " + currentTest.getExpectedResult()); //clm(); //Actual value results.WriteLine("Actual result: " + currentTest.getActualResult()); //clm(); //Time elapsed (in seconds) results.WriteLine("Time elapsed: " + timeDelta + "s"); //clm(); //Pass/Fail results.WriteLine("Test result: " + currentTest.result()); results.WriteLine(); } }
//[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); }
//TODOIF: Tweak console output to be a little clearer. Console is made redundant by logs, but it could be useful. static async Task testType(Test currentTest) { KeyValuePair <JObject, string> result; results.WriteLine("Raw test results:"); switch (currentTest.ToString()) { case "iCmd": result = await RunGetAsync(currentTest.getOperation().getUri()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); Console.WriteLine(result.Value + " Is the result of the iCmd test"); results.WriteLine(result.ToString()); break; case "DeviceScan": result = await RunPostAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); Console.WriteLine(result.Value + "Is the result of the DeviceScan test"); results.WriteLine(result.ToString()); break; case "DeviceSetting": result = await RunGetAsync(currentTest.getOperation().getUri()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); Console.WriteLine(result.Value + " Is the result of the DeviceSetting test"); results.WriteLine(result.ToString()); break; case "DeviceBackup": result = await RunPostAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); Console.WriteLine(result.Value + "Is the result of the DeviceBackup test"); results.WriteLine(result.ToString()); break; case "DeviceStatus": result = await RunPostAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result.Key.GetValue("StatusCode").ToString()); Console.WriteLine(result.Value + "Is the result of the DeviceStatus test"); results.WriteLine(result.ToString()); break; default: Console.WriteLine("Unrecognized test type!"); Console.WriteLine(currentTest.ToString()); break; } }
//TODO: Set up the different test types. static async Task testType(Test currentTest) { string result; switch (currentTest.ToString()) { case "iCmd": result = await RunGetAsync(currentTest.getOperation().getUri()); currentTest.setActualResult(result); Console.WriteLine(result + " Is the result of the iCmd test"); break; case "DeviceScan": result = await RunPostAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result); Console.WriteLine(result + "Is the result of the DeviceScan test"); break; case "DeviceSetting": result = await RunGetAsync(currentTest.getOperation().getUri()); currentTest.setActualResult(result); Console.WriteLine(result + " Is the result of the DeviceSetting test"); break; case "DeviceBackup": result = await RunPostAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result); Console.WriteLine(result + "Is the result of the DeviceBackup test"); break; case "DeviceStatus": result = await RunPostAsync(currentTest.getOperation().getUri(), currentTest.getOperation().getJson()); currentTest.setActualResult(result); Console.WriteLine(result + "Is the result of the DeviceStatus test"); break; default: Console.WriteLine("Unrecognized test type!"); Console.WriteLine(currentTest.ToString()); break; } }
//[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); }
//[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); }
//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); }