Example #1
0
        public void Insert_Strip()
        {
            var connection    = new ConnectToMySQL_Fetch_TestData();
            var testdataStrip = connection.Select(strtblname, strTestCaseNo, strTestType);

            var client = new RestClient(@ConfigurationManager.AppSettings["BaseURL"]);

            var request = new RestRequest("Strips/", Method.POST);

            request.AddHeader("Content-Type", @ConfigurationManager.AppSettings["Content-Type"]);
            request.AddHeader("X-ExternalRequest-ID", @ConfigurationManager.AppSettings["X-ExternalRequest-ID"]);
            request.AddHeader("X-ExternalSystem-ID", @ConfigurationManager.AppSettings["X-ExternalSystem-ID"]);
            request.AddHeader("X-Date", ConfigurationManager.AppSettings["X-Date"]);

            request.AddParameter("undefined", "<?xml version=\"1.0\"?>\r\n<Strip>\r\n  <AssetRegistration>" + testdataStrip[4] + "</AssetRegistration>\r\n  <AssetTypeID>" + testdataStrip[5] + "</AssetTypeID>\r\n  <Callsign>" + testdataStrip[6] + "</Callsign>\r\n  <LocationFromID>" + testdataStrip[7] + "</LocationFromID>\r\n  <LocationToID>" + testdataStrip[8] + "</LocationToID>\r\n  <PaneID>" + testdataStrip[9] + "</PaneID>\r\n  <People>\r\n    <StripPerson>\r\n      <PersonID>" + testdataStrip[10] + "</PersonID>\r\n      <SlotNumber>1</SlotNumber>\r\n    </StripPerson>\r\n    <StripPerson>\r\n      <PersonID>" + testdataStrip[11] + "</PersonID>\r\n      <SlotNumber>2</SlotNumber>\r\n    </StripPerson>\r\n  </People>\r\n  <PlannedEndTime>2019-07-23T03:15:00</PlannedEndTime>\r\n  <PlannedStartTime>2019-07-23T01:30:00</PlannedStartTime>\r\n  <Task>" + testdataStrip[12] + "</Task>\r\n  <Type>" + testdataStrip[13] + "</Type>\r\n</Strip>\r\n", ParameterType.RequestBody);


            var response = client.Execute(request);
            var content  = client.Execute(request).Content;

            Console.WriteLine("Content Length: " + content.Length);
            Console.WriteLine("Response Status: " + response.ResponseStatus);

            Console.WriteLine("Response Status Code: " + response.StatusCode);
            Console.WriteLine("Headers Count: " + response.Headers.Count);

            var doc = new XmlDocument();

            doc.LoadXml(response.Content);

            StripID = doc.GetElementsByTagName("ID")[2].InnerText;

            Console.WriteLine("StripID: " + StripID);

            Assert.IsNotNull(doc.GetElementsByTagName("ID")[2].InnerText);

            var connection1 = new ConnectToMySQL_Update_TestData();

            connection1.Update(strtblname, "StripID", StripID, "TC001");
        }
        public void TC05_UpdateWaypoint_waypoint()
        {
            PropertiesCollection.test = PropertiesCollection.extent.CreateTest("TC05_UpdateWaypoint");
            Object[] ObjDBResponse = new object[16];

            //Connecting to application database and retrieving the current count of documents attached to the strip
            string        strConnectionString = "Data Source=" + ConfigurationManager.AppSettings["SQLServerDataSource"] + ";Initial Catalog=" + ConfigurationManager.AppSettings["SQLServerInitialCatalog"] + ";Integrated Security=" + ConfigurationManager.AppSettings["SQLServerIntegratedSecurity"] + ';';
            SqlConnection myConnection        = new SqlConnection(strConnectionString);

            myConnection.Open();

            SqlDataReader reader = null;

            /****************** Retriving the count of Waypoint before Insert **************************************/
            String strQuerybefore = "select count(*) from dbo.tblWaypoint";

            SqlCommand commandbefore = new SqlCommand(strQuerybefore, myConnection);

            reader = commandbefore.ExecuteReader();

            while (reader.Read())
            {
                intWaypointCount = reader.GetInt32(0);
            }
            reader.Close();

            intWaypointCount = intWaypointCount - 1;
            Console.WriteLine("Count of Waypoints in Application Database: " + intWaypointCount);

            var client = new RestClient(ConfigurationManager.AppSettings["BaseURL"]);

            /**** PREREQUISITE *** Insert  Waypoint Operation and inserting the Waypoint ID into the Update Row *****/



            /****************** TestData Database call to retrieve the Insert details  ******************************/

            var connection = new ConnectToMySQL_Fetch_TestData();
            var testData   = connection.Select(strtblname, "TC001", strTestType);


            var InsertRequest = new RestRequest(ConfigurationManager.AppSettings["InsertWayPointEndResource"], Method.POST);

            InsertRequest.AddHeader("Content-Type", ConfigurationManager.AppSettings["Content-Type"]);
            InsertRequest.AddHeader("X-ExternalRequest-ID", ConfigurationManager.AppSettings["X-ExternalRequest-ID"]);
            InsertRequest.AddHeader("X-ExternalSystem-ID", ConfigurationManager.AppSettings["X-ExternalSystem-ID"]);
            InsertRequest.AddHeader("X-Date", ConfigurationManager.AppSettings["X-Date"]);
            InsertRequest.AddParameter("undefined", "<?xml version=\"1.0\"?>\r\n<Waypoint>\r\n  <Colour>" + testData[4] + "</Colour>\r\n  <DisplayCode>" + testData[5] + "</DisplayCode>\r\n  <Latitude>" + testData[6] + "</Latitude>\r\n  <Longitude>" + testData[7] + "</Longitude>\r\n  <Name>" + testData[8] + "</Name>\r\n  <ShortCode>" + testData[9] + "</ShortCode>\r\n  <TimeZoneKey>" + testData[10] + "</TimeZoneKey>\r\n  <UseDaylightSavings>" + testData[11] + "</UseDaylightSavings>\r\n</Waypoint>\r\n", ParameterType.RequestBody);

            IRestResponse response = client.Execute(InsertRequest);
            var           content  = client.Execute(InsertRequest).Content;

            var doc = new XmlDocument();

            doc.LoadXml(response.Content);

            String WaypointID = doc.GetElementsByTagName("WaypointID")[0].InnerText;

            Console.WriteLine("WaypointID: " + WaypointID);

            var updateconnection = new ConnectToMySQL_Update_TestData();

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC005");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC006");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC007");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC008");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC009");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC010");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC011");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC013");

            updateconnection.Update("automation_waypoint", "WaypointID", WaypointID, "TC014");


            /****************** Retriving the count of Waypoint before update **************************************/
            String strQuery = "select count(*) from dbo.tblWaypoint";

            SqlCommand command = new SqlCommand(strQuery, myConnection);

            reader = command.ExecuteReader();


            while (reader.Read())
            {
                intWaypointCount = reader.GetInt32(0);
            }
            reader.Close();

            intWaypointCount = intWaypointCount - 1;
            Console.WriteLine("Count of Waypoints in Application Database: " + intWaypointCount);

            /****************** TestData Database call to retrieve the Update Testcase details  ********************/

            var connectionupdate = new ConnectToMySQL_Fetch_TestData();
            var testDataupdate   = connection.Select(strtblname, "TC005", strTestType);



            /****************** UpdateStripDoc Waypoint Operation  *************************************************/


            var UpdateRequest = new RestRequest(ConfigurationManager.AppSettings["InsertWayPointEndResource"] + testDataupdate[12], Method.PUT);

            //Adding headers to the PUT request

            UpdateRequest.AddHeader("Content-Type", ConfigurationManager.AppSettings["Content-Type"]);
            UpdateRequest.AddHeader("X-ExternalRequest-ID", ConfigurationManager.AppSettings["X-ExternalRequest-ID"]);
            UpdateRequest.AddHeader("X-ExternalSystem-ID", ConfigurationManager.AppSettings["X-ExternalSystem-ID"]);
            UpdateRequest.AddHeader("X-Date", ConfigurationManager.AppSettings["X-Date"]);
            UpdateRequest.AddParameter("undefined", "<?xml version=\"1.0\"?>\r\n<Waypoint>\r\n  <Name>" + testDataupdate[8] + "</Name>\r\n  <ShortCode>" + testDataupdate[9] + "</ShortCode>\r\n  <TimeZoneKey>" + testDataupdate[10] + "</TimeZoneKey>\r\n</Waypoint>", ParameterType.RequestBody);

            IRestResponse Updateresponse = client.Execute(UpdateRequest);
            var           Updatecontent  = client.Execute(UpdateRequest).Content;

            Console.WriteLine("Content Length: " + content.Length);
            Console.WriteLine("Response Status: " + response.ResponseStatus);

            Console.WriteLine("Status Code: " + response.StatusCode);
            Console.WriteLine("Header Count: " + response.Headers.Count);

            var docUpdate = new XmlDocument();

            docUpdate.LoadXml(Updateresponse.Content);

            /******************************************************************************************************/

            /****************** Retriving the count of Waypoint after update **************************************/
            String strQueryafter = "select count(*) from dbo.tblWaypoint";

            SqlCommand commandafter = new SqlCommand(strQueryafter, myConnection);

            reader = commandafter.ExecuteReader();


            while (reader.Read())
            {
                intWaypointCount = reader.GetInt32(0);
            }
            reader.Close();

            intWaypointCount = intWaypointCount - 1;
            Console.WriteLine("Count of Waypoints in Application Database: " + intWaypointCount);
            /****************** Retriving the count of Waypoint after update **************************************/

            int intRespCode = Get_StatusCode(response);

            try
            {
                Console.WriteLine("intResponse: " + intRespCode);
                Assert.AreEqual(intRespCode, 200);
                PropertiesCollection.test.Log(Status.Pass, "Status Response is 200 OK");
            }
            catch
            {
                PropertiesCollection.test.Log(Status.Fail, "Status Response is not 200 OK");
            }

            strQuery = "select * from dbo.tblwaypoint where WaypointName = '" + testData[8] + "' and WaypointShortCode= '" + testData[9] + "'";
            command  = new SqlCommand(strQuery, myConnection);
            reader   = command.ExecuteReader();

            while (reader.Read())
            {
                ObjDBResponse[0] = reader[0].ToString();  //WayPointID
                ObjDBResponse[1] = reader[1].ToString();  //WayPointColour
                ObjDBResponse[2] = reader[3].ToString();  //WayPointName
                ObjDBResponse[3] = reader[4].ToString();  //WaypointShortCode
                ObjDBResponse[4] = reader[7].ToString();  //TimeZoneKey
                ObjDBResponse[5] = reader[10].ToString(); //LocationLatitude
                ObjDBResponse[6] = reader[11].ToString(); //LocationLongitude
                ObjDBResponse[7] = reader[13].ToString(); //WayPointDisplayCode
                ObjDBResponse[8] = reader[15].ToString(); //LoginName
            }

            try
            {
                Assert.AreEqual(doc.GetElementsByTagName("Colour")[0].InnerText, testData[4]);
                PropertiesCollection.test.Log(Status.Pass, "Validation for Colour is passed and Waypoint Colour is " + ObjDBResponse[1]);
            }
            catch
            {
                PropertiesCollection.test.Log(Status.Fail, "Validation for Colour is not passed");
            }
            try
            {
                Assert.AreEqual(doc.GetElementsByTagName("DisplayCode")[0].InnerText, testData[5]);
                PropertiesCollection.test.Log(Status.Pass, "Validation for DisplayCode is passed and is " + ObjDBResponse[7]);
            }
            catch
            {
                PropertiesCollection.test.Log(Status.Fail, "Validation for DisplayCode is not passed");
            }
            try
            {
                Assert.AreEqual(ObjDBResponse[8], "AFMIS");
                PropertiesCollection.test.Log(Status.Pass, "Validation for Login name is passed and is " + ObjDBResponse[8]);
            }
            catch
            {
                PropertiesCollection.test.Log(Status.Fail, "Validation for Login name is not passed. Expected is AFMIS. Actual is: " + ObjDBResponse[8]);
            }
        }