mercredi 5 août 2015

How to setup a controller's method using moq

I have an action method in my controller as below

public ActionResult Index()
{
     var supplier = GetSupplierForUser();
     var model = SupplierService.GetOutstandingItems(supplier);          
     return View(model);
}

I've setup the supplier service method as

var supplierService = new Mock<ISupplierService>();
var supplier = new Supplier { Name = "Some Name",Id = 100};

supplierService.Setup(s => s.GetOutstandingItems(supplier))
                            .Returns(outstandingSupplierItemInfo.Object);

I don't know how can we setup the method Supplier GetSupplierForUser() which is present in the base controller to return a Supplier object. From the moq setup above a null supplier is always passed to SupplierService.GetOutstandingItems(supplier)

Any ideas? thanks

Aucun commentaire:

Enregistrer un commentaire