public PlayersBaseInfoView GetPlayerBaseInfo(int playerId) { PlayersBaseInfoView result = null; using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[Helper.ConnectionName].ConnectionString)) { result = connection.Query <PlayersBaseInfoView>( "select " + " pbi.id" + ", pbi.FirstName" + ", pbi.LastName" + ", pbi.BirthYear" + ", pbi.BirthMonth" + ", pbi.BirthDay" + ", pbi.BirthplaceCountry" + ", pbi.BirthplaceCity" + ", pbi.[Weight]" + ", pbi.Height" + ", pbi.IsRightHanded" + ", pbi.IsTwoHandedBackhand" + ", pbi.CoachId" + ", pbi.CoachFirstName" + ", pbi.CoachLastName " + "from " + " dbo.PlayersBaseInfo pbi " + "where " + " pbi.Id = @Id", new { Id = playerId }).FirstOrDefault(); } return(result); }
public async Task GetPlayerBaseInfo_ForPlayer_PlayerExists() { // Arrange const int playerId = 1; PlayersBaseInfoView result = null; // Act using (var dataAccess = this.GetDataAccess()) { result = await dataAccess.GetPlayerBaseInfo(playerId).ConfigureAwait(false); } // Assert Assert.That(result, Is.Not.Null); System.Console.WriteLine(this.serializer.Serialize(result)); }
public async Task SetPlayerCoach_NewPalyer_CoachSet(int?coachId, int?previousCoachId) { // Arrange const int playerId = 1; PlayersBaseInfoView result = null; // Act using (var dataAccess = this.GetDataAccess()) { await dataAccess.SetPlayerCoach(playerId, coachId, previousCoachId).ConfigureAwait(false); } // Assert using (var dataAccess = this.GetDataAccess()) { result = await dataAccess.GetPlayerBaseInfo(playerId).ConfigureAwait(false); } Assert.That(result.CoachId, Is.EqualTo(coachId)); }
public async Task AddPlayer_NewPalyer_PlayerAdded() { // Arrange const int personId = 1; PlayersBaseInfoView result = null; // Act using (var dataAccess = this.GetDataAccess()) { await dataAccess.AddPlayer(personId, true, true).ConfigureAwait(false); } // Assert using (var dataAccess = this.GetDataAccess()) { result = await dataAccess.GetPlayerBaseInfo(personId).ConfigureAwait(false); } Assert.That(result, Is.Not.Null); }
public PlayersBaseInfoView GetPlayerBaseInfo(int playerId) { PlayersBaseInfoView result = null; using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[Helper.ConnectionName].ConnectionString)) { using (var command = new SqlCommand()) { command.Connection = connection; command.CommandType = CommandType.Text; command.CommandText = "select " + " pbi.id" + ", pbi.FirstName" + ", pbi.LastName" + ", pbi.BirthYear" + ", pbi.BirthMonth" + ", pbi.BirthDay" + ", pbi.BirthplaceCountry" + ", pbi.BirthplaceCity" + ", pbi.[Weight]" + ", pbi.Height" + ", pbi.IsRightHanded" + ", pbi.IsTwoHandedBackhand" + ", pbi.CoachId" + ", pbi.CoachFirstName" + ", pbi.CoachLastName " + "from " + " dbo.PlayersBaseInfo pbi " + "where " + " pbi.Id = @Id"; command.Parameters.Add("@Id", SqlDbType.Int, 4).Value = playerId; connection.Open(); using (var reader = command.ExecuteReader()) { if (reader.Read()) { result = new PlayersBaseInfoView { Id = Convert.ToInt32(reader["Id"]), FirstName = reader["FirstName"].ToString(), LastName = reader["LastName"].ToString(), BirthYear = Convert.ToInt32(reader["BirthYear"]), BirthMonth = Convert.ToInt32(reader["BirthMonth"]), BirthDay = Convert.ToInt32(reader["BirthDay"]), BirthplaceCountry = reader["BirthplaceCountry"].ToString(), BirthplaceCity = reader["BirthplaceCity"].ToString(), Weight = Convert.ToInt32(reader["Weight"]), Height = Convert.ToInt32(reader["Height"]), IsRightHanded = Convert.ToBoolean(reader["IsRightHanded"]), IsTwoHandedBackhand = Convert.ToBoolean(reader["IsTwoHandedBackhand"]), CoachId = reader["CoachId"] == DBNull.Value ? default(int?) : Convert.ToInt32(reader["CoachId"]), CoachFirstName = reader["CoachFirstName"] == DBNull.Value ? null : reader["CoachFirstName"].ToString(), CoachLastName = reader["CoachLastName"] == DBNull.Value ? null : reader["CoachLastName"].ToString(), }; } } } } return(result); }