passing a model int as a parameter in method

I am writing a unit test and i wrote a method to pass in parameters for testing. one of my ids are an integer but of a different type. Here is what i have:

Service layer:

public IEnumerable<IElement> GetType(int id, int userId, ElementType type, int depth = 2)
    {
        using (var db = database.connection)
        {

            var _results = db.table<_ElementBase>(id, userId, type.ModelId, IElementExtensions.IElementFactory(), depthLevel: depth);
            return _results.FilterByPermissions(userId);
        }
    }

ElementType Model:

public int ModelId { get; set; }

Unit Test code to test:

 var _elements = _elementSvc.GetType(82,1,10,2);

Here it is not likeing the (10) and it wants ElementType

Answers


Well yes - look at your parameter list:

GetType(int id, int userId, ElementType type, int depth = 2)

How are you expecting the third argument (10) to be converted into an ElementType? And how would you expect a ModelId to be extracted from that?

You should either change GetType to just take the modelId directly:

public IEnumerable<IElement> GetType(int id, int userId, int modelId, int depth = 2)
{
    using (var db = database.connection)
    {
        var _results = db.table<_ElementBase>(id, userId, modelId, 
                 IElementExtensions.IElementFactory(), depthLevel: depth);
        return _results.FilterByPermissions(userId);
    }
}

You could then overload the method if you still wanted the original signature as well:

public IEnumerable<IElement> GetType(int id, int userId, ElementType type,
                                     int depth = 2)
{
    return GetType(id, userId, type.ModelId, depth);
}

Need Your Help

Apache2 not starting

linux apache apache2

Every time I try to start apache, I get this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.