public void ToJSONTest() { DateTime birthDate = DateTime.Now; JSONWrappers.SubjectInfo jsonInfo = new JSONWrappers.SubjectInfo { FirstName = "Иван", LastName = "Иванов", Patronymic = "Иванович", Sex = "Male", BirthDate = birthDate.ToString("dd.MM.yyyy"), Address = "123, hghghg", Job = "Programmer", Diseases = "D1, D2", Phone = "88888888888" }; SubjectInfo info = SubjectInfo.FromJSON(jsonInfo); JSONWrappers.SubjectInfo result = info.ToJSON(); Assert.AreEqual(result.FirstName, jsonInfo.FirstName); Assert.AreEqual(result.LastName, jsonInfo.LastName); Assert.AreEqual(result.Patronymic, jsonInfo.Patronymic); Assert.AreEqual(result.Sex, jsonInfo.Sex); Assert.AreEqual(result.Address, jsonInfo.Address); Assert.AreEqual(result.Job, jsonInfo.Job); Assert.AreEqual(result.Diseases, jsonInfo.Diseases); Assert.AreEqual(result.Phone, jsonInfo.Phone); }
public IActionResult PostSubject(JSONWrappers.SubjectInfo jsonInfo) { try { if (ModelState.IsValid) { SubjectInfo info = SubjectInfo.FromJSON(jsonInfo); ulong subjectID = TestDataBase.CreateNewSubject(info); m_Logger.LogInformation($"New subject created with ID {subjectID}"); return(Ok(subjectID)); } return(BadRequest(ModelState)); } catch (Exception e) { m_Logger.LogError(e.Message); throw; } }
public void FromJSONSecondTest() { DateTime birthDate = DateTime.Now; JSONWrappers.SubjectInfo jsonInfo = new JSONWrappers.SubjectInfo { FirstName = "Мария", LastName = "Петрова", Patronymic = "", Sex = "Female", BirthDate = birthDate.ToString("dd.MM.yyyy"), Address = "123, hghghg", Job = "Programmer", Diseases = "D1, D2", Phone = "11111111111" }; SubjectInfo result = SubjectInfo.FromJSON(jsonInfo); Assert.AreEqual(result.FirstName, jsonInfo.FirstName); Assert.AreEqual(result.LastName, jsonInfo.LastName); Assert.AreEqual(result.Patronymic, jsonInfo.Patronymic); Assert.AreEqual(result.Sex, Sex.Female); }