public void Setup() { //Mock HttpMessageHandler of HttpClient var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); handlerMock .Protected() // Setup the PROTECTED method to mock .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(UserData.UserDataString()), }) .Verifiable(); // use real http client with mocked handler here var httpClient = new HttpClient(handlerMock.Object) { BaseAddress = new Uri("http://test.com/"), }; mockAPIService = new APIService(httpClient); mockdistanceCalculationService = new DistanceCalculationService(); mockUserFilterService = new UserFilterService(mockAPIService, mockdistanceCalculationService); }
public RandomEnglishTaskService( IEnglishTaskRepository taskRepository, ApplicationMapper applicationMapper, IUserFilterService userFilterService) { _taskRepository = taskRepository; _mapper = applicationMapper.Mapper; _userFilterService = userFilterService; }
public HomeController(IAPIService apiService, IUserFilterService userFilterService, IDistanceCalculationService distanceCalculationService) { this.apiService = apiService; this.userFilterService = userFilterService; this.distanceCalculationService = distanceCalculationService; }
public HomeController() { apiService = new APIService(Client); distanceCalculationService = new DistanceCalculationService(); userFilterService = new UserFilterService(apiService, distanceCalculationService); }