public IHttpActionResult RegisteredUserRestaurantSelection(string city, string state, string foodType, int distanceInMiles, int avgFoodPrice) { // Model Binding Validation if (!ModelState.IsValid) { return(BadRequest(GeneralErrorMessages.MODEL_STATE_ERROR)); } try { // Instantiating dependencies var restaurantSelectionDto = new RestaurantSelectionDto(city: city, state: state, foodType: foodType, distanceInMiles: distanceInMiles, avgFoodPrice: avgFoodPrice); var restaurantSelectionManager = new RegisteredUserRestaurantSelectionManager(restaurantSelectionDto: restaurantSelectionDto, token: Request.Headers.Authorization.Parameter); // Select a restaurant var response = restaurantSelectionManager.SelectRestaurant(); if (response.Error != null) { // Sending HTTP response 400 Status return(BadRequest(response.Error)); } // Sending HTTP response 200 Status return(Ok(response.Data)); } // Catch exceptions catch (Exception) { return(InternalServerError()); } }
public void Should_PassRegisteredUserPostLogicValidation_When_AllRulesPass() { // Arrange var restaurantSelectionDtoValidator = new RestaurantSelectionDtoValidator(); var restaurantSelectionDto = new RestaurantSelectionDto { City = "Los Angeles", State = "CA", FoodType = "American Food", DistanceInMiles = 10, FoodPreferences = new List <string> { "Halal", "Vegetarian" }, AvgFoodPrice = 1, CurrentUtcDateTime = DateTime.UtcNow }; // Act var result = restaurantSelectionDtoValidator.Validate(restaurantSelectionDto, ruleSet: "RegisteredUserPostLogic"); var isValid = result.IsValid; // Assert isValid.Should().Be(true); }
protected RestaurantSelectionManager(RestaurantSelectionDto restaurantSelectionDto) { RestaurantSelectionDto = restaurantSelectionDto; SelectedRestaurantDto = new SelectedRestaurantDto(); _restaurantSelectionPreLogicValidationStrategy = new RestaurantSelectionPreLogicValidationStrategy(restaurantSelectionDto); _geocodeService = new GoogleGeocodeService(); _timeZoneService = new GoogleTimeZoneService(); _dateTimeService = new DateTimeService(); }
public void Should_FailRegisteredUserPostLogicValidation_When_CurrentUtcDateTimeIsEmpty() { // Arrange var restaurantSelectionDtoValidator = new RestaurantSelectionDtoValidator(); var restaurantSelectionDto = new RestaurantSelectionDto { City = "Los Angeles", State = "CA", FoodType = "", DistanceInMiles = 10, AvgFoodPrice = 1 }; // Act var result = restaurantSelectionDtoValidator.Validate(restaurantSelectionDto, ruleSet: "RegisteredUserPostLogic"); var isValid = result.IsValid; // Assert isValid.Should().Be(false); }
public void Should_FailPreLogicValidation_When_DistanceInMilesIsEmpty() { // Arrange var restaurantSelectionDtoValidator = new RestaurantSelectionDtoValidator(); var restaurantSelectionDto = new RestaurantSelectionDto { City = "Los Angeles", State = "CA", FoodType = "American Food", AvgFoodPrice = 1, CurrentUtcDateTime = DateTime.UtcNow }; // Act var result = restaurantSelectionDtoValidator.Validate(restaurantSelectionDto, ruleSet: "PreLogic"); var isValid = result.IsValid; // Assert isValid.Should().Be(false); }
public void Should_FailRegisteredUserPostLogicValidation_When_CityIsNull() { // Arrange var restaurantSelectionDtoValidator = new RestaurantSelectionDtoValidator(); var restaurantSelectionDto = new RestaurantSelectionDto { City = null, State = "CA", FoodType = "American Food", DistanceInMiles = 10, AvgFoodPrice = 1, CurrentUtcDateTime = DateTime.UtcNow }; // Act var result = restaurantSelectionDtoValidator.Validate(restaurantSelectionDto, ruleSet: "RegisteredUserPostLogic"); var isValid = result.IsValid; // Assert isValid.Should().Be(false); }
public UnregisteredUserRestaurantSelectionPostLogicValidationStrategy(RestaurantSelectionDto restaurantSelectionDto) { _restaurantSelectionDto = restaurantSelectionDto; _restaurantSelectionDtoValidator = new RestaurantSelectionDtoValidator(); }
public RegisteredUserRestaurantSelectionManager(RestaurantSelectionDto restaurantSelectionDto, string token) : base(restaurantSelectionDto) { _registeredUserRestaurantSelectionPostLogicValidationStrategy = new RegisteredUserRestaurantSelectionPostLogicValidationStrategy(restaurantSelectionDto); _tokenService = new TokenService(); _token = token; }
public RestaurantSelectionPreLogicValidationStrategy(RestaurantSelectionDto restaurantSelectionDto) { _restaurantSelectionDto = restaurantSelectionDto; _restaurantSelectionDtoValidator = new RestaurantSelectionDtoValidator(); }
public UnregisteredUserRestaurantSelectionManager(RestaurantSelectionDto restaurantSelectionDto) : base(restaurantSelectionDto) { _unregisteredUserRestaurantSelectionPostLogicValidationStrategy = new UnregisteredUserRestaurantSelectionPostLogicValidationStrategy(restaurantSelectionDto); }