I have similar methods, in the Business layer. New to unit testing and sometimes get confused. For an idea, can you suggest, what will be a better approach to test this method behaviour? I am using C# NUnit and Moq
public int? AddNewCatRetID(string categoryName)
{
int? categoryID = 0;
Adapter.AddNewBlogCategoryReturnID(categoryName, ref categoryID);
if (categoryID.HasValue)
return categoryID;
else return 0;
}
where
Aadpter = Visual Studio 2008, Data Set Designer generated TableAdater
AddDeveloperCategoryReturnID() = Name of a function which utilises a Stored procedure in DB
It adds a new record, "Category" and returns its auto generated ID. If it is non zero, we take that result for further processing.
I know, should not be interested in talking to Database, below is the procedure, just to give an idea about what is going on in DB
PROCEDURE [dbo].[AddDeveloperCategoryReturnID]
@NAME NVARCHAR(MAX),
@CATEGORY_ID INT OUTPUT
AS
BEGIN
INSERT INTO [AllTimeGreatProgrammersDateBase].dbo.CATEGORIES
(NAME )
VALUES (@NAME )
SET @CATEGORY_ID = SCOPE_IDENTITY()
SELECT @CATEGORY_ID
END
some issues
- how to check the values returned using "ref" from the method
- what will you prefer to test and not to test? will be great if can list