public async Task <dynamic> GetUserProfileDataAsync(string oId, bool isProfileViewModel = false)
        {
            var resultUserData = await dbClient.FindItemsWhereAsync(dbSettings.ProfilesCollectionId, Constants.OId, oId);

            if (isProfileViewModel)
            {
                return(ConvertUserProfileViewModel(resultUserData));
            }
            return(ConvertUserProfile(resultUserData));
        }
Пример #2
0
        public void FindItemsWhereShouldConstructValidSqlQuery()
        {
            // Arrange
            string query = @"SELECT * FROM c WHERE c.name='eviction'";

            // Act
            var result = dynamicQueries.FindItemsWhereAsync("topicsCollections", "name", "eviction").Result;

            // Assert
            cosmosDbService.Received().QueryItemsAsync(Arg.Any <string>(), query);
        }
        public void GetServiceProviderAsyncTestsShouldReturnProperData(string serviceProviderId, JArray serviceProviderData, dynamic expectedServiceProviderdata)
        {
            //arrange
            var dbResponse = dynamicQueries.FindItemsWhereAsync(cosmosDbSettings.ResourcesCollectionId, Constants.Id, serviceProviderId);

            dbResponse.ReturnsForAnyArgs(serviceProviderData);

            //act
            var response = serviceProvidersBusinessLogic.GetServiceProviderDocumentAsync(serviceProviderId);

            //assert
            Assert.Equal(expectedServiceProviderdata.ToString(), response.Result.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 async Task <List <StateCode> > GetStateCodes()
        {
            var stateProvinceDetails = await dbClient.FindItemsWhereAsync(dbSettings.StateProvincesCollectionId, Constants.Type, Constants.StateProvinceType);

            List <StateProvinceViewModel> stateProvince = JsonUtilities.DeserializeDynamicObject <List <StateProvinceViewModel> >(stateProvinceDetails);

            return(stateProvince.Count() > 0 ? stateProvince[0].StateProvinces : null);
        }
Пример #6
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())
            });
        }
Пример #7
0
        public void GetStateCodesShouldValidate(JArray stateProvinceViewModel, dynamic expectedResult)
        {
            var dbResponse = dbClient.FindItemsWhereAsync(dbSettings.StateProvincesCollectionId, Constants.Type, Constants.StateProvinceType);

            dbResponse.ReturnsForAnyArgs(stateProvinceViewModel);

            //act
            var response = stateProvinceBusinessLogic.GetStateCodes();

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

            //assert
            Assert.Equal(expectedResult, actualResult);
        }
        public void GetUserProfileDataAsyncShouldReturnEmptyData()
        {
            //arrange
            var dbResponse = dynamicQueries.FindItemsWhereAsync(cosmosDbSettings.ProfilesCollectionId, "oId", expectedUserProfileId);

            dbResponse.ReturnsForAnyArgs <dynamic>(emptyData);

            //act
            var    response = userProfileBusinessLogic.GetUserProfileDataAsync(expectedUserProfileId);
            string result   = JsonConvert.SerializeObject(response);

            //assert
            Assert.DoesNotContain(expectedUserProfileId, result, StringComparison.InvariantCultureIgnoreCase);
        }
Пример #9
0
 public void FindItemsWhereShouldFailWhenParametersAreNullOrEmpty(string collection, string property)
 {
     Assert.ThrowsAny <Exception>(() => dynamicQueries.FindItemsWhereAsync(collection, property, Arg.Any <string>()).Result);
 }
        public async Task <Topic> GetTopic(string topicName)
        {
            List <dynamic> topics = await dbClient.FindItemsWhereAsync(dbSettings.TopicsCollectionId, Constants.Name, topicName);

            if (!topics.Any())
            {
                throw new Exception($"No topic found with this name: {topicName}");
            }

            return(JsonUtilities.DeserializeDynamicObject <Topic>(topics.FirstOrDefault()));
        }
Пример #11
0
 /// <summary>
 /// returns service provider based on id
 /// </summary>
 public async Task <dynamic> GetServiceProviderDocumentAsync(string id)
 {
     return(await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, Constants.Id, id).ConfigureAwait(false));
 }