コード例 #1
0
        public void TestPostContact()
        {
            ContactObject       Contact;
            HttpResponseMessage Response;

            ContactObject NewContact = new ContactObject();

            NewContact.first_name   = "Dejana";
            NewContact.last_name    = "Dejanovic";
            NewContact.email        = "*****@*****.**";
            NewContact.phone_number = "012/345-678";

            API.PostContact(NewContact, out Contact, out Response);

            Assert.AreEqual(HttpStatusCode.Created, Response.StatusCode);

            ContactObject VerifyContact;

            API.GetContact(Contact.id, out VerifyContact, out Response);

            Assert.AreEqual(HttpStatusCode.OK, Response.StatusCode);
            Assert.AreEqual(VerifyContact.first_name, NewContact.first_name);
            Assert.AreEqual(VerifyContact.last_name, NewContact.last_name);
            Assert.AreEqual(VerifyContact.email, NewContact.email);
            Assert.AreEqual(VerifyContact.phone_number, NewContact.phone_number);
        }
コード例 #2
0
ファイル: ContactsAPI.cs プロジェクト: Toni102/API
 public void GetContact(int Id, out ContactObject Contact, out HttpResponseMessage Response)
 {
     Response = Client.GetAsync("contact/" + Id.ToString()).Result;
     if (Response.IsSuccessStatusCode)
     {
         Contact = Response.Content.ReadAsAsync <ContactObject>().Result;
     }
     else
     {
         Contact = new ContactObject();
     }
 }
コード例 #3
0
        public void TestCreateUpdateDeleteUser()
        {
            ContactObject       Contact;
            ContactObject       VerifyContact;
            ContactObject       UpdateContact = new ContactObject();
            ContactObject       NewContact    = new ContactObject();
            HttpResponseMessage Response;

            NewContact.first_name   = "Bob";
            NewContact.last_name    = "Buttons";
            NewContact.email        = "*****@*****.**";
            NewContact.phone_number = "1-800-555-12345";

            API.PostContact(NewContact, out Contact, out Response);
            Assert.AreEqual(HttpStatusCode.Created, Response.StatusCode);
            TestContext.WriteLine("Created user with id: {0}", Contact.id);

            API.GetContact(Contact.id, out VerifyContact, out Response);
            Assert.AreEqual(HttpStatusCode.OK, Response.StatusCode);
            Assert.AreEqual(VerifyContact.first_name, NewContact.first_name);
            Assert.AreEqual(VerifyContact.last_name, NewContact.last_name);
            Assert.AreEqual(VerifyContact.email, NewContact.email);
            Assert.AreEqual(VerifyContact.phone_number, NewContact.phone_number);

            UpdateContact = VerifyContact;
            UpdateContact.phone_number = "1-800-555-6666";

            API.PutContact(UpdateContact.id, UpdateContact, out Response);
            Assert.AreEqual(HttpStatusCode.OK, Response.StatusCode);
            TestContext.WriteLine("Updated user {0} information", UpdateContact.id);

            API.GetContact(UpdateContact.id, out VerifyContact, out Response);
            Assert.AreEqual(HttpStatusCode.OK, Response.StatusCode);
            Assert.AreEqual(VerifyContact.first_name, UpdateContact.first_name);
            Assert.AreEqual(VerifyContact.last_name, UpdateContact.last_name);
            Assert.AreEqual(VerifyContact.email, UpdateContact.email);
            Assert.AreEqual(VerifyContact.phone_number, UpdateContact.phone_number);
            TestContext.WriteLine("Verified user {0} information update", UpdateContact.id);

            Thread.Sleep(1000);

            API.DeleteContact(UpdateContact.id, out Response);
            Assert.AreEqual(HttpStatusCode.NoContent, Response.StatusCode);

            API.GetContact(UpdateContact.id, out Contact, out Response);
            TestContext.Write("Deleting user with id: {0} ... ", UpdateContact.id);
            Assert.AreEqual(HttpStatusCode.NotFound, Response.StatusCode);
            TestContext.Write("Deleted");
        }
コード例 #4
0
ファイル: ContactsAPI.cs プロジェクト: Toni102/API
 public void PostContact(
     ContactObject NewContact,
     out ContactObject InsertedContact,
     out HttpResponseMessage Response
     )
 {
     Response = Client.PostAsJsonAsync <ContactObject>("contact", NewContact).Result;
     if (Response.IsSuccessStatusCode)
     {
         InsertedContact = Response.Content.ReadAsAsync <ContactObject>().Result;
     }
     else
     {
         InsertedContact = new ContactObject();
     }
 }
コード例 #5
0
ファイル: ContactsAPI.cs プロジェクト: Toni102/API
 public void PutContact(int Id, ContactObject UpdatedContact, out HttpResponseMessage Response)
 {
     Response = Client.PutAsJsonAsync <ContactObject>("contact/" + Id.ToString(), UpdatedContact).Result;
 }