public async Task TestUpdateUser() { Func <ProviderBase, Task> testFunction = new Func <ProviderBase, Task>( async(ProviderBase provider) => { PatchRequest2Legacy patchRequest = SampleComposer.Instance.ComposeUserPatch(); string correlationIdentifierCreate = Guid.NewGuid().ToString(); Resource inputResource = SampleComposer.Instance.ComposeUserResource(); Resource outputResource = await provider.CreateAsync(inputResource, correlationIdentifierCreate); Assert.IsNotNull(outputResource); Assert.IsFalse(string.IsNullOrWhiteSpace(outputResource.Identifier)); IResourceIdentifier resourceIdentifier = new ResourceIdentifier() { SchemaIdentifier = SchemaIdentifiers.Core2EnterpriseUser, Identifier = outputResource.Identifier }; IPatch patch = new Patch() { ResourceIdentifier = resourceIdentifier, PatchRequest = patchRequest }; string correlationIdentifierUpdate = Guid.NewGuid().ToString(); await provider.UpdateAsync(patch, correlationIdentifierUpdate); }); await this.RunTest(testFunction); }
public PatchRequest2Legacy ComposeReferencePatch( string referenceAttributeName, string referencedObjectUniqueIdentifier, OperationName operationName) { Assert.IsFalse(string.IsNullOrWhiteSpace(referenceAttributeName)); Assert.IsFalse(string.IsNullOrWhiteSpace(referencedObjectUniqueIdentifier)); IPath path; Assert.IsTrue(Path.TryParse(referenceAttributeName, out path)); OperationValue operationValue = new OperationValue() { Value = referencedObjectUniqueIdentifier }; PatchOperation2 operation = new PatchOperation2() { Name = operationName, Path = path }; operation.AddValue(operationValue); PatchRequest2Legacy result = new PatchRequest2Legacy(); result.AddOperation(operation); return(result); }
public PatchRequest2Legacy ComposeUserPatch() { string value = Guid.NewGuid().ToString(SampleComposer.FormatUniqueIdentifierCompressed); IPath path; PatchOperation2 operation; OperationValue operationValue; PatchRequest2Legacy result = new PatchRequest2Legacy(); Assert.IsTrue(Path.TryParse(AttributeNames.Active, out path)); operationValue = new OperationValue() { Value = bool.FalseString }; operation = new PatchOperation2() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); Assert.IsTrue(Path.TryParse(AttributeNames.DisplayName, out path)); operationValue = new OperationValue() { Value = value }; operation = new PatchOperation2() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); Assert.IsTrue(Path.TryParse(SampleComposer.PathExpressionPrimaryWorkElectronicMailAddress, out path)); string electronicMailAddressValue = string.Format( CultureInfo.InvariantCulture, SampleComposer.ElectronicMailAddressTemplate, value); operationValue = new OperationValue() { Value = electronicMailAddressValue }; operation = new PatchOperation2() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); Assert.IsTrue(Path.TryParse(SampleComposer.PathExpressionPostalCode, out path)); operationValue = new OperationValue() { Value = value }; operation = new PatchOperation2() { Name = OperationName.Replace, Path = path }; operation.AddValue(operationValue); result.AddOperation(operation); return(result); }
private async Task UpdateMembersAsync(Resource resource, IPatch patch) { if (null == resource) { throw new ArgumentNullException(nameof(resource)); } if (null == patch) { throw new ArgumentNullException(nameof(patch)); } if (null == patch.ResourceIdentifier) { throw new ArgumentException(FileProviderResources.ExceptionInvalidPatch); } if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidPatch); } if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.SchemaIdentifier)) { throw new ArgumentException(FileProviderResources.ExceptionInvalidPatch); } if (null == patch.PatchRequest) { throw new ArgumentException(FileProviderResources.ExceptionInvalidPatch); } PatchRequest2Legacy patchRequest = patch.PatchRequest as PatchRequest2Legacy; if (null == patchRequest) { string unsupportedPatchTypeName = patch.GetType().FullName; throw new NotSupportedException(unsupportedPatchTypeName); } if ( !FileProvider .SchemaIdentifiersGroup .Value .Any( (string item) => string.Equals(item, patch.ResourceIdentifier.SchemaIdentifier, StringComparison.Ordinal)) ) { return; } IReadOnlyCollection <PatchOperation2> memberOperations = patchRequest .Operations .Where( (PatchOperation2 item) => item.Path != null && string.Equals(item.Path.AttributePath, AttributeNames.Members, StringComparison.Ordinal)) .ToArray(); if (!memberOperations.Any()) { return; } foreach (PatchOperation2 memberOperation in memberOperations) { if (null == memberOperation.Value) { continue; } foreach (OperationValue value in memberOperation.Value) { if (string.IsNullOrWhiteSpace(value.Value)) { continue; } Dictionary <string, string> columnsQuery = new Dictionary <string, string>() { { AttributeNames.Schemas, patch.ResourceIdentifier.SchemaIdentifier }, { AttributeNames.Identifier, patch.ResourceIdentifier.Identifier }, { AttributeNames.Members, value.Value } }; IRow[] rows = await this.file.Query(columnsQuery); switch (memberOperation.Name) { case OperationName.Add: if (rows.Any()) { break; } Member member = new Member() { Value = value.Value }; MemberColumnsFactory memberColumnsFactory = new MemberColumnsFactory(resource, member); IReadOnlyDictionary <string, string> columnsMember = memberColumnsFactory.CreateColumns(); await this.file.InsertRow(columnsMember); break; case OperationName.Remove: foreach (IRow row in rows) { await this.file.RemoveRow(row.Key); } break; } } } }