public void ShareResourceDataAsyncShouldReturnResourceUrl(ShareInput shareInput, int permaLinkOutputLength, dynamic expectedResult)
        {
            dynamic profileResponse = userProfileBusinessLogic.GetUserProfileDataAsync(shareInput.UserId).Returns <dynamic>(ShareTestData.UserProfileWithoutSharedResourceData);

            dbShareSettings.PermaLinkMaxLength.Returns(permaLinkOutputLength);

            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
            var result = shareBusinessLogic.ShareResourceDataAsync(shareInput).Result;

            //assert
            Assert.Equal(expectedResult.PermaLink.Length, result.PermaLink.Length);
        }
        public void UnshareResourceDataAsyncShouldReturnTrue(ShareInput unShareInput, dynamic expectedResult)
        {
            var profileResponse = userProfileBusinessLogic.GetUserProfileDataAsync(unShareInput.UserId);

            profileResponse.ReturnsForAnyArgs(ShareTestData.UserProfileWithSharedResourceData);

            Document       updatedDocument = new Document();
            JsonTextReader reader          = new JsonTextReader(new StringReader(ShareTestData.updatedSharedResourcesData));

            updatedDocument.LoadFrom(reader);

            dbService.UpdateItemAsync <SharedResources>(
                Arg.Any <string>(),
                Arg.Any <SharedResources>(),
                Arg.Any <string>()).ReturnsForAnyArgs <Document>(updatedDocument);
            var dbResponse = dynamicQueries.FindItemsWhereAsync(dbSettings.UserResourcesCollectionId, "SharedResourceId", "0568B88C-3866-4CCA-97C8-B8E3F3D1FF3C");

            dbResponse.ReturnsForAnyArgs(ShareTestData.sharedResourcesData);

            //act
            var result = shareBusinessLogic.UnshareResourceDataAsync(unShareInput).Result;

            expectedResult = JsonConvert.SerializeObject(expectedResult);
            var actualResult = JsonConvert.SerializeObject(result);

            //assert
            Assert.Equal(expectedResult, actualResult);
        }
Пример #3
0
        public async Task <IActionResult> CheckDataAsync([FromBody] ShareInput shareInput)
        {
            if (shareInput != null)
            {
                var response = await shareBusinessLogic.CheckPermaLinkDataAsync(shareInput);

                return(Ok(response));
            }
            return(StatusCode(StatusCodes.Status412PreconditionFailed));
        }
        public void CheckPermaLinkDataAsyncShouldValidateNull(ShareInput shareInput, dynamic expectedResult)
        {
            shareInput.UserId = null;
            shareInput.Url    = null;
            //act
            var response = shareBusinessLogic.CheckPermaLinkDataAsync(shareInput);

            expectedResult = JsonConvert.SerializeObject(null);
            var actualResult = JsonConvert.SerializeObject(response.Result);

            //assert
            Assert.Contains(expectedResult, actualResult);
        }
Пример #5
0
        public async Task <IActionResult> UnshareAsync([FromBody] ShareInput unShareInput)
        {
            if (unShareInput != null)
            {
                var response = await shareBusinessLogic.UnshareResourceDataAsync(unShareInput);

                if (response == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
                return(Ok(response));
            }
            return(StatusCode(StatusCodes.Status412PreconditionFailed));
        }
        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);
        }
Пример #7
0
        public async Task <object> UnshareResourceDataAsync(ShareInput unShareInput)
        {
            dynamic userSharedResourcesDBData = null;
            var     userSharedResources       = new List <SharedResources>();

            if (unShareInput.UserId == null || unShareInput.ResourceId == null || unShareInput.Url == null)
            {
                return(null);
            }
            UserProfile userProfile = await dbUserProfile.GetUserProfileDataAsync(unShareInput.UserId);

            if (userProfile == null || userProfile?.SharedResourceId == null)
            {
                return(null);
            }
            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)
            {
                userSharedResources = JsonUtilities.DeserializeDynamicObject <List <SharedResources> >(userSharedResourcesDBData);
            }
            var sharedResource = userSharedResources[0].SharedResource.FindAll(a => a.Url.OriginalString.
                                                                               Contains(unShareInput.Url.OriginalString));

            if (sharedResource.Count == 0)
            {
                return(false);
            }
            userSharedResources[0].SharedResource.RemoveAll(a => a.Url.OriginalString.
                                                            Contains(unShareInput.Url.OriginalString));
            var response = await dbService.UpdateItemAsync(userSharedResources[0].SharedResourceId.ToString(), userSharedResources[0],
                                                           dbSettings.UserResourcesCollectionId);

            if (unShareInput.Url.OriginalString.Contains("plan"))
            {
                string planId = unShareInput.Url.OriginalString.Substring(6);
                await UpdatePlanIsSharedStatus(planId, false);
            }
            return(response == null ? false : true);
        }
Пример #8
0
        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())
            });
        }
Пример #9
0
        public async Task <ShareViewModel> ShareResourceDataAsync(ShareInput shareInput)
        {
            dynamic response = null;

            if (shareInput.Url == null || shareInput.UserId == null || shareInput.ResourceId == null)
            {
                return(null);
            }
            UserProfile userProfile = await dbUserProfile.GetUserProfileDataAsync(shareInput.UserId);

            shareInput.UniqueId   = shareInput.UniqueId != Guid.Empty ? shareInput.UniqueId : Guid.NewGuid();
            shareInput.ResourceId = shareInput.ResourceId != Guid.Empty ? shareInput.ResourceId : Guid.NewGuid();

            var permaLink = EncryptionUtilities.GenerateSHA256String(shareInput.UniqueId + shareInput.UserId +
                                                                     shareInput.ResourceId);
            var sharedResource = new SharedResource
            {
                ExpirationDate = DateTime.UtcNow.AddYears(Constants.ExpirationDateDurationInYears),
                IsShared       = true,
                Url            = new Uri(shareInput.Url.OriginalString, UriKind.RelativeOrAbsolute),
                PermaLink      = permaLink
            };

            response = await UpsertSharedResource(userProfile, sharedResource);

            if (shareInput.Url.OriginalString.Contains("plan"))
            {
                string planId = shareInput.Url.OriginalString.Substring(6);
                await UpdatePlanIsSharedStatus(planId, true);
            }

            return(response == null ? null : new ShareViewModel
            {
                PermaLink = dbShareSettings.PermaLinkMaxLength > 0 ? GetPermaLink(permaLink) : permaLink
            });
        }