コード例 #1
0
        public static int SetUpRemoteAppUserToAdd(Mock<IRemoteAppManagementClient> clientMock, string collectionName, PrincipalProviderType userIdType, string[] userNames)
        {
            SecurityPrincipalOperationsResult response = new SecurityPrincipalOperationsResult()
            {
                RequestId = "122-13342",
                TrackingId = "2334-323456",
                StatusCode = System.Net.HttpStatusCode.Accepted,
                Errors = null,
            };

            mockSecurityPrincipalResult = new List<SecurityPrincipalOperationsResult>()
            {
                new SecurityPrincipalOperationsResult()
                {
                    RequestId = response.RequestId,
                    TrackingId = response.TrackingId,
                    StatusCode = response.StatusCode,
                    Errors = response.Errors
                },
            };

            SecurityPrincipalList spAdd = new SecurityPrincipalList();

            foreach (string userName in userNames)
            {
                SecurityPrincipal mockUser = new SecurityPrincipal()
                {
                    Name = userName,
                    SecurityPrincipalType = PrincipalType.User,
                    UserIdType = userIdType,
                };
                spAdd.SecurityPrincipals.Add(mockUser);
            }

            ISetup<IRemoteAppManagementClient, Task<SecurityPrincipalOperationsResult>> setup = clientMock.Setup(c => c.Principals.AddAsync(collectionName, It.IsAny<SecurityPrincipalList>(), It.IsAny<CancellationToken>()));
            setup.Returns(Task.Factory.StartNew(() => response));

            mockUsers = spAdd.SecurityPrincipals;

            return mockUsers.Count;
        }
コード例 #2
0
        public static bool ContainsExpectedStatus(List<SecurityPrincipalOperationsResult> expectedResult, SecurityPrincipalOperationsResult operationResult)
        {
            bool isIdentical = false;
            foreach (SecurityPrincipalOperationsResult expected in expectedResult)
            {
                isIdentical = expected.RequestId == operationResult.RequestId;
                isIdentical &= expected.StatusCode == operationResult.StatusCode;
                isIdentical &= expected.TrackingId == operationResult.TrackingId;

                if (expected.Errors != null && operationResult.Errors != null)
                {
                    if (expected.Errors.Count == operationResult.Errors.Count)
                    {
                        isIdentical &= ContainsExpectedServicePrincipalErrorDetails(expected.Errors, operationResult.Errors);
                    }
                    else
                    {
                        isIdentical = false;
                    }
                }
                else if (expected.Errors == null && operationResult.Errors != null)
                {
                    isIdentical = false;
                }
                else if (expected.Errors != null && operationResult.Errors == null)
                {
                    isIdentical = false;
                }

                if (isIdentical)
                {
                    break;
                }
            }

            return isIdentical;
        }
コード例 #3
0
        protected void ProcessResult( SecurityPrincipalOperationsResult result, string collectionName, Operation operation)
        {
            ErrorRecord er = null;
            ErrorCategory category = ErrorCategory.NotImplemented;
            String errorMessageFormat = String.Empty;

            if (result.Errors != null)
            {
                switch (operation)
                {
                    case Operation.Add:
                        errorMessageFormat = "Could not add {0} to collection {1} because of error: {2} [{3}].";
                        break;
                    case Operation.Remove:
                        errorMessageFormat = "Could not remove {0} from collection {1} because of error: {2} [{3}].";
                        break;
                    default:
                        errorMessageFormat = "Unknown error.";
                        break;
                }

                foreach (SecurityPrincipalOperationErrorDetails errorDetails in result.Errors)
                {

                    switch (errorDetails.Error)
                    {
                        case SecurityPrincipalOperationError.NotSupported:
                        case SecurityPrincipalOperationError.AlreadyExists:
                        case SecurityPrincipalOperationError.AssignedToAnotherCollection:
                            {
                                category = ErrorCategory.InvalidOperation;
                                break;
                            }

                        case SecurityPrincipalOperationError.NotFound:
                        case SecurityPrincipalOperationError.CouldNotBeResolved:
                        case SecurityPrincipalOperationError.NotDirsynced:
                            {
                                category = ErrorCategory.ObjectNotFound;
                                break;
                            }
                    }

                    er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                        String.Format(errorMessageFormat,
                            errorDetails.SecurityPrincipal,
                            collectionName,
                            errorDetails.Error.ToString(),
                            errorDetails.ErrorDetails
                            ),
                        String.Empty,
                        Client.Principals,
                        category
                    );

                    WriteError(er);
                }
            }
            else
            {
                WriteObject(result);
            }
        }