public static async Task <string> CreateContact() { var obj = new ContactModel(); foreach (var item in obj.GetType().GetProperties()) { dynamic value = null; if (item.PropertyType == typeof(DateTime)) { value = DateTime.Today; } else if (item.PropertyType == typeof(string)) { value = item.Name + "_test"; } else if (item.PropertyType == typeof(decimal)) { value = Convert.ToDecimal("134.00"); } else if (item.PropertyType == typeof(int) || item.PropertyType == typeof(Nullable <int>)) { value = 1; } else if (item.PropertyType == typeof(bool)) { value = true; } item.SetValue(obj, value); } // Serialize our concrete class into a JSON String var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(obj)); // Wrap our JSON inside a StringContent which then can be used by the HttpClient class var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("api/Contact/CreateContact", httpContent); var result = await response.Content.ReadAsStringAsync(); return(result); }
public void SetUp() { theModel = new ContactModel(); theType = theModel.GetType(); r1 = MockRepository.GenerateStub<IValidationRule>(); r2 = MockRepository.GenerateStub<IValidationRule>(); r3 = MockRepository.GenerateStub<IValidationRule>(); theMatchingSource = ConfiguredValidationSource.For(type => type == theType, r1, r2); theOtherSource = ConfiguredValidationSource.For(type => type == typeof(int), r3); theGraph = ValidationGraph.BasicGraph(); theGraph.RegisterSource(theMatchingSource); theGraph.RegisterSource(theOtherSource); theContext = ValidationContext.For(theModel); thePlan = ValidationPlan.For(theType, theGraph); }