I can't configurate Code Contracts in my class. I've followed the documentation and the example but it doesn't work.
I would to insert Code Contracts condition into my interface, here my code
The interface
[ContractClass(typeof(ArticleBLLContract))]
public interface IArticleBLL
{
int getArticleNSheet(string IdBox);
IEnumerable<IArticle> getArticleValue(string IdBox, string IdLanguage);
}
The Contract Class
[ContractClassFor(typeof(IArticleBLL))]
public sealed class ArticleBLLContract : IArticleBLL
{
int IArticleBLL.getArticleNSheet(string IdBox)
{
Contract.Requires<ArgumentOutOfRangeException>(!String.IsNullOrEmpty(IdBox),"IdBox has no valid value");
return default(int);
}
IEnumerable<Base.Article.IArticle> IArticleBLL.getArticleValue(string IdBox, string IdLanguage)
{
Contract.Requires<ArgumentOutOfRangeException>(!String.IsNullOrEmpty(IdBox), "IdBox has no valid value");
Contract.Requires<ArgumentOutOfRangeException>(!String.IsNullOrEmpty(IdLanguage), "IdLanguagehas no valid value");
Contract.Ensures(Contract.Result<IEnumerable<Base.Article.IArticle>>() != null, "Return value is out of Range");
return default(IEnumerable<Base.Article.IArticle>);
}
}
The class to apply Contract
public class ArticleBLL : IArticleBLL
{
public int getArticlNSheet(string IdBox)
{
try
{
return _Dal...
}
catch (Exception ex)
{
throw ex;
}
}
public IEnumerable<IArticle> getArticleValue(string IdBox, string IdLanguage)
{
IEnumerable<IArticle> article = null;
try
{
article = _Dal...
return article;
}
catch (Exception ex)
{
throw ex;
}
}
}
I've tried to insert a breakpoint in this line
Contract.Requires<ArgumentOutOfRangeException>(!String.IsNullOrEmpty(IdBox),"IdBox has no valid value");
but when I call the method it never passes here This is my project configuration
Is there something wrong?
Thank you!
Assembly Mode in your configuration should be "Standard Contract Requires".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With