public LobbyCreationInfo Create([FromBody] LobbyPostInfo model) { if (string.IsNullOrWhiteSpace(model.LobbyName)) { return(default(LobbyCreationInfo)); } var table = new DataTable(); using (var connection = new SqlConnection(connectionString)) using (var command = new SqlCommand("usp_CreateLobby", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@name", model.LobbyName)); command.Parameters.Add(new SqlParameter("@hostid", model.UserId)); var dataAdapter = new SqlDataAdapter(command); connection.Open(); dataAdapter.Fill(table); connection.Close(); var resultSet = table.Rows[0]; return(new LobbyCreationInfo() { CreationDate = DateTime.Parse(resultSet["CreationDate"].ToString()), LobbyId = int.Parse(resultSet["LobbyId"].ToString()), LobbyName = resultSet["Name"].ToString() }); } }
public void CreatePassingTest() { LobbiesController controller = new LobbiesController(); const string lobbyName = "invocation_lobbyName"; const int userId = 6; var model = new LobbyPostInfo() { LobbyName = lobbyName, UserId = userId }; var response = controller.Create(model); Assert.IsNotNull(response); Assert.IsNotNull(response.CreationDate); Assert.AreEqual(response.LobbyName, lobbyName); }