public void DeleteWithIncorrectId() { var testConference = new ConferenceWithoutIDModel(); var testId = new Guid().ToString("N"); var testController = new ConferencesController(); Assert.Throws <NotFoudException>(delegate { testController.Delete(testId); }); }
public void Post() { var testConference = new ConferenceWithoutIDModel(); var result = new Guid().ToString("N"); var testController = new ConferencesController(); Assert.AreEqual(result.GetType(), testController.Post(testConference).GetType()); }
internal static string PutConference(ConferenceWithoutIDModel conference) { var conferences = getData(Constants.pathToFile); var id = Guid.NewGuid().ToString("N"); conferences.Add(conference.ToConferenceWithIDModel(id)); var result = JsonConvert.SerializeObject(conferences); using (StreamWriter streamWriter = new StreamWriter(Constants.pathToFile, false)) { streamWriter.WriteLine(result); } return(id); }
internal static void UpdateConference(ConferenceWithoutIDModel updatedConference, string id) { var isFound = false; var conferences = getData(Constants.pathToFile); foreach (var conference in conferences) { if (conference._id == id) { conferences.Remove(conference); isFound = true; break; } } if (!isFound) { throw new NotFoudException("Conferences are not found", 404); } conferences.Add(updatedConference.ToConferenceWithIDModel(id)); string result = JsonConvert.SerializeObject(conferences); using (StreamWriter streamWriter = new StreamWriter(Constants.pathToFile, false)) { streamWriter.WriteLine(result); } }
public void Put([FromBody] ConferenceWithoutIDModel conference, string id) { WorkWithData.UpdateConference(conference, id); }
public string Post([FromBody] ConferenceWithoutIDModel conference) { return(WorkWithData.PutConference(conference)); }