public void CheckUserIdGenerated() { string pathToDb = Path.GetFullPath("test_db.mdf"); PhoneBookDatebase db = new PhoneBookDatebase(pathToDb); db.InitializeDatabase(); db.OpenConnection(); Assert.Equal(1, db.AddUser("Vasia", "Ivanov", "03.12.2012")); Assert.Equal(1, db.AddUser("Petia", "Petrov", "08.07.2000")); SqlCommand getUserIdsCommand = new SqlCommand("SELECT Id FROM Users", db.DatabaseConnection); SqlDataReader reader = getUserIdsCommand.ExecuteReader(); List <int> userIds = new List <int>(); while (reader.Read()) { userIds.Add(reader.GetInt32(0)); } reader.Close(); Assert.Equal(2, userIds.Count); Assert.NotEqual(userIds[0], userIds[1]); db.CloseConnection(); db.DeleteDatabase(); }
public void CheckUserDeleted() { string pathToDb = Path.GetFullPath("test_db.mdf"); PhoneBookDatebase db = new PhoneBookDatebase(pathToDb); db.InitializeDatabase(); db.OpenConnection(); Assert.Equal(1, db.AddUser("Vasia", "Ivanov", "03.12.2012")); Assert.Equal(1, db.AddPhoneNumber("1", "+375259002315")); Assert.Equal(1, db.DeleteUser("Vasia")); SqlCommand getUsersCommand = new SqlCommand("SELECT * FROM Users", db.DatabaseConnection); SqlDataReader getUsersReader = getUsersCommand.ExecuteReader(); Assert.False(getUsersReader.HasRows); getUsersReader.Close(); SqlCommand getPhoneNumbersCommand = new SqlCommand("SELECT * FROM PhoneNumbers", db.DatabaseConnection); SqlDataReader getPhoneNumbersReader = getPhoneNumbersCommand.ExecuteReader(); Assert.False(getPhoneNumbersReader.HasRows); getPhoneNumbersReader.Close(); db.CloseConnection(); db.DeleteDatabase(); }