public void PerformDelete(HttpListenerContext context, DeleteResource deleteResource, string parameter) { if (_verify != null && !_verify(context.Request)) { WriteError(context.Response, HttpStatusCode.Unauthorized, "Authorization failed"); return; } if (int.TryParse(parameter, out int id)) { if (deleteResource.Invoke(id)) { context.Response.StatusCode = (int)HttpStatusCode.NoContent; context.Response.OutputStream.Close(); } else { WriteError(context.Response, HttpStatusCode.NotFound, "resource with provided id not found"); } } else { WriteError(context.Response, HttpStatusCode.BadRequest, parameter + " unexpected"); } }
public async virtual Task <IActionResult> DeleteAsync(int id) { if (!User.IsAuthorized(ResourceType)) { return(Unauthorized()); } var deleteResourceEvent = new DeleteResource <TResource>(id); var cancelDelete = await _mediator.Send(deleteResourceEvent); if (cancelDelete) { return(Forbid()); } var delete = await _repository.DeleteAsync(id, UserID); if (delete <= 0) { return(BadRequest()); } _logger.LogResourceDeleted(ResourceType, id); var resourceDeletedEvent = new ResourceDeleted <TResource>(id); await _mediator.Publish(resourceDeletedEvent); return(NoContent()); }
public void Execute_GivenGlobalWorkspace_ShouldDeleteTests() { //---------------Set up test pack------------------- var testCatalog = new Mock <ITestCatalog>(); var resourceCatalog = new Mock <IResourceCatalog>(); var workScpace = new Mock <IWorkspace>(); workScpace.Setup(workspace => workspace.ID).Returns(GlobalConstants.ServerWorkspaceID); resourceCatalog.Setup(catalog => catalog.DeleteResource(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <bool>())).Returns(new ResourceCatalogResult() { Message = "Hi", Status = ExecStatus.Success }); const string guid = "7B71D6B8-3E11-4726-A7A0-AC924977D6E5"; DeleteResource resourceService = new DeleteResource(resourceCatalog.Object, testCatalog.Object); //---------------Assert Precondition---------------- Assert.IsNotNull(resourceService); //---------------Execute Test ---------------------- var stringBuilder = resourceService.Execute(new Dictionary <string, StringBuilder> { { "ResourceID", new StringBuilder(guid) }, { "ResourceType", new StringBuilder("NewName") }, }, workScpace.Object); //---------------Test Result ----------------------- testCatalog.Verify(catalog => catalog.DeleteAllTests(guid.ToGuid()), Times.Once); var serializer = new Dev2JsonSerializer(); var executeMessage = serializer.Deserialize <ExecuteMessage>(stringBuilder); Assert.IsFalse(executeMessage.HasError); Assert.IsFalse(string.IsNullOrEmpty(executeMessage.Message.ToString())); }
public virtual void Any(DeleteResource request) { var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsResource, IDataContextNhJars> >(); _repository.Delete(request.Id); TrySendDeleteNotificationToChannel(typeof(JarsResource).Name, new[] { request.Id.ToString() }); }
public void SetUp() { _createResource = new CreateResourceFake(); _deleteFeature = new DeleteResource(); _getResource = new GetResource(); Runner.SqlCompact("Lemonade").Down(); Runner.SqlCompact("Lemonade").Up(); }
private void DeleteResources(DeleteResource deleter, List <uint> list) { lock (list) { for (int i = list.Count - 1; i >= 0; i--) { deleter(list[i]); } list.Clear(); } }
public void GetAuthorizationContextForService_ShouldReturnContext() { //------------Setup for test-------------------------- var service = new DeleteResource(); //------------Execute Test--------------------------- var resId = service.GetAuthorizationContextForService(); //------------Assert Results------------------------- Assert.AreEqual(AuthorizationContext.Contribute, resId); }
public void GetResourceID_ShouldReturnEmptyGuid() { //------------Setup for test-------------------------- var service = new DeleteResource(); //------------Execute Test--------------------------- var resId = service.GetResourceID(new Dictionary <string, StringBuilder>()); //------------Assert Results------------------------- Assert.AreEqual(Guid.Empty, resId); }
public void CreateServiceEntry_GivenServiceIsCreated_ShouldCreateCorrectDynamicService() { //---------------Set up test pack------------------- DeleteResource resourceService = new DeleteResource(); //---------------Assert Precondition---------------- Assert.IsNotNull(resourceService); //---------------Execute Test ---------------------- var handlesType = resourceService.CreateServiceEntry(); //---------------Test Result ----------------------- Assert.AreEqual(1, handlesType.Actions.Count); }
public void HandlesType_GivenServiceIsCreated_ShouldHandleCorrectly() { //---------------Set up test pack------------------- DeleteResource resourceService = new DeleteResource(); //---------------Assert Precondition---------------- Assert.IsNotNull(resourceService); //---------------Execute Test ---------------------- var handlesType = resourceService.HandlesType(); //---------------Test Result ----------------------- Assert.AreEqual("DeleteResourceService", handlesType); }
public override bool OnDeleteData() { try { if (base.OnDeleteData(true)) { JarsResource delObj = defaultBindingSource.Current as JarsResource; var delReq = new DeleteResource { Id = delObj.Id }; ServiceClient.Delete(delReq); defaultBindingSource.RemoveCurrent(); defaultBindingSource.ResetBindings(false); } //call this after the record removal was successful. } catch (Exception exD) { OnExceptionEvent(exD); } return(base.OnDeleteData()); }
public void Execute(object parameter) { DeleteResource dialog = new DeleteResource(resource); }