public void Setup() { logger = Substitute.For <ILogger <UserLocationController> >(); locationService = Substitute.For <ILocationService>(); bpdtsClient = Substitute.For <IBpdtsClient>(); userLocationController = new UserLocationController(logger, locationService, bpdtsClient); }
public void Index() { //ARRANGE UserLocationController controller = new UserLocationController(); //ACT var result = controller.Index() as ViewResult; //ASSERT Assert.IsNotNull(result); }
public void SetLoggedUserLocation() { UserLocationController usersController = CreateFakeUserLocationController(_users[0]); //Setting logged user location var response = usersController.PostUserLocation(new LocationModel(10, 10)); Assert.IsType <OkObjectResult>(response.Result); Assert.Equal(_users[0].Location.Latitude, ((LocationModel)((OkObjectResult)response.Result).Value).Latitude); Assert.Equal(_users[0].Location.Longitude, ((LocationModel)((OkObjectResult)response.Result).Value).Longitude); }
private UserLocationController CreateFakeUserLocationController(User loggedUser = null) { //Create fake DBContext var context = new GlovoDbContext(ContextOptions); //Create fake HttpContextAccessor var httpContext = new DefaultHttpContext(); var httpContextAccessor = new HttpContextAccessor { HttpContext = httpContext }; //Add logged user to HttpContextAccessor in case it is needed if (loggedUser != null) { httpContextAccessor.HttpContext.Items["User"] = loggedUser; } //Create RestApiUsersService instance with fake DBContext and HttpContextAccessor _usersService = new RestApiUsersService(context, httpContextAccessor); //Create mapper with UsersProfile var mapper = new MapperConfiguration(cfg => { cfg.AddProfile <LocationsProfile>(); cfg.AddProfile <OrdersProductsProfile>(); cfg.AddProfile <OrdersProfile>(); cfg.AddProfile <ProductsProfile>(); cfg.AddProfile <RestaurantsProfile>(); cfg.AddProfile <UsersProfile>(); }).CreateMapper(); //Create UsersController instance with the RestApiUsersService instance and the mapper var usersController = new UserLocationController(_usersService, mapper) { ControllerContext = { HttpContext = httpContext } }; return(usersController); }