public void DeleteUser() { var userRepository = new UsersRepository(); var userDelete = new User { Id = 7 }; userRepository.Delete(userDelete); }
public void ShouldCreateUser() { //arrange var userRepository = new UsersRepository(); var user = new User { Email = "*****@*****.**", FullName = "test", Twitter = "test.tw", Facebook = "test.fb" }; //act userRepository.Create(user); //asserts //var resultUser = userRepository.Get(user.Id); //Assert.AreEqual(user.Email, resultUser.Email); }
public void Create(User user) { if (user == null) throw new ArgumentNullException("user"); using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "INSERT INTO [dbo].[users] (fullname, email, twitter, facebook) VALUES (@fullname, @email, @twitter, @facebook)"; command.Parameters.AddWithValue("@fullname", user.FullName); command.Parameters.AddWithValue("@email", user.Email); command.Parameters.AddWithValue("@twitter", user.Twitter); command.Parameters.AddWithValue("@facebook", user.Facebook); command.ExecuteNonQuery(); } } }
public void Update(int id, User user) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { //нужно поправить, проблемы с null command.CommandText = "UPDATE [dbo].[users] SET fullname=@fullname WHERE id = @id"; command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@fullname", user.FullName); // command.Parameters.AddWithValue("@email", user.Email); // command.Parameters.AddWithValue("@twitter",user.Twitter); // command.Parameters.AddWithValue("@facebook", user.Facebook); command.ExecuteNonQuery(); } } }