示例#1
0
        public void DeleteAsync_PerformsCorrectRequest()
        {
            HttpRequestMessage actualRequest = null;

            _innerHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage()))
            .Callback <HttpRequestMessage, CancellationToken>((request, _) => actualRequest = request);

            _testObject.DeleteAsync("path/id", CancellationToken.None).Wait();

            Assert.NotNull(actualRequest);
            Assert.AreEqual(HttpMethod.Delete, actualRequest.Method);
            Assert.AreEqual(BaseAddress + "/path/id", actualRequest.RequestUri.ToString());
        }
示例#2
0
 public ActionResult DeleteScheduleConfirmed(int id)
 {
     using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
     {
         var responseMessage = httpClient.DeleteAsync("api/ScheduleAPI/" + id.ToString()).Result;
         responseMessage.EnsureSuccessStatusCode();
     }
     return(RedirectToAction("IndexSchedule"));
 }
示例#3
0
 public ActionResult RecurringShiftDeleteConfirmed(Guid BusinessLocationId, Guid id)
 {
     using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
     {
         var responseMessage = httpClient.DeleteAsync("api/ShiftTemplateAPI/" + id.ToString()).Result;
         responseMessage.EnsureSuccessStatusCode();
     }
     return(RedirectToAction("RecurringShiftIndex", new { businesslocationid = BusinessLocationId }));
 }
示例#4
0
 public ActionResult RoleDeleteConfirmed(Guid employeeid, Guid id)
 {
     using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
     {
         var responseMessage = httpClient.DeleteAsync("api/EmployeeAPI/Employee/" + employeeid.ToString() + "/Role/" + id.ToString()).Result;
         responseMessage.EnsureSuccessStatusCode();
     }
     return(RedirectToAction("RoleIndex", new { employeeid = employeeid }));
 }
        public async Task <bool> DeleteAsync(string requestUri)
        {
            using (HttpClientWrapper client = await this.GetHttpClient())
            {
                this.LogRequest(requestUri);
                HttpResponseMessage response = await client.DeleteAsync(requestUri);

                return(response.StatusCode == HttpStatusCode.NoContent);
            }
        }
示例#6
0
 private async Task DeleteAsync(string endpoint)
 {
     try
     {
         using (HttpClientWrapper client = new HttpClientWrapper(MixItUpAPIEndpoint))
         {
             HttpResponseMessage response = await client.DeleteAsync(endpoint);
         }
     }
     catch (Exception) { }
 }
        private async Task DeleteAsync(string endpoint)
        {
            try
            {
                using (HttpClientWrapper client = new HttpClientWrapper(MixItUpAPIEndpoint))
                {
                    HttpResponseMessage response = await client.DeleteAsync(endpoint);

                    await this.ProcessResponseIfError(response);
                }
            }
            catch (Exception ex) { Logger.Log(ex); }
        }
示例#8
0
        public ActionResult RoleDeleteConfirmed(Guid businessid, Guid id)
        {
            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                var responseMessage = httpClient.DeleteAsync("api/BusinessAPI/Business/" + businessid.ToString() + "/Role/" + id.ToString()).Result;
                responseMessage.EnsureSuccessStatusCode();
            }

            //Invalidate dependant cache item
            CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + businessid.ToString());

            return(RedirectToAction("RoleIndex", new { businessid = businessid }));
        }
示例#9
0
        public async Task DeleteById(string path, string id, string token = null)
        {
            _loggerWrapper.LogInformation("path: " + path + " " + "id: " + id, this.GetType().Name, nameof(DeleteById) + "()", null);

            try
            {
                await HttpClientWrapper.DeleteAsync(path, id, token);
            }
            catch (HttwrapException httwrapException)
            {
                _loggerWrapper.LogError("Failed to find item with ID: " + id, this.GetType().Name, nameof(DeleteById) + "()", null);
                _loggerWrapper.LogError(httwrapException.Message, this.GetType().Name, nameof(DeleteById) + "()", null);
                _loggerWrapper.LogError(httwrapException.InnerException != null ? httwrapException.InnerException.Message : null, this.GetType().Name, nameof(DeleteById) + "()", null);

                throw new HttwrapException("Failed to find item with ID: " + id, httwrapException);
            }
        }
示例#10
0
        public ActionResult DeleteConfirmed(Guid businesslocationId, Guid id)
        {
            //Get roles for business
            BusinessController bc = new BusinessController();
            var busLoc            = bc.GetBusinessLocation(businesslocationId, this.Session);


            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                var responseMessage = httpClient.DeleteAsync("api/ShiftBlockAPI/" + id.ToString()).Result;
                responseMessage.EnsureSuccessStatusCode();

                CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS_LOCATION + busLoc.Id.ToString()); //Remove the stale business item from the cache
                CacheManager.Instance.Remove(CacheManager.CACHE_KEY_BUSINESS + busLoc.BusinessId.ToString());  //Remove the stale business item from the cache
            }
            return(RedirectToAction("Index", new { businesslocationid = businesslocationId }));
        }
示例#11
0
        /// <summary>
        /// Performs a DELETE REST request using the provided request URI.
        /// </summary>
        /// <param name="requestUri">The request URI to use</param>
        /// <returns>Whether the deletion was successful</returns>
        public async Task <bool> DeleteAsync(string requestUri, HttpContent content = null)
        {
            using (HttpClientWrapper client = await this.GetHttpClient())
            {
                this.LogRequest(requestUri);
                if (content != null)
                {
                    HttpMethod         method  = new HttpMethod("DELETE");
                    HttpRequestMessage request = new HttpRequestMessage(method, requestUri)
                    {
                        Content = content
                    };
                    HttpResponseMessage response = await client.SendAsync(request);

                    return(response.StatusCode == HttpStatusCode.NoContent);
                }
                else
                {
                    HttpResponseMessage response = await client.DeleteAsync(requestUri);

                    return(response.StatusCode == HttpStatusCode.NoContent);
                }
            }
        }
 public async Task DeleteAsync(int id, IPrincipal principal)
 {
     await _httpClient.DeleteAsync($"governor/{id}", null, principal);
 }
示例#13
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            await _clientWrapper.DeleteAsync($"api/Employees/{id}");

            return(RedirectToAction("Index"));
        }