コード例 #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;
        }