public void UpsertPersonalizedPlanAsyncValidate(UserPlan userPlan)
        {
            //arrange
            dynamic        expectedResult;
            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 = personalizedPlanBusinessLogic.UpsertPersonalizedPlanAsync(userPlan).Result;

            expectedResult = null;

            //assert
            Assert.Equal(expectedResult, result);
        }
示例#2
0
        public async Task <Document> ImportA2JTemplate(JObject mainTemplate, Guid newTemplateId)
        {
            mainTemplate.AddFirst(new JProperty(Constants.Id, newTemplateId));

            return(await backendDatabaseService.CreateItemAsync(mainTemplate,
                                                                cosmosDbSettings.A2JAuthorDocsCollectionId));
        }
        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 async Task <dynamic> CreateUserSavedResourcesAsync(ProfileResources userResources)
        {
            var userDocument = new UserSavedResources()
            {
                SavedResourcesId = Guid.NewGuid(),
                Resources        = BuildResources(userResources)
            };

            userDocument = JsonConvert.DeserializeObject <UserSavedResources>(JsonConvert.SerializeObject(userDocument));
            return(await dbService.CreateItemAsync((userDocument), dbSettings.UserResourcesCollectionId));
        }
示例#5
0
        public CuratedExperience ConvertA2JAuthorToCuratedExperience(JObject a2jSchema, bool isFromAdminImport = false)
        {
            var             curatedExperience = new CuratedExperience();
            var             a2jProperties     = a2jSchema.Properties();
            GuidedAssistant resource          = null;

            curatedExperience.CuratedExperienceId = Guid.NewGuid();
            curatedExperience.Title = a2jProperties.GetValue("title");

            if (!isFromAdminImport)
            {
                resource = MapResourceProperties(a2jProperties, curatedExperience.CuratedExperienceId);
                dbService.CreateItemAsync(resource, dbSettings.ResourcesCollectionId);
            }

            var pages = ((JObject)a2jProperties.Where(x => x.Name == "pages").FirstOrDefault()?.Value).Properties();

            foreach (var page in pages)
            {
                var pageProperties   = ((JObject)page.FirstOrDefault()).Properties();
                var componentFields  = GetFields(pageProperties);
                var componentButtons = GetButtons(pageProperties);
                var componentCodes   = GetCodes(pageProperties);

                curatedExperience.Components.Add(new CuratedExperienceComponent
                {
                    ComponentId = Guid.NewGuid(),
                    Name        = pageProperties.GetValue("name"),
                    Help        = pageProperties.GetValue("help").RemoveHtmlTags(),
                    Learn       = pageProperties.GetValue("learn").RemoveHtmlTags(),
                    Text        = pageProperties.GetValue("text").RemoveHtmlTags(keepTextFormatingTags: true, keepHyperlinkTags: true).RemoveCustomA2JFunctions(),
                    Fields      = componentFields,
                    Buttons     = componentButtons,
                    Code        = componentCodes
                });
            }

            // find out the first question in the list and add it to top (A2J Author doesn't order the pages in the json array, it depends on
            // an additional xml file to arrange the questions!)
            var firstQuestion      = curatedExperience.Components.Where(x => x.Name == a2jProperties.GetValue("firstPage")).First();
            var firstQuestionIndex = curatedExperience.Components.IndexOf(firstQuestion);

            curatedExperience.Components.RemoveAt(firstQuestionIndex);
            curatedExperience.Components.Insert(0, firstQuestion);

            dbService.CreateItemAsync(curatedExperience, dbSettings.CuratedExperiencesCollectionId);
            return(curatedExperience);
        }
        public void CreateUserSavedResourcesAsyncTestsShouldReturnProperData()
        {
            //arrange
            var            userProfileSavedResources = this.userProfileSavedResourcesData;
            var            resource = JsonConvert.DeserializeObject <ProfileResources>(JsonConvert.SerializeObject(this.userProfileSavedResourcesData.First));
            Document       document = new Document();
            JsonTextReader reader   = new JsonTextReader(new StringReader(userProfileSavedResources[0].ToString()));

            document.LoadFrom(reader);
            dynamic actualUserSavedResourcesData = null;
            var     dbResponse = backendDatabaseService.CreateItemAsync <dynamic>(userProfileSavedResources, cosmosDbSettings.ResourcesCollectionId).ReturnsForAnyArgs(document);

            //act
            actualUserSavedResourcesData = userProfileBusinessLogic.CreateUserSavedResourcesAsync(resource).Result;

            //assert
            Assert.Equal(expectedUserProfileSavedResourcesData[0].ToString(), actualUserSavedResourcesData.ToString());
        }
        public async Task <CuratedExperienceComponentViewModel> GetComponent(CuratedExperience curatedExperience, Guid componentId)
        {
            var dbComponent = new CuratedExperienceComponent();
            var answers     = new CuratedExperienceAnswers();

            if (componentId == default(Guid))
            {
                answers.AnswersDocId        = Guid.NewGuid();
                answers.CuratedExperienceId = curatedExperience.CuratedExperienceId;
                await dbService.CreateItemAsync(answers, dbSettings.GuidedAssistantAnswersCollectionId);

                dbComponent = curatedExperience.Components.First();
            }
            else
            {
                dbComponent = curatedExperience.Components.Where(x => x.ComponentId == componentId).FirstOrDefault();
            }

            return(MapComponentViewModel(curatedExperience, dbComponent, answers.AnswersDocId));
        }
        public void GetComponentValidate(CuratedExperience curatedExperiencedata, CuratedExperienceComponentViewModel expectedData, Guid id, dynamic curateExperienceAnswers)
        {
            //arrange
            Document       updatedDocument = new Document();
            JsonTextReader reader          = new JsonTextReader(new StringReader(curateExperienceAnswers));

            updatedDocument.LoadFrom(reader);

            dbService.CreateItemAsync <CuratedExperienceComponentViewModel>(
                Arg.Any <CuratedExperienceComponentViewModel>(),
                Arg.Any <string>()).ReturnsForAnyArgs <Document>(updatedDocument);

            var response = curatedExperience.GetComponent(curatedExperiencedata, id);

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

            //assert
            Assert.Equal(expectedResult, actualResult);
        }
        public void UpsertStaticNavigationDataAsyncShouldValidate(Navigation navigationInput, JArray navigationDBData, dynamic expectedResult)
        {
            var expectedName = "Navigation";
            var dbResponse   = dynamicQueries.FindItemsWhereWithLocationAsync(cosmosDbSettings.StaticResourcesCollectionId, Constants.Name, navigationInput.Name, new Location());

            dbResponse.ReturnsForAnyArgs(navigationDBData);

            Document       updatedDocument = new Document();
            JsonTextReader reader          = new JsonTextReader(new StringReader(StaticResourceTestData.updatedStaticNavigationContent));

            updatedDocument.LoadFrom(reader);

            backendDatabaseService.CreateItemAsync <dynamic>(
                Arg.Any <Navigation>(),
                Arg.Any <string>()).ReturnsForAnyArgs <Document>(updatedDocument);

            backendDatabaseService.UpdateItemAsync <dynamic>(
                Arg.Any <string>(),
                Arg.Any <Navigation>(),
                Arg.Any <string>()).ReturnsForAnyArgs <Document>(updatedDocument);

            //act
            var response = staticResourceBusinessLogic.UpsertStaticNavigationDataAsync(navigationInput);

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

            //assert
            Assert.Contains(expectedName, expectedResult);
        }
示例#10
0
        /// <summary>
        /// upserts service provider
        /// </summary>
        public async Task <IEnumerable <Document> > UpsertServiceProviderDocumentAsync(List <ServiceProvider> serviceProvider, string topic)
        {
            var resources = new List <Document>();
            var serviceProviderObjects = JsonUtilities.DeserializeDynamicObject <List <ServiceProvider> >(serviceProvider);

            foreach (var serviceProviderObject in serviceProviderObjects)
            {
                var serviceProviderLocation = new Location {
                    State = serviceProviderObject.Location[0].State
                };
                if (!string.IsNullOrEmpty(topic))
                {
                    var topicDBData = await dbClient.FindItemsWhereContainsWithLocationAsync(dbSettings.TopicsCollectionId, Constants.Name, topic, serviceProviderLocation).ConfigureAwait(false);

                    serviceProviderObject.TopicTags = topicDBData.Count > 0 ? GetServiceProviderTopicTags(topicDBData[0].id) : null;
                }
                List <string> propertyNames = new List <string>()
                {
                    Constants.ExternalId, Constants.ResourceType
                };
                List <string> values = new List <string>()
                {
                    serviceProviderObject.ExternalId, serviceProviderObject.ResourceType
                };
                var serviceProviderDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values).ConfigureAwait(false);

                if (serviceProviderDBData.Count == 0)
                {
                    var resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(serviceProviderObject);
                    var result           = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId).ConfigureAwait(false);

                    resources.Add(result);
                }
                else
                {
                    serviceProviderObject.ResourceId = serviceProviderDBData[0].id.ToString();
                    var resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(serviceProviderObject);
                    var result           = await dbService.UpdateItemAsync(serviceProviderObject.ResourceId, resourceDocument, dbSettings.ResourcesCollectionId).ConfigureAwait(false);

                    resources.Add(result);
                }
            }

            return(resources);
        }
示例#11
0
 public async Task<dynamic> UpsertStaticHomePageDataAsync(HomeContent homePageContent)
 {
     dynamic result = null;
     var pageDBData = await dbClient.FindItemsWhereWithLocationAsync(dbSettings.StaticResourcesCollectionId, Constants.Name, homePageContent.Name, homePageContent.Location.FirstOrDefault());
     if (pageDBData?.Count > 0)
     {
         string id = pageDBData[0].id;
         homePageContent.Id = id;
         var pageDocument = JsonUtilities.DeserializeDynamicObject<object>(homePageContent);
         result = await dbService.UpdateItemAsync(id, pageDocument, dbSettings.StaticResourcesCollectionId);
     }
     else
     {
         var pageDocument = JsonUtilities.DeserializeDynamicObject<object>(homePageContent);
         result = await dbService.CreateItemAsync(pageDocument, dbSettings.StaticResourcesCollectionId);
     }
     return result;
 }
        public async Task <object> UpsertSharedResource(UserProfile userProfile, SharedResource sharedResource)
        {
            List <SharedResource> sharedResources = new List <SharedResource>();
            dynamic userSharedResourcesDBData     = null;
            dynamic response = 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 && userSharedResourcesDBData.Count > 0)
            {
                var userSharedResources = new List <SharedResources>();
                userSharedResources = JsonUtilities.DeserializeDynamicObject <List <SharedResources> >(userSharedResourcesDBData);
                userSharedResources[0].SharedResourceId = userProfile.SharedResourceId;
                userSharedResources[0].SharedResource.Add(sharedResource);
                response = await dbService.UpdateItemAsync(userProfile.SharedResourceId.ToString(), userSharedResources[0],
                                                           dbSettings.UserResourcesCollectionId);
            }
            else
            {
                var userSharedResources = new SharedResources();
                if (userSharedResourcesDBData != null)
                {
                    userSharedResources.SharedResourceId = userProfile.SharedResourceId;
                }
                else
                {
                    userSharedResources.SharedResourceId = Guid.NewGuid();
                }
                sharedResources.Add(sharedResource);
                userSharedResources.SharedResource = sharedResources;
                userProfile.SharedResourceId       = userSharedResources.SharedResourceId;
                await dbService.UpdateItemAsync(userProfile.Id, userProfile,
                                                dbSettings.ProfilesCollectionId);

                response = await dbService.CreateItemAsync((userSharedResources), dbSettings.UserResourcesCollectionId);
            }
            return(response);
        }
        public void UpsertServiceProviderAsyncTestsShouldReturnProperData(string topicName, JArray topic, string externalId, JArray serviceProviderResponseData, string serviceProviderId, JArray serviceProviderData, List <ServiceProvider> serviceProvider, dynamic expectedServiceProviderdata)
        {
            //arrange
            dynamic  actualServiceProviderData = null;
            Location location            = new Location();
            var      dbResponseFindTopic = dynamicQueries.FindItemsWhereContainsWithLocationAsync(cosmosDbSettings.TopicsCollectionId, Constants.Name, topicName, location);

            dbResponseFindTopic.ReturnsForAnyArgs(topic);
            List <string> propertyNames = new List <string>()
            {
                Constants.ExternalId, Constants.ResourceType
            };
            List <string> values = new List <string>()
            {
                externalId, Constants.ServiceProviderResourceType
            };
            var dbResponseFindItems = dynamicQueries.FindItemsWhereAsync(cosmosDbSettings.ResourcesCollectionId, propertyNames, values);

            dbResponseFindItems.ReturnsForAnyArgs(serviceProviderResponseData);
            Document       updatedDocument = new Document();
            JsonTextReader reader          = new JsonTextReader(new StringReader(serviceProviderData[0].ToString()));

            updatedDocument.LoadFrom(reader);
            backendDatabaseService.UpdateItemAsync <dynamic>(serviceProviderId, serviceProviderData, cosmosDbSettings.ResourcesCollectionId)
            .ReturnsForAnyArgs <Document>(updatedDocument);
            backendDatabaseService.CreateItemAsync <dynamic>(serviceProviderData, cosmosDbSettings.ResourcesCollectionId)
            .ReturnsForAnyArgs <Document>(updatedDocument);

            //act
            var response = serviceProvidersBusinessLogic.UpsertServiceProviderDocumentAsync(serviceProvider, topicName).Result;

            foreach (var result in response)
            {
                actualServiceProviderData = result;
            }

            //assert
            Assert.Equal(expectedServiceProviderdata[0].ToString(), actualServiceProviderData.ToString());
        }
        public async Task <Document> UpsertPersonalizedPlanAsync(UserPlan userPlan)
        {
            try
            {
                PersonalizedPlanViewModel personalizedPlan = userPlan.PersonalizedPlan;
                string  oId      = userPlan.UserId;
                dynamic response = null;

                var userPersonalizedPlan = await GetPersonalizedPlanAsync(personalizedPlan.PersonalizedPlanId);

                if (userPersonalizedPlan == null || userPersonalizedPlan?.PersonalizedPlanId == Guid.Empty)
                {
                    var newPlan = await backendDatabaseService.CreateItemAsync(personalizedPlan, cosmosDbSettings.ActionPlansCollectionId);

                    if (!Guid.TryParse(newPlan.Id, out Guid guid))
                    {
                        return(response);
                    }
                    response = newPlan;
                }
                else
                {
                    response = await backendDatabaseService.UpdateItemAsync(
                        personalizedPlan.PersonalizedPlanId.ToString(), personalizedPlan, cosmosDbSettings.ActionPlansCollectionId);
                }
                if (!userPlan.saveActionPlan)
                {
                    await UpdatePlanToProfile(personalizedPlan.PersonalizedPlanId, oId, personalizedPlan);
                }
                return(response);
            }
            catch
            {
                return(null);
            }
        }
        public async Task <IEnumerable <object> > UpsertResourceDocumentAsync(dynamic resource)
        {
            List <dynamic>    results            = new List <dynamic>();
            List <dynamic>    resources          = new List <dynamic>();
            var               resourceObjects    = JsonUtilities.DeserializeDynamicObject <List <dynamic> >(resource);
            Form              forms              = new Form();
            ActionPlan        actionPlans        = new ActionPlan();
            Article           articles           = new Article();
            Video             videos             = new Video();
            Organization      organizations      = new Organization();
            AdditionalReading additionalReadings = new AdditionalReading();
            RelatedLink       relatedLinks       = new RelatedLink();

            foreach (var resourceObject in resourceObjects)
            {
                string id           = resourceObject.id;
                string resourceType = resourceObject.resourceType;
                if (resourceObject.resourceType == "Forms")
                {
                    forms = UpsertResourcesForms(resourceObject);
                    var           resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(forms);
                    List <string> propertyNames    = new List <string>()
                    {
                        Constants.Id, Constants.ResourceType
                    };
                    List <string> values = new List <string>()
                    {
                        id, resourceType
                    };
                    var resourceDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values);

                    if (resourceDBData.Count == 0)
                    {
                        var result = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                    else
                    {
                        var result = await dbService.UpdateItemAsync(id, resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                }

                else if (resourceObject.resourceType == "Action Plans")
                {
                    actionPlans = UpsertResourcesActionPlans(resourceObject);
                    var           resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(actionPlans);
                    List <string> propertyNames    = new List <string>()
                    {
                        Constants.Id, Constants.ResourceType
                    };
                    List <string> values = new List <string>()
                    {
                        id, resourceType
                    };
                    var resourceDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values);

                    if (resourceDBData.Count == 0)
                    {
                        var result = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                    else
                    {
                        var result = await dbService.UpdateItemAsync(id, resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                }

                else if (resourceObject.resourceType == "Articles")
                {
                    articles = UpsertResourcesArticles(resourceObject);
                    var           resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(articles);
                    List <string> propertyNames    = new List <string>()
                    {
                        Constants.Id, Constants.ResourceType
                    };
                    List <string> values = new List <string>()
                    {
                        id, resourceType
                    };
                    var resourceDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values);

                    if (resourceDBData.Count == 0)
                    {
                        var result = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                    else
                    {
                        var result = await dbService.UpdateItemAsync(id, resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                }

                else if (resourceObject.resourceType == "Videos")
                {
                    videos = UpsertResourcesVideos(resourceObject);
                    var           resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(videos);
                    List <string> propertyNames    = new List <string>()
                    {
                        Constants.Id, Constants.ResourceType
                    };
                    List <string> values = new List <string>()
                    {
                        id, resourceType
                    };
                    var resourceDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values);

                    if (resourceDBData.Count == 0)
                    {
                        var result = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                    else
                    {
                        var result = await dbService.UpdateItemAsync(id, resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                }

                else if (resourceObject.resourceType == "Organizations")
                {
                    organizations = UpsertResourcesOrganizations(resourceObject);
                    var           resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(organizations);
                    List <string> propertyNames    = new List <string>()
                    {
                        Constants.Id, Constants.ResourceType
                    };
                    List <string> values = new List <string>()
                    {
                        id, resourceType
                    };
                    var resourceDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values);

                    if (resourceDBData.Count == 0)
                    {
                        var result = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                    else
                    {
                        var result = await dbService.UpdateItemAsync(id, resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                }

                else if (resourceObject.resourceType == "Additional Readings")
                {
                    additionalReadings = UpsertResourcesAdditionalReadings(resourceObject);
                    var           resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(additionalReadings);
                    List <string> propertyNames    = new List <string>()
                    {
                        Constants.Id, Constants.ResourceType
                    };
                    List <string> values = new List <string>()
                    {
                        id, resourceType
                    };
                    var resourceDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values);

                    if (resourceDBData.Count == 0)
                    {
                        var result = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                    else
                    {
                        var result = await dbService.UpdateItemAsync(id, resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                }

                else if (resourceObject.resourceType == "Related Links")
                {
                    relatedLinks = UpsertResourcesRelatedLinks(resourceObject);
                    var           resourceDocument = JsonUtilities.DeserializeDynamicObject <object>(relatedLinks);
                    List <string> propertyNames    = new List <string>()
                    {
                        Constants.Id, Constants.ResourceType
                    };
                    List <string> values = new List <string>()
                    {
                        id, resourceType
                    };
                    var resourceDBData = await dbClient.FindItemsWhereAsync(dbSettings.ResourcesCollectionId, propertyNames, values);

                    if (resourceDBData.Count == 0)
                    {
                        var result = await dbService.CreateItemAsync(resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                    else
                    {
                        var result = await dbService.UpdateItemAsync(id, resourceDocument, dbSettings.ResourcesCollectionId);

                        resources.Add(result);
                    }
                }
            }
            return(resources);
        }