예제 #1
0
        public void UpdateDrink()
        {
            var fortyTwoUnits = new DrinkUpdate()
            {
                Quantity = 42
            };
            var response = CheckoutClient.DrinkService.UpdateDrink(_pepsiId, fortyTwoUnits);

            response.Should().NotBeNull();
            response.HttpStatusCode.Should().Be(HttpStatusCode.OK);
            response.Model.Should().NotBeNull();
            response.Model.Quantity.Should().Be(42);
        }
예제 #2
0
        public HttpResponseMessage Put(string id, DrinkUpdate updateDrinkData)
        {
            var drink = new Drink()
            {
                Id       = id,
                Name     = updateDrinkData.Name != null ? updateDrinkData.Name : " ",
                Quantity = updateDrinkData.Quantity
            };

            var validationResult = _drinkValidator.Validate(drink);

            try
            {
                if (validationResult.IsValid)
                {
                    var drinkResult = _drinkService.Update(drink);
                    return(Request.CreateResponse <Drink>(HttpStatusCode.OK, drinkResult));
                }
                else
                {
                    var responseError = new ResponseError()
                    {
                        Errors = validationResult.ErrorList
                    };
                    return(Request.CreateResponse <ResponseError>(HttpStatusCode.BadRequest, responseError));
                }
            }
            catch (ArgumentException ex)
            {
                var responseError = new ResponseError()
                {
                    Errors = new List <string>()
                    {
                        ex.Message
                    }
                };
                return(Request.CreateResponse <ResponseError>(HttpStatusCode.BadRequest, responseError));
            }
        }
예제 #3
0
        public HttpResponse <OkResponse> UpdateDrink(string drinkId, DrinkUpdate requestModel)
        {
            var updateDrinkUri = string.Format(ApiUrls.Drink, drinkId);

            return(new ApiHttpClient().PutRequest <OkResponse>(updateDrinkUri, AppSettings.SecretKey, requestModel));
        }
예제 #4
0
        public HttpResponse <Drink> UpdateDrink(string drinkId, DrinkUpdate requestModel)
        {
            var updateDrinkUri = string.Format(ApiUrls.Drink, drinkId);

            return(new ApiHttpClient().PutRequest <Drink>(updateDrinkUri, requestModel));
        }