mardi 6 juin 2017

Testing A function

I need to write a unit test for a function. I have no idea about testing and the examples I have seen are more maths oriented so I can not understand how to write a test for this funtion. Can Anyone please help me write a unit test for this function:

public static void CreateUser(
    int userId, 
    string name, 
    System.DateTime createdAt, 
    string createdBy, 
    System.DateTime modifiedAt, 
    string modifiedBy, 
    string address, 
    string city, 
    string province, 
    string country, 
    string postcode, 
    string phone)
{
    try
    {
        using (UserDbContext _usermain = new UserDbContext())
        {
            User newuser = new User()
            {
                UserId = userId,
                Name = name,
                CreatedAt = createdAt,
                CreatedBy = createdBy,
                ModifiedBy = modifiedBy,
                ModifiedAt = modifiedAt,
                Address = address,
                City = city
            };
            _usermain.Users.Add(newuser);
            _usermain.SaveChanges();
        }
    }
    catch (Exception ex)
    {
        string error = string.Format("Error in Creating User", ex.Message);
        throw new Exception(error, ex);
    }
}

Aucun commentaire:

Enregistrer un commentaire