public void InvalidPut() { // Arrange bool res = false; SQLiteServiceBase db = new SQLiteServiceBase(); RestrictedInfo obj = GetInvalidObject(); // Act try { int len = 0; if (db.GetRestrictedInfo() != null) { foreach (var c in db.GetRestrictedInfo()) { len++; } } if (len != 0) { db.Edit(len - 1, obj); } } catch (Exception) { res = true; } // Assert Assert.IsFalse(res); }
RestrictedInfo GetInvalidObject() { RestrictedInfo obj = new RestrictedInfo(); obj.DateOfBirth = "13.12.2001"; obj.DateOfDeath = "unknown"; return(obj); }
public void DeleteRestrictedInfo(int id) { RestrictedInfo obj = dataBase.RestrictedInfo.Find(id); if (obj != null) { dataBase.RestrictedInfo.Remove(obj); Update(); } }
RestrictedInfo GetValidObject() { RestrictedInfo obj = new RestrictedInfo(); obj.DateOfBirth = "13.12.2001"; obj.DateOfDeath = "unknown"; obj.GovernmentId = "why Id is string?"; obj.PassportId = "MP12333"; obj.HireDire = "what is it"; obj.SeniorityCode = 112233; return(obj); }
public RestrictedInfo GetRestrictedInfoId(int id) { RestrictedInfo obj = null; foreach (RestrictedInfo o in dataBase.RestrictedInfo) { if (o.== id) { obj = o; break; } } return(obj); }
// PUT api/RestrictedInfo/{id} public IHttpActionResult Put(int id, [FromBody] RestrictedInfo value) { try { _db.Edit(id, value); } catch (Exception ex) { ModelState.AddModelError(nameof(RestrictedInfo), ex.Message); return(BadRequest(ModelState)); } return(Ok()); }
// POST api/RestrictedInfo public IHttpActionResult Post([FromBody] RestrictedInfo value) { try { db.Add(value); } catch (Exception ex) { ModelState.AddModelError(nameof(Country), ex.Message); return(BadRequest(ModelState)); } return(Ok()); }
public void Edit(int id, RestrictedInfo obj) { using (var context = new ApplicationContext()) { var temp = context.RestrictedInfo.FirstOrDefault(_ => _.== id); try { if (temp != null) { // // change properties // context.SaveChanges(); } } catch (Exception) { /*TO DO*/ } } }
public void InvalidPost() { // Arrange bool res = false; SQLiteServiceBase db = new SQLiteServiceBase(); RestrictedInfo obj = GetInvalidObject(); // Act try { db.Add(obj); } catch (Exception) { res = true; } // Assert Assert.IsTrue(res); }
public void Edit(int id, RestrictedInfo obj) { using (var context = new ApplicationContext()) { var temp = context.RestrictedInfo.FirstOrDefault(_ => _.PersonId == id); try { if (temp != null) { temp.DateOfBirth = obj.DateOfBirth; temp.DateOfDeath = obj.DateOfDeath; temp.GovernmentId = obj.GovernmentId; temp.PassportId = obj.PassportId; temp.HireDire = obj.HireDire; temp.SeniorityCode = obj.SeniorityCode; context.SaveChanges(); } } catch (Exception) { /*TO DO*/ } } }
public void Add(RestrictedInfo obj) { dataBase.RestrictedInfo.Add(obj); Update(); }