public static async Task <LabResponse> GetLabUserDataAsync(UserQuery query)
        {
            if (s_userCache.ContainsKey(query))
            {
                Debug.WriteLine("User cache hit");
                return(s_userCache[query]);
            }

            var user = await s_labService.GetLabResponseAsync(query).ConfigureAwait(false);

            if (user == null)
            {
                throw new LabUserNotFoundException(query, "Found no users for the given query.");
            }

            Debug.WriteLine("User cache miss");
            s_userCache.Add(query, user);

            return(user);
        }
Beispiel #2
0
        private LabResponse GetLabResponseFromApi(UserQuery query)
        {
            //Fetch user
            string result = RunQuery(query);

            if (string.IsNullOrWhiteSpace(result))
            {
                throw new LabUserNotFoundException(query, "No lab user with specified parameters exists");
            }

            LabResponse response = JsonConvert.DeserializeObject <LabResponse>(result);
            LabUser     user     = JsonConvert.DeserializeObject <LabUser>(result);

            if (!string.IsNullOrEmpty(user.HomeTenantId) && !string.IsNullOrEmpty(user.HomeUPN))
            {
                user.InitializeHomeUser();
            }

            return(response);
        }
Beispiel #3
0
        public static LabResponse GetLabUserData(UserQuery query)
        {
            if (s_userCache.ContainsKey(query))
            {
                Debug.WriteLine("User cache hit");
                return(s_userCache[query]);
            }

            var user = s_labService.GetLabResponse(query);

            if (user == null)
            {
                throw new LabUserNotFoundException(query, "Found no users for the given query.");
            }

            Debug.WriteLine("User cache miss");
            s_userCache.Add(query, user);

            return(user);
        }
        public static async Task <LabResponse> GetLabUserDataAsync(UserQuery query)
        {
            if (s_userCache.ContainsKey(query))
            {
                Trace.WriteLine("Lab user cache hit. Selected user: "******"Found no users for the given query.");
            }

            s_userCache.Add(query, response);
            Debug.WriteLine("User cache miss. Returning user from lab: " + response.User.Upn);

            return(response);
        }
Beispiel #5
0
 public LabUserNotFoundException(UserQuery parameters, string message) : base(message)
 {
     Parameters = parameters;
 }
Beispiel #6
0
        /// <summary>
        /// Returns a test user account for use in testing.
        /// </summary>
        /// <param name="query">Any and all parameters that the returned user should satisfy.</param>
        /// <returns>Users that match the given query parameters.</returns>
        public async Task <LabResponse> GetLabResponseAsync(UserQuery query)
        {
            var response = await GetLabResponseFromApiAsync(query).ConfigureAwait(false);

            return(response);
        }
        public static Task <LabResponse> GetSpecificUserAsync(string upn)
        {
            var query = new UserQuery();

            return(GetLabUserDataAsync(query));
        }
        private Task <string> RunQueryAsync(UserQuery query)
        {
            IDictionary <string, string> queryDict = new Dictionary <string, string>();

            //Disabled for now until there are tests that use it.
            queryDict.Add(LabApiConstants.MobileAppManagementWithConditionalAccess, LabApiConstants.False);
            queryDict.Add(LabApiConstants.MobileDeviceManagementWithConditionalAccess, LabApiConstants.False);
            bool queryRequiresBetaEndpoint = false;

            //Building user query
            if (!string.IsNullOrWhiteSpace(query.Upn))
            {
                queryDict.Add(LabApiConstants.Upn, query.Upn);
                return(SendLabRequestAsync(LabApiConstants.LabEndpoint, queryDict));
            }

            if (query.FederationProvider != null)
            {
                if (query.FederationProvider == FederationProvider.ADFSv2019)
                {
                    queryRequiresBetaEndpoint = true;
                }
                queryDict.Add(LabApiConstants.FederationProvider, query.FederationProvider.ToString());
            }

            if (!string.IsNullOrWhiteSpace(query.Upn))
            {
                queryDict.Add(LabApiConstants.Upn, query.Upn);
            }

            queryDict.Add(LabApiConstants.MobileAppManagement, query.IsMamUser != null && (bool)(query.IsMamUser) ? LabApiConstants.True : LabApiConstants.False);
            queryDict.Add(LabApiConstants.MultiFactorAuthentication, query.IsMfaUser != null && (bool)(query.IsMfaUser) ? LabApiConstants.True : LabApiConstants.False);

            if (query.Licenses != null && query.Licenses.Count > 0)
            {
                queryDict.Add(LabApiConstants.License, query.Licenses.ToArray().ToString());
            }

            queryDict.Add(LabApiConstants.FederatedUser, query.IsFederatedUser != null && (bool)(query.IsFederatedUser) ? LabApiConstants.True : LabApiConstants.False);

            if (query.UserType != null)
            {
                queryDict.Add(LabApiConstants.UserType, query.UserType.ToString());
            }

            queryDict.Add(LabApiConstants.External, query.IsExternalUser != null && (bool)(query.IsExternalUser) ? LabApiConstants.True : LabApiConstants.False);

            if (query.B2CIdentityProvider == B2CIdentityProvider.Local)
            {
                queryDict.Add(LabApiConstants.B2CProvider, LabApiConstants.B2CLocal);
            }

            if (query.B2CIdentityProvider == B2CIdentityProvider.Facebook)
            {
                queryDict.Add(LabApiConstants.B2CProvider, LabApiConstants.B2CFacebook);
            }

            if (query.B2CIdentityProvider == B2CIdentityProvider.Google)
            {
                queryDict.Add(LabApiConstants.B2CProvider, LabApiConstants.B2CGoogle);
            }

            if (query.B2CIdentityProvider == B2CIdentityProvider.MSA)
            {
                queryDict.Add(LabApiConstants.B2CProvider, LabApiConstants.B2CMSA);
            }

            if (!string.IsNullOrEmpty(query.UserSearch))
            {
                queryDict.Add(LabApiConstants.UserContains, query.UserSearch);
            }

            return(SendLabRequestAsync(queryRequiresBetaEndpoint ? LabApiConstants.BetaEndpoint : LabApiConstants.LabEndpoint, queryDict));
        }