public void AddGroupAPI() { using (var client = new HttpClient()) { string accesstoken = ""; client.BaseAddress = new Uri(this.Host); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); using (HttpContent hc = new StringContent("{ UserName: \"inTren\", Password: \"hello\"}")) { hc.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (HttpResponseMessage response = client.PostAsync("api/member/signin", hc).Result) { string message = response.Content.ReadAsStringAsync().Result; OrgCommunication.Models.Member.ProfileResultModel result = Newtonsoft.Json.JsonConvert.DeserializeObject <OrgCommunication.Models.Member.ProfileResultModel>(message); accesstoken = result.Member.AccessToken; } } ////client.DefaultRequestHeaders.Accept.Clear(); ////client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //string FirstName = "Pichit"; using (var mdc = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture))) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accesstoken); //mdc.Headers.ContentType = new MediaTypeHeaderValue("application/json"); string title = "CS15"; string filepath = "D:\\me.jpg"; byte[] file = File.ReadAllBytes(filepath); mdc.Add(new StreamContent(new MemoryStream(file)), "Logo", "me.jpg"); mdc.Add(new StringContent("15"), "MemberId"); mdc.Add(new StringContent(title), "Title"); mdc.Add(new StringContent("Com-Sci"), "SubTitle"); using (HttpResponseMessage response = client.PostAsync("api/group/addgroup", mdc).Result) { string message = response.Content.ReadAsStringAsync().Result; OrgCommunication.Models.Group.GroupResultModel result = Newtonsoft.Json.JsonConvert.DeserializeObject <OrgCommunication.Models.Group.GroupResultModel>(message); Assert.AreEqual(title, result.Group.Title); } } } }
public void RegisterAPI() { using (var client = new HttpClient()) { client.BaseAddress = new Uri(this.Host); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string FirstName = "Pichit"; using (var mdc = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture))) { //mdc.Headers.ContentType = new MediaTypeHeaderValue("application/json"); string filepath = "D:\\me.jpg"; byte[] file = File.ReadAllBytes(filepath); mdc.Add(new StreamContent(new MemoryStream(file)), "Photo", "me.jpg"); mdc.Add(new StringContent("inTren"), "LoginId"); mdc.Add(new StringContent("hello"), "Password"); mdc.Add(new StringContent("*****@*****.**"), "Email"); mdc.Add(new StringContent(FirstName), "FirstName"); mdc.Add(new StringContent("Kongchoke"), "LastName"); mdc.Add(new StringContent("Tern"), "NickName"); mdc.Add(new StringContent("M"), "Gender"); mdc.Add(new StringContent("71.2"), "Weight"); //mdc.Add(new StringContent("172"), "Height"); mdc.Add(new StringContent("15/413"), "Address"); mdc.Add(new StringContent("Bangkapi"), "City"); mdc.Add(new StringContent("10240"), "ZipCode"); mdc.Add(new StringContent("TH"), "CountryCode"); mdc.Add(new StringContent("0809671230"), "Phone"); using (HttpResponseMessage response = client.PostAsync("api/member/register", mdc).Result) { string message = response.Content.ReadAsStringAsync().Result; OrgCommunication.Models.Member.ProfileResultModel result = Newtonsoft.Json.JsonConvert.DeserializeObject <OrgCommunication.Models.Member.ProfileResultModel>(message); Assert.AreEqual(FirstName, result.Member.FirstName); } } } }