Beispiel #1
0
        public async Task <ApiActionResult> UpdateUser(string id, JObject jObj, string locationPattern)
        {
            var processId = Guid.NewGuid().ToString();

            try
            {
                _eventPublisher.Publish(new UpdateUserReceived(Guid.NewGuid().ToString(), processId, jObj.ToString(), 0));
                var result = await _updateRepresentationAction.Execute(id, jObj, Common.Constants.SchemaUrns.User, locationPattern, Common.Constants.ResourceTypes.User);

                _eventPublisher.Publish(new UpdateUserFinished(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;
            }
        }
Beispiel #2
0
        public async Task When_Passing_Null_Or_Empty_Parameters_Then_Exceptions_Are_Thrown()
        {
            // ARRANGE
            InitializeFakeObjects();

            // ACTS & ASSERTS
            await Assert.ThrowsAsync <ArgumentNullException>(() => _updateRepresentationAction.Execute(null, null, null, "http://localhost/{id}", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => _updateRepresentationAction.Execute(string.Empty, null, null, "http://localhost/{id}", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => _updateRepresentationAction.Execute("representation_id", null, null, "http://localhost/{id}", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => _updateRepresentationAction.Execute("representation_id", new JObject(), null, "http://localhost/{id}", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => _updateRepresentationAction.Execute("representation_id", new JObject(), string.Empty, "http://localhost/{id}", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => _updateRepresentationAction.Execute("representation_id", new JObject(), "schema_id", "http://localhost/{id}", null));

            await Assert.ThrowsAsync <ArgumentNullException>(() => _updateRepresentationAction.Execute("representation_id", new JObject(), "schema_id", "http://localhost/{id}", string.Empty));
        }
 public Task <ApiActionResult> UpdateUser(string id, JObject jObj, string locationPattern)
 {
     return(_updateRepresentationAction.Execute(id, jObj, Common.Constants.SchemaUrns.User, locationPattern, 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));
        }