public async Task When_Passing_Null_Parameter_Then_Exception_Is_Thrown() { // ARRANGE Initialize(); // ACTS & ASSERTS await Assert.ThrowsAsync <ArgumentNullException>(() => _addRepresentationAction.Execute(null, string.Empty, string.Empty, string.Empty, string.Empty)); await Assert.ThrowsAsync <ArgumentNullException>(() => _addRepresentationAction.Execute(new JObject(), string.Empty, string.Empty, string.Empty, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => _addRepresentationAction.Execute(new JObject(), string.Empty, null, string.Empty, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => _addRepresentationAction.Execute(new JObject(), string.Empty, "schemaid", string.Empty, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => _addRepresentationAction.Execute(new JObject(), string.Empty, "schemaid", null, null)); await Assert.ThrowsAsync <ArgumentNullException>(() => _addRepresentationAction.Execute(new JObject(), string.Empty, "schemaid", "resourcetype", string.Empty)); await Assert.ThrowsAsync <ArgumentNullException>(() => _addRepresentationAction.Execute(new JObject(), string.Empty, "schemaid", "resourcetype", null)); }
public async Task <ApiActionResult> AddUser(JObject jObj, string locationPattern) { var processId = Guid.NewGuid().ToString(); try { _eventPublisher.Publish(new AddUserReceived(Guid.NewGuid().ToString(), processId, jObj.ToString(), 0)); var result = await _addRepresentationAction.Execute(jObj, locationPattern, Common.Constants.SchemaUrns.User, Common.Constants.ResourceTypes.User); _eventPublisher.Publish(new AddUserFinished(Guid.NewGuid().ToString(), processId, JsonConvert.SerializeObject(result).ToString(), 1)); return(result); } catch (Exception ex) { _eventPublisher.Publish(new ScimErrorReceived(Guid.NewGuid().ToString(), processId, ex.Message, 1)); throw; } }
public Task <ApiActionResult> AddUser(JObject jObj, string locationPattern) { return(_addRepresentationAction.Execute(jObj, locationPattern, Common.Constants.SchemaUrns.User, Common.Constants.ResourceTypes.User)); }
public async Task <ApiActionResult> Execute(JObject jObj, string baseUrl) { // 1. Check parameter. if (jObj == null) { throw new ArgumentNullException(nameof(jObj)); } // 2. Parse the request. var bulk = await _bulkRequestParser.Parse(jObj, baseUrl); if (!bulk.IsParsed) { return(_apiResponseFactory.CreateError(HttpStatusCode.InternalServerError, bulk.ErrorResponse)); } // 3. Execute bulk operation. var numberOfErrors = 0; var operationsResult = new JArray(); foreach (var operation in bulk.BulkResult.Operations) { ApiActionResult operationResult = null; if (operation.Method == HttpMethod.Post) { operationResult = await _addRepresentationAction.Execute(operation.Data, operation.LocationPattern, operation.SchemaId, operation.ResourceType); } else if (operation.Method == HttpMethod.Put) { operationResult = await _updateRepresentationAction.Execute(operation.ResourceId, operation.Data, operation.SchemaId, operation.LocationPattern, operation.ResourceType); } else if (operation.Method == HttpMethod.Delete) { operationResult = await _deleteRepresentationAction.Execute(operation.ResourceId); } else if (operation.Method.Method == "PATCH") { operationResult = await _patchRepresentationAction.Execute(operation.ResourceId, operation.Data, operation.SchemaId, operation.LocationPattern); } // 3.2. If maximum number of errors has been reached then return an error. if (!operationResult.IsSucceed()) { numberOfErrors++; if (bulk.BulkResult.FailOnErrors.HasValue && numberOfErrors > bulk.BulkResult.FailOnErrors) { return(_apiResponseFactory.CreateError(HttpStatusCode.InternalServerError, _errorResponseFactory.CreateError( string.Format(ErrorMessages.TheMaximumNumberOfErrorHasBeenReached, bulk.BulkResult.FailOnErrors), HttpStatusCode.InternalServerError, Common.Constants.ScimTypeValues.TooMany))); } } operationsResult.Add(CreateOperationResponse(operationResult, operation)); } var response = CreateResponse(operationsResult); return(_apiResponseFactory.CreateResultWithContent(HttpStatusCode.OK, response)); }