public void SenderCRU() { BrickStreetConnect brickst = makeClient(); HttpStatusCode status; String statusMessage; Sender s1 = new Sender(); s1.Name = "My Test Sender"; s1.EmailAddress = "mytestsender"; s1.DepartmentID = ConnectDepartmentID; s1.DefaultSender = false; Sender s2 = brickst.AddSender(s1, out status, out statusMessage); Assert.AreEqual(HttpStatusCode.OK, status); Assert.IsNotNull(s2); Assert.IsTrue(s2.Id.HasValue); Assert.AreEqual(s2.Name, s1.Name); Assert.AreEqual(s2.EmailAddress, s1.EmailAddress); Assert.AreEqual(s2.DepartmentID, s1.DepartmentID); Assert.AreEqual(s2.DefaultSender, s1.DefaultSender); s2.EmailAddress = "testsender"; Sender s3 = brickst.UpdateSender(s2, out status, out statusMessage); Assert.AreEqual(HttpStatusCode.OK, status); Assert.IsNotNull(s3); Assert.IsTrue(s3.Id.HasValue); Assert.AreEqual(s3.Id.Value, s2.Id.Value); Assert.AreEqual(s3.Name, s2.Name); Assert.AreEqual(s3.EmailAddress, s2.EmailAddress); Assert.AreEqual(s3.DepartmentID, s2.DepartmentID); Assert.AreEqual(s3.DefaultSender, s2.DefaultSender); }
public Sender AddSender(Sender newSender, out HttpStatusCode status, out string statusMessage) { RestClient restClient = createClient(); RestRequest restRequest = new RestRequest { Resource = "data/sender", RequestFormat = DataFormat.Json, Method = Method.POST }; // we handle our own serialization instead of calling AddBody JsonSerializerSettings serSettings = new JsonSerializerSettings(); serSettings.DefaultValueHandling = DefaultValueHandling.Ignore; serSettings.NullValueHandling = NullValueHandling.Ignore; string serialized = JsonConvert.SerializeObject(newSender, serSettings); restRequest.AddParameter("application/json", serialized, ParameterType.RequestBody); IRestResponse restResponse = restClient.Execute(restRequest); status = restResponse.StatusCode; if (status != HttpStatusCode.OK) { statusMessage = restResponse.Content; return null; } else { statusMessage = null; } serialized = restResponse.Content; Sender obj = JsonConvert.DeserializeObject<Sender>(serialized); return obj; }