Search code examples
asp.netunit-testingtestingmvpnsubstitute

Why can't I mock out a view property in MVP using NSubstitute


i'm trying to unit test my presenter in MVP application. here is my view interface which i'm trying to mock out using NSubstitude:

public interface ICategoriesView : IBaseViewInterface
{
    string CategoryName { get; }
    long CategorId { get; }
    long CategoryParent { get; }
    IEnumerable<EntityObject> CategoryDataSource { set; }
}

here is my unit test class. i'm using NUnit framework:

[TestFixture]
public class CategoriesTests
{
    [Test(Description="this is used for testing the behavior of presenter if we pass empty name.")]
    public void Add_EmptyName_Fails()
    {
        var _view = NSubstitute.Substitute.For<ICategoriesView>();
        //now here i'm supposed to get something like _view.CategoryId.Returns(2) but i don't!
        //the error message says that _view.CategoryId doesn't have an extension method 
        //named Returns. and it's true since intellisence doesn't list it after period
    }
}

i added set modifer to the view interface and it didn't work. so what is wrong?


Solution

  • actually i forgot to add a using NSubstitude on top of my test class.