private readonly Mock <ILogger <ConsultantsController> > logger; //create Moq object of Serilog public ConsultantsControllerUnitTests() { mockService = new Mock <IService>(); logger = new Mock <ILogger <ConsultantsController> >(); //Setup moq controller with moq objects and local version of automapper consultantsController = new ConsultantsController(mockService.Object, logger.Object); expectedListShopsConsultants = GetExpectedListShopsConsultants(); //Setup all methods of the moq object of Repository mockService.Setup(m => m.GetShopsConsultants()).Returns(Task.FromResult(expectedListShopsConsultants)); mockService.Setup(m => m.AddConsultant(It.IsAny <AddConsultantViewModel>())) .Returns((AddConsultantViewModel target) => { expectedListShopsConsultants.Consultants.Add(4, target.Name); return(Task.FromResult(true)); }); mockService.Setup(m => m.AppointConsultant(It.IsAny <AppointConsultantViewModel>())) .Returns((AppointConsultantViewModel target) => { string shopName; var shop = expectedListShopsConsultants.Shops. TryGetValue(Convert.ToInt32(target.ShopId), out shopName); if (shop) { return(Task.FromResult(true)); } return(Task.FromResult(false)); }); }
private ConsultantsController GetConsultantsController(IQueryable <Consultant> consultants) { var dataContextMock = new Mock <DataAccess.ContosoConsultancyDataContext>(); var consultantDBSetMock = TestHelper.GetMockedDbSet(consultants); var urlHelperMock = new Mock <UrlHelper>(); dataContextMock.Setup(m => m.Consultants).Returns(consultantDBSetMock.Object); urlHelperMock.Setup(u => u.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(""); var controller = new ConsultantsController(dataContextMock.Object) { Url = urlHelperMock.Object }; return(controller); }
public ConsultantControllerTest() { _mediator = A.Fake <IMediator>(); _controller = new ConsultantsController(_mediator); }
void before_each() { controller = new ConsultantsController(); consultants = new Consultants(); }