public void PutAccount() { Database.SetInitializer(new ManahostManagerInitializer()); using (ManahostManagerDAL prectx = new ManahostManagerDAL()) { prectx.Database.Delete(); } var PutClientModel = new PutAccountModel() { Civility = "Mlle", Country = "UnderCity", FirstName = "Sylvanas", LastName = "Coursevent" }; using (var server = TestServer.Create<WebApiApplication>()) { HttpResponseMessage response = server.CreateRequest("/token").And((x) => x.Content = new StringContent(string.Format("grant_type=password&username={0}&password={1}&client_id=UNITTEST&client_secret=BLAHBLAHCAR", ControllerUtils.username, ControllerUtils.password), Encoding.UTF8, "application/x-www-form-urlencoded")).PostAsync().Result; TokenAuth token = response.Content.ReadAsAsync<TokenAuth>().Result; Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, "Status Authentification"); response = server.CreateRequest("/Api/Account").And(x => { x.Content = new ObjectContent(typeof(PutAccountModel), PutClientModel, new JilFormatter()); x.Content.Headers.ContentType = new MediaTypeHeaderValue(GenericNames.APP_JSON); }).AddHeader("Authorization", new AuthenticationHeaderValue("Bearer", token.access_token).ToString()).SendAsync("PUT").Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "Status Code PUT Account"); response = server.CreateRequest("/api/Account").AddHeader("Authorization", new AuthenticationHeaderValue("Bearer", token.access_token).ToString()).GetAsync().Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var ExposeModel = response.Content.ReadAsAsync<ExposeAccountModel>().Result; Assert.AreEqual(PutClientModel.Civility, ExposeModel.Civility, "Check Civility"); Assert.AreEqual(PutClientModel.Country, ExposeModel.Country, "Check Country"); Assert.AreEqual(PutClientModel.FirstName, ExposeModel.FirstName, "Check FirstName"); Assert.AreEqual(PutClientModel.LastName, ExposeModel.LastName, "Check LastName"); } }
public static Client Create(Client baseModel, PutAccountModel model) { baseModel.Civility = model.Civility; baseModel.Country = model.Country; baseModel.LastName = model.LastName; baseModel.FirstName = model.FirstName; baseModel.Timezone = model.Timezone; return baseModel; }