Ejemplo n.º 1
0
        public void givenContactDetail_updateInJsonServer_andDatabase()
        {
            AddressBookContactDetails contact = new AddressBookContactDetails();

            contact.firstName       = "Mahak";
            contact.lastName        = "Singla";
            contact.address         = "New Grain Market";
            contact.city            = "Barwala";
            contact.state           = "Haryana";
            contact.zip             = 125125;
            contact.phoneNo         = 7014245875;
            contact.eMail           = "*****@*****.**";
            contact.addressBookName = "A";

            //making a request for a particular employee to be updated
            RestRequest request = new RestRequest("AddressBook/4", Method.PUT);
            //creating a jobject for new data to be added in place of old
            //json represents a new json object
            JObject jObject = new JObject();

            jObject.Add("firstName", contact.firstName);
            jObject.Add("lastName", contact.lastName);
            jObject.Add("address", contact.address);
            jObject.Add("city", contact.city);
            jObject.Add("state", contact.state);
            jObject.Add("zip", contact.zip);
            jObject.Add("phoneNo", contact.phoneNo);
            jObject.Add("eMail", contact.eMail);
            jObject.Add("addressBookName", contact.addressBookName);
            //adding parameters in request
            //request body parameter type signifies values added using add.
            request.AddParameter("application/json", jObject, ParameterType.RequestBody);
            //executing request using client
            //IRest response act as a container for the data sent back from api.
            IRestResponse response = client.Execute(request);

            //checking status code of response
            Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
            //deserializing content added in json file
            AddressBookContactDetails dataResponse = JsonConvert.DeserializeObject <AddressBookContactDetails>(response.Content);

            //asserting for salary
            Assert.AreEqual(dataResponse.address, "New Grain Market");
            //writing content without deserializing from resopnse.
            Console.WriteLine(response.Content);

            //updating data in database using threading
            AddressBookOperations addressBookOperations = new AddressBookOperations();

            addressBookOperations.UpdateContactDetailsInDataBase(contact);
            //checking if details are updated
            AddressBookContactDetails expected = addressBookOperations.GettingUpdatedDetails(contact);

            Assert.AreEqual(contact, expected);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the contact details. UC17
        /// </summary>
        /// <returns></returns>
        public AddressBookContactDetails UpdateContactDetails()
        {
            //passing data for updating
            AddressBookContactDetails contactDetails = new AddressBookContactDetails();

            contactDetails.firstName       = "Vishal";
            contactDetails.lastName        = "Garg";
            contactDetails.address         = "Barwala";
            contactDetails.city            = "Hisar";
            contactDetails.state           = "Haryana";
            contactDetails.zip             = 125121;
            contactDetails.phoneNo         = 8570934858;
            contactDetails.eMail           = "vishal.garg";
            contactDetails.addressBookName = "A";
            //passing data to update method in address book operations
            AddressBookOperations addressBookOperations = new AddressBookOperations();
            bool result = addressBookOperations.UpdateContactDetailsInDataBase(contactDetails);

            Console.WriteLine(result);
            return(contactDetails);
        }