public void Add() { var entityToAdd = new Student {Name = "Dipon"}; Student addedEntity = null; var client = new HttpClient(_server); HttpRequestMessage request = CreateRequest("api/student/create", "application/json", HttpMethod.Post, JsonConvert.SerializeObject(entityToAdd)); //important; new{Entity: entityToAdd} wasn't working as expected using (HttpResponseMessage response = client.SendAsync(request).Result) { addedEntity = JsonConvert.DeserializeObject<Student>(response.Content.ReadAsStringAsync().Result); } Assert.Less(0, addedEntity.Id); Assert.AreEqual(entityToAdd.Name, addedEntity.Name); //passed by json Assert.IsTrue(addedEntity.IsActive); }
public void Replace() { const int studentId = 5; var entity = new Student {Name = "Dipon", IsActive = false}; Student updatedEntity = null; var client = new HttpClient(_server); HttpRequestMessage request = CreateRequest(String.Format("api/student/update/{0}", studentId), "application/json", HttpMethod.Put, JsonConvert.SerializeObject(entity)); //important; new{Entity: entityToAdd} wasn't working as expected using (HttpResponseMessage response = client.SendAsync(request).Result) { updatedEntity = JsonConvert.DeserializeObject<Student>(response.Content.ReadAsStringAsync().Result); } Assert.AreEqual(studentId, updatedEntity.Id); //passed by url Assert.AreEqual(entity.Name, updatedEntity.Name); //passed by json Assert.AreEqual(entity.IsActive, updatedEntity.IsActive); //passed by json }