public async Task Restaurant_Is_Added_When_Correct() { using (var context = new ApplicationDbContext(options)) { var restaurantRequest = new RestaurantRequest() { Name = "Test" }; var manager = new AppUser() { UserName = "******" }; mockMapper.Setup(x => x.Map <RestaurantRequest, Restaurant>(It.IsAny <RestaurantRequest>())) .Returns(new Restaurant() { Name = restaurantRequest.Name, Manager = manager }); mockUserService.Setup(x => x.FindUserByNameOrEmailAsync(manager.UserName)).Returns(Task.FromResult(manager)); var restaurantService = new RestaurantService(context, mockUserService.Object, mockMapper.Object, mockBlobStorageService.Object); var length = await context.Restaurants.CountAsync(); var restaurant = await restaurantService.SaveRestaurantAsync(restaurantRequest, manager.UserName); Assert.Equal(length + 1, await context.Restaurants.CountAsync()); Assert.Equal(restaurant.Name, restaurantRequest.Name); } }
private string GetUrlWithExploreParameters(string baseUrl, RestaurantRequest request) { return(baseUrl + $"&near={request.ZipCode}" + $"&categoryId={request.Category}" + $"&limit={request.ResultCount}"); }
public RestaurantResponse Insert <V>(RestaurantRequest entity) where V : AbstractValidator <RestaurantRequest> { var restaurant = _mapper.Map <Restaurant>(entity); _restaurants.Add(restaurant); return(_mapper.Map <RestaurantResponse>(restaurant)); }
public void TestSetup() { restaurantToAdd = new Restaurant { ContactInformation = new Contact { Address = new Address { Address1 = "address1", Address2 = "address2", Address3 = "address3", City = Guid.NewGuid().ToString(), Country = "USA", State = "PA", ZipCode = Guid.NewGuid().ToString() }, Email = "*****@*****.**", Phone = "412-867-5309" }, Cuisine = "cuisine", Name = "Milliways" }; restaurantRequest = new RestaurantRequest { City = restaurantToAdd.ContactInformation.Address.City, ZipCode = restaurantToAdd.ContactInformation.Address.ZipCode }; user = new User { ContactInformation = new Contact { Address = new Address { Address1 = "address1", Address2 = "address2", Address3 = "address3", City = Guid.NewGuid().ToString(), Country = "USA", State = "PA", ZipCode = Guid.NewGuid().ToString() }, Email = Guid.NewGuid().ToString() }, FirstName = "FirstName", LastName = "LastName", UserName = Guid.NewGuid().ToString() }; AddRestaurantRecordsForTest(); AddUserRecordsForTest(); review = new Review { Comment = "Test comment", RatingDateTime = DateTime.UtcNow, RestaurantId = currentRestaurant.RestaurantId, UserId = currentUser.UserId, Score = 3 }; AddReviewRecordsForTest(); }
public void TestSetup() { restaurantToAdd = new Restaurant { ContactInformation = new Contact { Address = new Address { Address1 = "address1", Address2 = "address2", Address3 = "address3", City = "city", Country = "USA", State = "PA", ZipCode = "zipcode" }, Email = "*****@*****.**", Phone = "412-867-5309" }, Cuisine = "cuisine", Name = "Milliways" }; restaurantRequest = new RestaurantRequest { City = restaurantToAdd.ContactInformation.Address.City, ZipCode = restaurantToAdd.ContactInformation.Address.ZipCode }; AddTestRecordToDatabase(); }
public IEnumerable <Restaurant> GetAllRestaurantsByAddress(RestaurantRequest address) { using (var context = new CMMIContext()) { context.Configuration.LazyLoadingEnabled = false; IUnitOfWork unitOfWork = new UnitOfWork(context); return(unitOfWork.Restaurants.GetRestaurantsByAddress(address)); } }
public IActionResult Edit([FromBody] RestaurantRequest restaurant) { try { return(Ok(_restaurantService.Update <RestaurantValidator>(restaurant))); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> GetRestaurants([FromBody] RestaurantRequest request) { var result = await _restaurantService.GetRestaurants(request); if (result.IsFailed) { return(BadRequest(result.Errors)); } return(Ok(result.Value)); }
public async Task <Restaurant> EditRestaurantAsync(long id, RestaurantRequest restaurantRequest) { var editedRestaurant = await GetRestaurantByIdAsync(id); editedRestaurant = mapper.Map <RestaurantRequest, Restaurant>(restaurantRequest, editedRestaurant); if (restaurantRequest.Image != null) { CloudBlockBlob blob = await blobStorageService.MakeBlobFolderAndSaveImageAsync(int.MaxValue - editedRestaurant.RestaurantId, restaurantRequest.Image); await AddImageUriToRestaurantAsync(id, blob); } await applicationDbContext.SaveChangesAsync(); return(editedRestaurant); }
public void Add_ValidObjectPassed_ReturnsOk() { // Arrange var item = new RestaurantRequest() { Name = "Restaurante 1" }; // Act var okResult = _controller.Save(item) as ObjectResult; // Assert Assert.IsType <RestaurantResponse>(okResult.Value); }
public IEnumerable <Restaurant> GetRestaurantsByAddress(RestaurantRequest address) { if (address == null) { return(null); } return(context.Restaurants.Where(restaurant => (restaurant.ContactInformation.Address.ZipCode == address.ZipCode) || (restaurant.ContactInformation.Address.City == address.City) || (restaurant.RestaurantId == address.RestaurantId)) .Include(contact => contact.ContactInformation) .Include(restaurant => restaurant.ContactInformation.Address) .ToList()); }
public async Task <IActionResult> Add(RestaurantRequest restaurantRequest) { if (ModelState.IsValid) { await restaurantService.SaveRestaurantAsync(restaurantRequest, User.Identity.Name); return(RedirectToAction(nameof(HomeController.Index), "Home")); } var editRestaurantViewModel = new EditRestaurantViewModel() { RestaurantRequest = restaurantRequest, Meals = null, RestaurantId = 0 }; return(View(editRestaurantViewModel)); }
public async Task <Result <IEnumerable <RestaurantResult> > > GetRestaurants(RestaurantRequest request) { try { if (string.IsNullOrEmpty(request.Category)) { return(Result.Fail("No category provided")); } if (request.ZipCode.Length != 5 || !int.TryParse(request.ZipCode, out var zipCode)) { return(Result.Fail("Invalid zip code")); } var client = _httpClientFactory.CreateClient("foursquare"); // Add client secrets to url var baseUrl = GetBaseUrlWithSecrets("explore"); // Add request parameters to url var requestUrl = GetUrlWithExploreParameters(baseUrl, request); var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUrl)); if (!response.IsSuccessStatusCode) { return(Result.Fail("Foursquare service error")); } using var stream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializer.DeserializeAsync <FoursquareFullResponse>(stream, _jsonSerializerOptions); // Get venues from api response var venues = result.GetVenues(); // Convert venues to result objects var restaurants = venues.Select(venue => new RestaurantResult(venue)); return(Result.Ok(restaurants)); } catch (Exception ex) { return(Result.Fail(ex.Message)); } }
public IHttpActionResult Get([FromUri] RestaurantRequest request) { try { _logger.Info("Request received for restaurants by address properties. "); var restaurants = _facade.GetAllRestaurantsByAddress(request).ToList(); if (restaurants.Count == 0) { _logger.Info("No Restaurants found matching the request. "); return(NotFound()); } return(Ok(restaurants)); } catch (Exception ex) { _logger.Error(ex); return(InternalServerError()); } }
public async Task <Restaurant> SaveRestaurantAsync(RestaurantRequest restaurantReq, string managerName) { var manager = await userService.FindUserByNameOrEmailAsync(managerName); var restaurant = mapper.Map <RestaurantRequest, Restaurant>(restaurantReq); restaurant.Manager = manager; await applicationDbContext.Restaurants.AddAsync(restaurant); await applicationDbContext.SaveChangesAsync(); if (restaurantReq.Image == null) { restaurant.ImageUri = "https://dotnetpincerstorage.blob.core.windows.net/mealimages/default/default.png"; } else { CloudBlockBlob blob = await blobStorageService.MakeBlobFolderAndSaveImageAsync(int.MaxValue - restaurant.RestaurantId, restaurantReq.Image); await AddImageUriToRestaurantAsync(restaurant.RestaurantId, blob); } await applicationDbContext.SaveChangesAsync(); return(restaurant); }
public RestaurantResponse Update <V>(RestaurantRequest entity) where V : AbstractValidator <RestaurantRequest> { throw new NotImplementedException(); }
public async Task <EditRestaurantViewModel> BuildEditRestaurantViewModelAsync(long restaurantId, RestaurantRequest restaurantRequest) { var restaurant = await GetRestaurantByIdAsync(restaurantId); var editRestaurantViewModel = new EditRestaurantViewModel() { RestaurantRequest = restaurantRequest, Meals = restaurant.Meals, RestaurantId = restaurant.RestaurantId }; await applicationDbContext.SaveChangesAsync(); return(editRestaurantViewModel); }