public async Task <List <string> > GetPermissionDataAsync(string oId) { List <string> permissionPaths = new List <string>(); UserProfile userProfile = await dbUserProfile.GetUserProfileDataAsync(oId); if (userProfile?.RoleInformationId.Count() > 0) { var roleIdsList = userProfile.RoleInformationId.Select(x => x.ToString()).ToList().Distinct(); var permissionData = await dbClient.FindItemsWhereInClauseAsync(dbSettings.RolesCollectionId, Constants.Id, roleIdsList); List <Role> userRole = JsonUtilities.DeserializeDynamicObject <List <Role> >(permissionData); return(userRole.SelectMany(x => x.Permissions).Distinct().ToList()); } return(permissionPaths); }
public void UpdatePlanToProfileValidate(Guid planId, string oId, PersonalizedPlanViewModel personalizedPlan) { //arrange var profileResponse = userProfileBusinessLogic.GetUserProfileDataAsync(oId); profileResponse.ReturnsForAnyArgs(ShareTestData.UserProfileWithoutPlanId); var dbResponse = dbService.GetItemAsync <PersonalizedPlanViewModel>(personalizedPlan.PersonalizedPlanId.ToString(), dbSettings.ActionPlansCollectionId); dbResponse.ReturnsForAnyArgs <PersonalizedPlanViewModel>(personalizedPlan); var response1 = personalizedPlanBusinessLogic.GetPersonalizedPlanAsync(personalizedPlan.PersonalizedPlanId); Document updatedDocument = new Document(); JsonTextReader reader = new JsonTextReader(new StringReader(ShareTestData.userProfileWithSharedResource)); updatedDocument.LoadFrom(reader); dbService.UpdateItemAsync <UserProfile>( Arg.Any <string>(), Arg.Any <UserProfile>(), Arg.Any <string>()).ReturnsForAnyArgs <Document>(updatedDocument); dbService.CreateItemAsync <SharedResources>( Arg.Any <SharedResources>(), Arg.Any <string>()).ReturnsForAnyArgs <Document>(updatedDocument); //act dynamic response = personalizedPlanBusinessLogic.UpdatePlanToProfile(planId, oId, personalizedPlan); //assert Assert.Equal("RanToCompletion", response.Status.ToString()); }
public void CheckPermaLinkDataAsyncShouldValidate(ShareInput shareInput, dynamic expectedResult) { dynamic profileResponse = userProfileBusinessLogic.GetUserProfileDataAsync(shareInput.UserId, false).Returns <dynamic>(ShareTestData.UserProfileWithSharedResourceData); var dbResponse = dynamicQueries.FindItemsWhereAsync(dbSettings.UserResourcesCollectionId, "SharedResourceId", "0568B88C-3866-4CCA-97C8-B8E3F3D1FF3C"); dbResponse.ReturnsForAnyArgs(ShareTestData.sharedResourcesData); //act var response = shareBusinessLogic.CheckPermaLinkDataAsync(shareInput); expectedResult = JsonConvert.SerializeObject(expectedResult); var actualResult = JsonConvert.SerializeObject(response.Result); //assert Assert.Equal(expectedResult, actualResult); }
public void GetUserRoleDataAsyncShouldValidate(UserProfile userProfile, JArray roleResponse, dynamic expectedResult) { //arrange dynamic profileResponse = dbUserProfile.GetUserProfileDataAsync(userProfile.OId).Returns <dynamic>(userProfile); var ids = new List <string>() { "guid1" }; var dbResponse = dbClient.FindItemsWhereInClauseAsync(dbSettings.RolesCollectionId, Constants.Id, ids); dbResponse.ReturnsForAnyArgs(roleResponse); //act var response = userRoleBusinessLogic.GetPermissionDataAsync(userProfile.OId); expectedResult = JsonConvert.SerializeObject(expectedResult); var actualResult = JsonConvert.SerializeObject(response.Result); //assert Assert.Equal(expectedResult, actualResult); }
public async Task <ShareViewModel> CheckPermaLinkDataAsync(ShareInput shareInput) { dynamic userSharedResourcesDBData = null; List <SharedResources> userSharedResources = new List <SharedResources>(); if (shareInput.UserId == null || shareInput.Url == null) { return(null); } UserProfile userProfile = await dbUserProfile.GetUserProfileDataAsync(shareInput.UserId); if (userProfile == null) { return(null); } else { if (userProfile?.SharedResourceId != null && userProfile.SharedResourceId != Guid.Empty) { userSharedResourcesDBData = await dbClient.FindItemsWhereAsync(dbSettings.UserResourcesCollectionId, Constants.Id, Convert.ToString(userProfile.SharedResourceId, CultureInfo.InvariantCulture)); } if (userSharedResourcesDBData != null && userSharedResourcesDBData?.Count > 0) { userSharedResources = JsonUtilities.DeserializeDynamicObject <List <SharedResources> >(userSharedResourcesDBData); } else { return(null); } } var resource = userSharedResources[0].SharedResource.FindAll(a => a.Url.OriginalString. Contains(shareInput.Url.OriginalString) && DateTime.Compare(a.ExpirationDate, DateTime.UtcNow) >= 0); return(resource.Count == 0 ? null : new ShareViewModel { PermaLink = GetPermaLink(resource.Select(a => a.PermaLink).First()) }); }
public async Task <IActionResult> GetUserProfileDataAsync(string oid) { oid = Instance.Sanitize(oid); return(Ok(await userProfileBusinessLogic.GetUserProfileDataAsync(oid))); }