//It's not really a edit, just create a new version, with new time and new text public async Task <Room> Edit(EditRoomDTO editRoom, int jwtOwner, MyDbContext _context) { var helper = Helper.ValidRoomName(editRoom.NewName); if (!helper) { throw new Exception("Room name is invalid"); } var room = await _context.Rooms.FirstOrDefaultAsync(c => c.RoomID == editRoom.RoomId); if (room == null) { throw new Exception("Room does not exist, please contact the chat administrator"); } room.RoomName = editRoom.NewName; await _context.SaveChangesAsync(); return(room); }
public async Task EditRoom(string newRoomName, int roomId, JwtToken jwt, bool valid) { var client = _factory.CreateClient(); var newRoom = new EditRoomDTO(roomId, newRoomName); var addMessageJson = new StringContent( JsonConvert.SerializeObject(newRoom), Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Add("jwt", jwt.Token); var response = await client.PostAsync("/editroom", addMessageJson); var result = await response.Content.ReadAsStringAsync(); if (valid) { Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode); } else { Assert.Equal(System.Net.HttpStatusCode.InternalServerError, response.StatusCode); } }