jeudi 28 janvier 2016

C# Unit test for stored procedure methods

Instead of Entity framework, I am using enterprise library to perform the data operations.

The following is my sample BL method which is used to update the person culture. I don't have idea about how to write unit test for these kind of methods.

public static Culture UpdatePersonCulture(Guid userId, Culture culture)
        {
            try
            {
                if (userId == Guid.Empty)
                    throw new exception("User id should not be empty");

                DatabaseProviderFactory factory = new DatabaseProviderFactory();
                Database database = factory.CreateDefault();

                using (DbConnection dbConnection = database.CreateConnection())
                {
                    if (dbConnection.State == ConnectionState.Closed)
                        dbConnection.Open();

                    DbCommand dbCommand = database.GetStoredProcCommand("usp_UpdatePersonCulture");
                    database.DiscoverParameters(dbCommand);
                    dbCommand.Parameters["@userId"].Value = userId;
                    dbCommand.Parameters["@cultureId"].Value = culture.Id;
                    DataSet dataSet = database.ExecuteDataSet(dbCommand);
                    return BLDataPopulation.PopulateCultures(dataSet.Tables[0]).FirstOrDefault();
                }
            }
            catch (Exception exception)
            {
                throw BLLogger.Log(exception);
            }
        }

Aucun commentaire:

Enregistrer un commentaire