public async Task Should_Return_Content()
        {
            var region               = ValorantEndpointRegion.EU;
            var endpoint             = "/content/v1/contents?locale=en-GB";
            var expectedUri          = new Uri("https://eu.api.riotgames.com/val");
            var expectContentVersion = "unitTest";

            var mockApiUrlResolver = new Mock <IRiotApiUrlResolver>();

            mockApiUrlResolver.Setup(x => x.Resolve(It.Is <ValorantEndpointRegion>(inputRegion => inputRegion == region), It.Is <string>(inputEndpoint => inputEndpoint == endpoint)))
            .Returns(expectedUri)
            .Verifiable();

            var mockRiotHttpClient = new Mock <IRiotHttpClient>();

            mockRiotHttpClient.Setup(x => x.GetAsync <ContentResponse>(It.Is <Uri>(inputUri => inputUri == expectedUri)))
            .ReturnsAsync(new ContentResponse {
                Version = expectContentVersion
            })
            .Verifiable();

            using var contentClient = new ContentClient(mockRiotHttpClient.Object, mockApiUrlResolver.Object);

            var response = await contentClient.GetContentOptionallyFilteredByLocale();

            response.Should().NotBeNull();
            response.Version.Should().Be(expectContentVersion);

            mockApiUrlResolver.VerifyAll();
            mockRiotHttpClient.VerifyAll();
        }
Example #2
0
        public async Task Get_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            // act

            var get1response = await ContentClient.GetContent("aut", schemaName, create1id);

            var get2response = await ContentClient.GetContent("aut", schemaName, create2id);

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Example #3
0
        public async Task ContentImport_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;
            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            var expected1 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[0];
            var expected2 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[1];

            await ContentStories.ImportContent(ContentImportSystemUnderTest, "aut", name1, AssetLoader.AsPath(AssetLoader.Schema1DataImportName), publish : true);

            var actuals = await ContentClient.QueryContent("aut", name1, new QueryRequest()
            {
                Skip = 0,
                Top  = 100
            });

            var actualsTotal = actuals.Total;

            actualsTotal.Should().Be(2);

            var actual1 = actuals.Items[0];
            var actual2 = actuals.Items[1];

            // todo : verify

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
        public void Markup_client_retrieves_last_known_good_content_from_local_cache_if_service_throws_exception()
        {
            // Arrange
            var service = new Mock<IContentService>();

            service.Setup(x => x.Get(ContentTypes.Intranet_FatFooter)).Throws(new Exception("Unit test exception"));
            var cache = new Mock<ILocalCache<Content>>();
            cache.Setup(x => x.WriteToCache(ContentTypes.Intranet_FatFooter, It.IsAny<Content>(), It.IsAny<DateTime>()));
            var content = new Content
            {
                RefreshDate = DateTime.Now,
                Sections = new List<ContentSection>
                {
                    new ContentSection
                    {
                        Id = ContentTypes.Intranet_FatFooter.ToString()
                    }
                }
            };
            cache.Setup(x => x.ReadFromCache(ContentTypes.Intranet_FatFooter)).Returns(content);
            var client = new ContentClient(service.Object, cache.Object);

            // Act
            client.Get(ContentTypes.Intranet_FatFooter);

            // Assert
            service.Verify(x => x.Get(ContentTypes.Intranet_FatFooter), Times.Once);
            cache.Verify(x => x.ReadFromCache(ContentTypes.Intranet_FatFooter), Times.Once);
            cache.Verify(x => x.WriteToCache(ContentTypes.Intranet_FatFooter, It.IsAny<Content>(), It.IsAny<DateTime>()), Times.Never);
        }
Example #5
0
        public async Task ContentDelete_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;
            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            dynamic create1response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", name1, create1id);

            await ContentClient.PublishContent("aut", name1, create2id);

            // act

            await ContentStories.DeleteContent(ContentDeleteSystemUnderTest, "aut", name1, create1id);

            // todo : verify export content

            await ContentClient.AssertContentMustNotExists("aut", name1, create1id, delay : TimeSpan.FromSeconds(0.5));

            await ContentClient.AssertContentMustExists("aut", name1, create2id, delay : TimeSpan.FromSeconds(0.5));

            // clean up

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
Example #6
0
        public async Task ContentPost_Execute_EndToEnd()
        {
            var name1 = GetRandomSchemaName;
            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            var expectedFirst  = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[0];
            var expectedSecond = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[1];

            // act

            await ContentStories.PostContent(ContentPostSystemUnderTest, "aut", name1, AssetLoader.AsPath(AssetLoader.Schema1Data1PostName), publish : true);

            await ContentStories.PostContent(ContentPostSystemUnderTest, "aut", name1, AssetLoader.AsPath(AssetLoader.Schema1Data2PostName), publish : true);

            var content = await ContentClient.QueryContent("aut", name1, new QueryRequest()
            {
                Skip = 0,
                Top  = 100
            });

            int contentTotal = Convert.ToInt32(content.Total);

            contentTotal.Should().Be(2);
            var actualFirst  = content.Items[0];
            var actualSecond = content.Items[1];

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
Example #7
0
        public async Task Create_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            // act

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.AssertContentMustExists("aut", schemaName, create1id, delay : TimeSpan.FromSeconds(0.5));

            await ContentClient.AssertContentMustExists("aut", schemaName, create2id, delay : TimeSpan.FromSeconds(0.5));

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
 public static ContentClient CreateContentClient(this CommerceClients source, string serviceUrl)
 {
     var connectionString = serviceUrl;
     var subscriptionKey = ConfigurationManager.AppSettings["vc-marketplace-apikey"];
     var client = new ContentClient(new Uri(connectionString), new AzureSubscriptionMessageProcessingHandler(subscriptionKey, "secret"));
     return client;
 }
Example #9
0
        public async Task GetContentOptionallyFilteredByLocale_Should_return_valid_response()
        {
            using var contentClient = new ContentClient(new RiotHttpClient(new RiotTokenResolver(), new RiotApiResponseHandler()), new RiotApiUrlResolver());

            var response = await contentClient.GetContentOptionallyFilteredByLocale();

            response.Should().NotBeNull();
        }
        /// <inheritdoc />
        public async Task <IPrefabContentResourceHandle> LoadAvatarPrefabAsync(long avatarId)
        {
            //If it's already available, we can just return immediately
            if (IsAvatarResourceAvailable(avatarId))
            {
                return(TryLoadAvatarPrefab(avatarId));
            }

            ContentDownloadURLResponse downloadUrlResponse = await ContentClient.RequestAvatarDownloadUrl(avatarId, AuthTokenRepo.RetrieveWithType())
                                                             .ConfigureAwait(false);

            //TODO: Handle failure
            TaskCompletionSource <IPrefabContentResourceHandle> completionSource = new TaskCompletionSource <IPrefabContentResourceHandle>();

            //Asset bundle requests can sadly only happen on the main thread, so we must join the main thread.
            await new UnityYieldAwaitable();

            //TODO: We should handle caching, versioning and etc here.
            UnityWebRequestAsyncOperation asyncOperation = UnityWebRequestAssetBundle.GetAssetBundle(downloadUrlResponse.DownloadURL, 0).SendWebRequest();

            //TODO: We should render these operations to the loading screen UI.
            asyncOperation.completed += operation =>
            {
                //When we first get back on the main thread, the main concern
                //is that this resource manager may be from the last scene
                //and that the client may have moved on
                //to avoid this issues we check disposal state
                //and do nothing, otherwise if we check AFTER then we just have to release the assetbundle immediately anyway.
                if (isDisposed)
                {
                    //Just tell anyone awaiting this that it is canceled. They should handle that case, not us.
                    completionSource.SetCanceled();
                    return;
                }


                //GetContent will throw if the assetbundle has already been loaded.
                //So to prevent this from occuring due to multiple requests for the
                //content async we will check, on this main thread, via a write lock.
                lock (SyncObj)
                {
                    //We're on the main thread again. So, we should check if another
                    //request already got the bundle
                    if (IsAvatarResourceAvailable(avatarId))
                    {
                        completionSource.SetResult(TryLoadAvatarPrefab(avatarId));
                        return;
                    }

                    //otherwise, we still don't have it so we should initialize it.
                    this.ResourceHandleCache[avatarId] = new ReferenceCountedPrefabContentResourceHandle(DownloadHandlerAssetBundle.GetContent(asyncOperation.webRequest));
                    completionSource.SetResult(TryLoadAvatarPrefab(avatarId));                     //we assume this will work now.
                }
            };

            return(await completionSource.Task
                   .ConfigureAwait(false));
        }
Example #11
0
        public async Task Restore_EndToEnd()
        {
            // Query only 'sees' published records so that is a quick way to determine publish state
            // - insert some records
            // - publish them
            // - archive them
            // - assert there are none (because we archived them)

            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            var create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            var create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.PublishContent("aut", schemaName, create1response.Id);

            await ContentClient.PublishContent("aut", schemaName, create2response.Id);

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.ArchiveContent("aut", schemaName, create1response.Id);

            await ContentClient.ArchiveContent("aut", schemaName, create2response.Id);

            // act

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.RestoreContent("aut", schemaName, create1response.Id);

            await ContentClient.RestoreContent("aut", schemaName, create2response.Id);

            await Task.Delay(TimeSpan.FromSeconds(1));

            //var content = await ContentClient.Query<dynamic>("aut", schemaName, new QueryRequest()
            //{
            //  Skip = 0,
            //  Top = 100
            //});
            var content = await ContentClient.QueryContent("aut", schemaName, top : 100, skip : 0);

            // ma
            content.Total.Should().Be(2);

            // clean up

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
        private async Task performSearch(string searchTerms, bool isDeepLink = false)
        {
            IEnumerable <IContentItem> children = null;

            try
            {
                if (isDeepLink)
                {
                    children = await ContentClient.DeepLink(selectedChannel.ID, searchTerms);
                }
                else
                {
                    children = await ContentClient.Search(selectedChannel.ID, searchTerms);
                }
            }
            catch (SessionExpiredException)
            {
                await getItemChildren(selectedChannel, true);

                if (isDeepLink)
                {
                    children = await ContentClient.DeepLink(selectedChannel.ID, searchTerms);
                }
                else
                {
                    children = await ContentClient.Search(selectedChannel.ID, searchTerms);
                }
            }

            var name = searchTerms;

            if (isDeepLink)
            {
                name = "Videos";
            }

            ContentItemEx searchResults = new ContentItemEx
            {
                Type         = ContentType.Folder,
                ID           = searchTerms,
                Parent       = selectedChannel,
                Name         = name,
                IsFromSearch = !isDeepLink,
                IsDeepLink   = isDeepLink
            };

            if (children != null)
            {
                searchResults.Children = new ObservableCollection <IContentItem>(children);
            }

            selectedItem = searchResults;
            updateBreadcrumbs();
            SelectedFolder = selectedItem;
            OnPropertyChanged("SelectedItem");
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var contentItems = ContentClient.GetItems("WEB_HOME");

            foreach (var item in contentItems.OrderBy(x => x.Index))
            {
                var literal = new Literal();
                literal.Text = item.Value;
                cms.Controls.Add(literal);
            }
        }
        public static async Task StartContentManagementFunction(FeatureContext context)
        {
            await OpenApiWebHostManager.GetInstance(context).StartFunctionAsync <Startup>(BaseUrl).ConfigureAwait(false);

            // Create a client for the test
            var httpClient = new HttpClient();
            var client     = new ContentClient(httpClient)
            {
                BaseUrl = BaseUrl,
            };

            context.Set(httpClient);
            context.Set(client);
        }
        private async Task loadSelectedItemDetailsAsync()
        {
            if (selectedMediaItem == null)
            {
                return;
            }

            try
            {
                IsDetailsLoading = true;
                ContentItemEx details = null;

                if (selectedMediaItem.Expired)
                {
                    await renewItemID(selectedMediaItem);
                }

                try
                {
                    details = await ContentClient.GetDetails(selectedMediaItem.ID);

                    if ((details == null) && await renewItemID(selectedMediaItem))
                    {
                        details = await ContentClient.GetDetails(selectedMediaItem.ID);
                    }
                }
                catch (SessionExpiredException)
                {
                    if (await renewItemID(selectedMediaItem))
                    {
                        markAllExpired();
                        details = await ContentClient.GetDetails(selectedMediaItem.ID);
                    }
                }

                if ((details != null) && (selectedMediaItem is ContentItemEx))
                {
                    (selectedMediaItem as ContentItemEx).UpdateFromDetails(details);
                }
            }
            catch (Exception ex)
            {
                //XXX : Handle error
                LoggerService.Instance.Log("ERROR: MediaContent.loadSelectedItemDetailsAsync: " + ex);
            }
            finally
            {
                IsDetailsLoading = false;
            }
        }
        public void Content_service_reference_is_only_initialised_once()
        {
            // Arrange
            ConfigurationManager.AppSettings["ContentServiceUrl"] = "http://*****:*****@;_90382";  // invalid url so would break if tried to re-init
            var fatFooterContent = client.Get(ContentTypes.Intranet_FatFooter);

            // Assert
            Assert.That(footerContent, Is.Not.Null);
            Assert.That(fatFooterContent, Is.Not.Null);
        }
        private async Task GetWorkflowStateHistoryAndStoreResponseAsync(string slug, string workflowId, int?limit, string continuationToken, string embed)
        {
            string resolvedSlug       = SpecHelpers.ParseSpecValue <string>(this.featureContext, slug);
            string resolvedWorkflowId = SpecHelpers.ParseSpecValue <string>(this.featureContext, workflowId);
            Embed2?resolvedEmbed      = string.IsNullOrEmpty(embed) ? (Embed2?)null : Enum.Parse <Embed2>(embed, true);

            ContentClient client = this.featureContext.Get <ContentClient>();
            SwaggerResponse <ContentStatesResponse> response = await client.GetWorkflowHistoryAsync(
                this.featureContext.GetCurrentTenantId(),
                resolvedWorkflowId,
                resolvedSlug,
                limit,
                continuationToken,
                resolvedEmbed).ConfigureAwait(false);

            this.scenarioContext.StoreLastApiResponse(response);
        }
Example #18
0
        public MythServiceHost(string mythTvPath, string username, string password)
        {
            _password   = password;
            _userName   = username;
            _mythTvPath = new Uri(mythTvPath);

            _binding = new BasicHttpBinding();
            _binding.MaxReceivedMessageSize = int.MaxValue;

            if (!string.IsNullOrWhiteSpace(username) || !string.IsNullOrWhiteSpace(password))
            {
                _binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            }

            _mythAddress    = new EndpointAddress(string.Format("{0}/Myth", mythTvPath));
            _guideAddress   = new EndpointAddress(string.Format("{0}/Guide", mythTvPath));
            _videoAddress   = new EndpointAddress(string.Format("{0}/Video", mythTvPath));
            _dvrAddress     = new EndpointAddress(string.Format("{0}/Dvr", mythTvPath));
            _contentAddress = new EndpointAddress(string.Format("{0}/Content", mythTvPath));
            _channelAddress = new EndpointAddress(string.Format("{0}/Channel", mythTvPath));
            _captureAddress = new EndpointAddress(string.Format("{0}/Capture", mythTvPath));


            DvrService     = new DvrClient(_binding, _dvrAddress);
            MythService    = new MythClient(_binding, _mythAddress);
            GuideService   = new GuideClient(_binding, _guideAddress);
            VideoService   = new VideoClient(_binding, _videoAddress);
            ContentService = new ContentClient(_binding, _contentAddress);
            ChannelService = new ChannelClient(_binding, _channelAddress);
            CaptureService = new CaptureClient(_binding, _captureAddress);

            DvrService.ClientCredentials.UserName.UserName     = _userName;
            DvrService.ClientCredentials.UserName.Password     = _password;
            MythService.ClientCredentials.UserName.UserName    = _userName;
            MythService.ClientCredentials.UserName.Password    = _password;
            GuideService.ClientCredentials.UserName.UserName   = _userName;
            GuideService.ClientCredentials.UserName.Password   = _password;
            VideoService.ClientCredentials.UserName.UserName   = _userName;
            VideoService.ClientCredentials.UserName.Password   = _password;
            ContentService.ClientCredentials.UserName.UserName = _userName;
            ContentService.ClientCredentials.UserName.Password = _password;
            ChannelService.ClientCredentials.UserName.UserName = _userName;
            ChannelService.ClientCredentials.UserName.Password = _password;
            CaptureService.ClientCredentials.UserName.UserName = _userName;
            CaptureService.ClientCredentials.UserName.Password = _password;
        }
Example #19
0
        public MythServiceHost(string mythTvPath, string username, string password)
        {
            _password = password;
            _userName = username;
            _mythTvPath = new Uri(mythTvPath);

            _binding = new BasicHttpBinding();
            _binding.MaxReceivedMessageSize = int.MaxValue;

            if (!string.IsNullOrWhiteSpace(username) || !string.IsNullOrWhiteSpace(password))
            {
                _binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            }

            _mythAddress = new EndpointAddress(string.Format("{0}/Myth", mythTvPath));
            _guideAddress = new EndpointAddress(string.Format("{0}/Guide", mythTvPath));
            _videoAddress = new EndpointAddress(string.Format("{0}/Video", mythTvPath));
            _dvrAddress = new EndpointAddress(string.Format("{0}/Dvr", mythTvPath));
            _contentAddress = new EndpointAddress(string.Format("{0}/Content", mythTvPath));
            _channelAddress = new EndpointAddress(string.Format("{0}/Channel", mythTvPath));
            _captureAddress = new EndpointAddress(string.Format("{0}/Capture", mythTvPath));


            DvrService = new DvrClient(_binding, _dvrAddress);
            MythService = new MythClient(_binding, _mythAddress);
            GuideService = new GuideClient(_binding, _guideAddress);
            VideoService = new VideoClient(_binding, _videoAddress);
            ContentService = new ContentClient(_binding, _contentAddress);
            ChannelService = new ChannelClient(_binding, _channelAddress);
            CaptureService = new CaptureClient(_binding, _captureAddress);

            DvrService.ClientCredentials.UserName.UserName = _userName;
            DvrService.ClientCredentials.UserName.Password = _password;
            MythService.ClientCredentials.UserName.UserName = _userName;
            MythService.ClientCredentials.UserName.Password = _password;
            GuideService.ClientCredentials.UserName.UserName = _userName;
            GuideService.ClientCredentials.UserName.Password = _password;
            VideoService.ClientCredentials.UserName.UserName = _userName;
            VideoService.ClientCredentials.UserName.Password = _password;
            ContentService.ClientCredentials.UserName.UserName = _userName;
            ContentService.ClientCredentials.UserName.Password = _password;
            ChannelService.ClientCredentials.UserName.UserName = _userName;
            ChannelService.ClientCredentials.UserName.Password = _password;
            CaptureService.ClientCredentials.UserName.UserName = _userName;
            CaptureService.ClientCredentials.UserName.Password = _password;
        }
        public async Task NavigateToDeepLink(IContentItem provider, string link)
        {
            if (string.IsNullOrEmpty(link) || (provider == null) || !provider.IsChannel)
            {
                return;
            }

            IsLoading = true;
            try
            {
                var channel = provider as ChannelEx;
                if (!channel.IsAvailable)
                {
                    return;
                }

                SelectedChannel = channel;
                selectedItem    = provider;
                OnPropertyChanged("SelectedItem");
                SelectedFolder = selectedItem;
                if ((channel.LoginInfo != null) && channel.LoginInfo.HasCredentials && !channel.LoginInfo.LoginPerformed)
                {
                    channel.LoginInfo.LoginPerformed = true;
                    var result = await ContentClient.LoginAndGetChildren(channel.ID, channel.LoginInfo);

                    if (result == null)
                    {
                        return;
                    }

                    channel.LoginInfo.ValidationSuccessful = true;
                    channel.RefreshIsSearchVisible();
                }

                await performSearch(link, true);
            }
            catch (Exception ex)
            {
                LoggerService.Instance.Log("ERROR: MediaContent.NavigateToDeepLink: " + ex);
            }
            finally
            {
                IsLoading = false;
            }
        }
Example #21
0
        public async Task Patch_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            string  create1id      = Convert.ToString(create1response.id);
            dynamic patch1response = await ContentClient.PatchContent("aut", schemaName, create1id, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            // clean up

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Example #22
0
        private async Task RequestContentHistoryAndStoreResponseAsync(
            string slug,
            int?limit,
            string continuationToken,
            string etag)
        {
            string resolvedSlug = SpecHelpers.ParseSpecValue <string>(this.featureContext, slug);

            ContentClient client = this.featureContext.Get <ContentClient>();
            SwaggerResponse <ContentSummariesResponse> response = await client.GetContentHistoryAsync(
                this.featureContext.GetCurrentTenantId(),
                resolvedSlug,
                limit,
                continuationToken,
                etag).ConfigureAwait(false);

            this.scenarioContext.StoreLastApiResponse(response);
        }
Example #23
0
        public async Task Publish_EndToEnd()
        {
            // Query only 'sees' published records so that is a quick way to determine publish state
            // - insert some records
            // - assert that there are none (because we havent published them)
            // - publish them
            // - assert there are two (because we published two)

            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);


            // act

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            await Task.Delay(TimeSpan.FromSeconds(1));

            await ContentClient.AssertContentMustExists("aut", schemaName, create1id, delay : TimeSpan.FromSeconds(0.5));

            await ContentClient.AssertContentMustExists("aut", schemaName, create2id, delay : TimeSpan.FromSeconds(0.5));

            // clean up

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
        public void Markup_client_retrieves_last_known_good_content_from_local_cache_if_service_returns_no_data()
        {
            // Arrange
            var service = new Mock<IContentService>();

            service.Setup(x => x.Get(ContentTypes.Intranet_FatFooter)).Returns((Content)null);
            var cache = new Mock<ILocalCache<Content>>();
            cache.Setup(x => x.WriteToCache(ContentTypes.Intranet_FatFooter, It.IsAny<Content>(), It.IsAny<DateTime>()));
            cache.Setup(x => x.ReadFromCache(ContentTypes.Intranet_FatFooter)).Returns((Content)null);
            var client = new ContentClient(service.Object, cache.Object);

            // Act
            client.Get(ContentTypes.Intranet_FatFooter);

            // Assert
            service.Verify(x => x.Get(ContentTypes.Intranet_FatFooter), Times.Once);
            cache.Verify(x => x.ReadFromCache(ContentTypes.Intranet_FatFooter), Times.Once);
            cache.Verify(x => x.WriteToCache(ContentTypes.Intranet_FatFooter, It.IsAny<Content>(), It.IsAny<DateTime>()), Times.Never);
        }
Example #25
0
        public async Task Query_EndToEnd()
        {
            var schemaName = GetRandomName;
            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));

            var createschema = await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(schemaName));

            var publishedschema = await SchemaClient.PublishSchema("aut", schemaName);

            dynamic create1response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", schemaName, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", schemaName, create1id);

            await ContentClient.PublishContent("aut", schemaName, create2id);

            // act

            // note : eventual consistency and all that sometimes we don't get away with validating right away.

            await Task.Delay(TimeSpan.FromSeconds(1));

            //var content = await ContentClient.Query<dynamic>("aut", schemaName, new QueryRequest()
            //{
            //  Skip = 0,
            //  Top = 100
            //});
            var content = await ContentClient.QueryContent("aut", schemaName, top : 100, skip : 0);

            int contenttotal = Convert.ToInt32(content.total);

            contenttotal.Should().Be(2);
            var actualFirst  = content.items[0];
            var actualSecond = content.items[1];

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", schemaName);
        }
Example #26
0
        public Task <ResponseModel <ContentUploadToken, ContentUploadResponseCode> > Create(ContentUploadTokenFactoryContext context)
        {
            switch (context.ContentType)
            {
            case UserContentType.World:
                return(ContentClient.RequestUpdateExistingWorld(ContentDataDefinition.ContentId));

            case UserContentType.Avatar:
                return(ContentClient.RequestUpdateExistingAvatar(ContentDataDefinition.ContentId));

            case UserContentType.Creature:
                return(ContentClient.RequestUpdateExistingCreature(ContentDataDefinition.ContentId));

            case UserContentType.GameObject:
                return(ContentClient.RequestUpdateExistingGameObjectModel(ContentDataDefinition.ContentId));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private async void photoList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 1)
            {
                var             photo   = e.AddedItems[0] as FacebookAlbumPhotoViewModel;
                AddPhotoRequest request = new AddPhotoRequest();
                request.Transmit = "fb";

                Asset asset = new Asset()
                {
                    Id = photo.ID, Main = _main, XdistancePercent = 1, YdistancePercent = 1, XoffsetPercent = 0, YoffsetPercent = 0
                };

                request.Assets = new Asset[] { asset };

                TinderSession.CurrentSession.CurrentProfile.Photos = await ContentClient.PostAsync <List <Photo> >("media", request).ConfigureAwait(false);

                NavigationService.GoBack();
            }
        }
Example #28
0
        public async Task WhenIRequestThatTheContentIsCreated(string contentItem)
        {
            Cms.Content          item = this.scenarioContext.Get <Cms.Content>(contentItem);
            CreateContentRequest createContentRequest = ContentSpecHelpers.ContentAsCreateContentRequest(item);

            ContentClient client = this.featureContext.Get <ContentClient>();

            try
            {
                SwaggerResponse <ContentResponse> response = await client.CreateContentAsync(
                    this.featureContext.GetCurrentTenantId(),
                    item.Slug,
                    createContentRequest).ConfigureAwait(false);

                this.scenarioContext.StoreLastApiResponse(response);
            }
            catch (SwaggerException ex)
            {
                this.scenarioContext.StoreLastApiException(ex);
            }
        }
Example #29
0
        private async Task RequestContentSummaryAndStoreResponseAsync(string slug, string id, string etag)
        {
            string resolvedSlug = SpecHelpers.ParseSpecValue <string>(this.scenarioContext, slug);
            string resolvedId   = SpecHelpers.ParseSpecValue <string>(this.scenarioContext, id);

            try
            {
                ContentClient client = this.featureContext.Get <ContentClient>();
                SwaggerResponse <ContentSummaryResponse> response = await client.GetContentSummaryAsync(
                    this.featureContext.GetCurrentTenantId(),
                    resolvedSlug,
                    resolvedId,
                    etag).ConfigureAwait(false);

                this.scenarioContext.StoreLastApiResponse(response);
            }
            catch (SwaggerException ex)
            {
                this.scenarioContext.StoreLastApiException(ex);
            }
        }
        public async Task WhenIRequestTheWorkflowStateForSlugAndWorkflowIdWithEmbedded(string embed, string slug, string workflowId)
        {
            string resolvedSlug       = SpecHelpers.ParseSpecValue <string>(this.scenarioContext, slug);
            string resolvedWorkflowId = SpecHelpers.ParseSpecValue <string>(this.scenarioContext, workflowId);
            Embed? resolvedEmbed      = string.IsNullOrEmpty(embed) ? (Embed?)null : Enum.Parse <Embed>(embed, true);

            try
            {
                ContentClient client = this.featureContext.Get <ContentClient>();
                SwaggerResponse <ContentStateResponse> response = await client.GetWorkflowStateAsync(
                    this.featureContext.GetCurrentTenantId(),
                    resolvedSlug,
                    resolvedWorkflowId,
                    resolvedEmbed).ConfigureAwait(false);

                this.scenarioContext.StoreLastApiResponse(response);
            }
            catch (SwaggerException ex)
            {
                this.scenarioContext.StoreLastApiException(ex);
            }
        }
Example #31
0
        public async Task ContentExport_Execute_EndToEnd()
        {
            var name1  = GetRandomSchemaName;
            var export = Path.Combine(AssetLoader.ExportPath, $"{nameof(ContentHandlersIntegrationTest)} {nameof(ContentExport_Execute_EndToEnd)}-out.json");

            await SchemaClient.CreateSchema("aut", AssetLoader.Schema1(name1));

            await SchemaClient.PublishSchema("aut", name1);

            dynamic create1response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data1PostName));

            dynamic create2response = await ContentClient.CreateContent("aut", name1, AssetLoader.AsDynamic(AssetLoader.Schema1Data2PostName));

            string create1id = Convert.ToString(create1response.id);
            string create2id = Convert.ToString(create2response.id);
            await ContentClient.PublishContent("aut", name1, create1id);

            await ContentClient.PublishContent("aut", name1, create2id);

            var expected1 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[0];
            var expected2 = AssetLoader.AsDynamic(AssetLoader.Schema1DataQueryResponseName).Items[1];

            // act

            await ContentStories.ExportContent(ContentExportSystemUnderTest, "aut", name1, export, top : "10", skip : "0");

            var exportExists = File.Exists(export);

            exportExists.Should().BeTrue($"{nameof(SchemaExportRequest)} failed to export file");

            // todo : verify export content

            await SchemaClient.DeleteSchema("aut", name1);

            await SchemaClient.AssertNoSchemasExist("aut", delay : TimeSpan.FromSeconds(0.5));
        }
Example #32
0
 public void SetUp()
 {
     _contentServerConfiguration = ContentConfiguration.MemoryStore();
     _sut = new ContentClient(_contentServerConfiguration);
 }
        public void Markup_client_stores_last_known_good_response_to_local_cache()
        {
            // Arrange
            var service = new Mock<IContentService>();
            var content = new Content
            {
                RefreshDate = DateTime.Now,
                Sections = new List<ContentSection>
                {
                    new ContentSection
                    {
                        Id = ContentTypes.Intranet_FatFooter.ToString(),
                        Html = "fat"
                    }
                }
            };
            service.Setup(x => x.Get(ContentTypes.Intranet_FatFooter)).Returns(content);
            var cache = new Mock<ILocalCache<Content>>();
            cache.Setup(x => x.WriteToCache(ContentTypes.Intranet_FatFooter, It.IsAny<Content>(), It.IsAny<DateTime>()));
            var client = new ContentClient(service.Object, cache.Object);

            // Act
            client.Get(ContentTypes.Intranet_FatFooter);

            // Assert
            service.Verify(x => x.Get(ContentTypes.Intranet_FatFooter), Times.Once);
            cache.Verify(x => x.WriteToCache(ContentTypes.Intranet_FatFooter, It.IsAny<Content>(), It.IsAny<DateTime>()), Times.Once);
        }
        private async Task <IEnumerable <IContentItem> > getItemChildren(IContentItem item, bool silent)
        {
            if (item.IsRoot)
            {
                lastChannelsLoaded = DateTime.Now;
                var result = await ContentClient.GetChannels();

                canRefresh = true;
                if ((result != null) && result.Any())
                {
                    return(result);
                }
                else
                {
                    var isConnected = await RestService.Instance.GetIsConnected();

                    if (!silent && isConnected)
                    {
                        Device.BeginInvokeOnMainThread(() => Application.Current.MainPage.DisplayAlert("Error", "Unable to get channel list. Please make sure you are online, and try again.", "OK"));
                    }

                    return(null);
                }
            }
            else
            {
                if (item.IsChannel)
                {
                    var channel = item as ChannelEx;
                    if (!channel.IsAvailable)
                    {
                        return(null);
                    }

                    if ((channel.LoginInfo != null) && channel.LoginInfo.HasCredentials)
                    {
                        channel.LoginInfo.LoginPerformed = true;
                        var result = await ContentClient.LoginAndGetChildren(item.ID, channel.LoginInfo);

                        if (result == null)
                        {
                            var validation = await SettingsClient.ValidateCredentials(channel.ID, channel.LoginInfo);

                            if ((validation != null) && !validation.Success)
                            {
                                channel.LoginInfo.ValidationSuccessful = false;
                                Device.BeginInvokeOnMainThread(() => AlertViewService.Instance.ShowAlert(validation.Message));
                            }
                        }
                        else
                        {
                            channel.LoginInfo.ValidationSuccessful = true;
                            UserStoreService.Instance.StoreRecordInKeychain(getAccountEmail() + "channel-" + item.ID, JsonConvert.SerializeObject((item as ChannelEx).LoginInfo));
                        }

                        channel.RefreshIsSearchVisible();

                        return(result);
                    }
                    else if (channel.CredentialsType != ChannelCredentialsType.Anonymous)
                    {
                        return(await ContentClient.LoginAndGetChildren(item.ID, new ChannelLoginInfo()));
                    }
                }

                return(await ContentClient.GetChildren(item.ID));
            }
        }
        public void SmokeTest()
        {
            // Arrange
            ConfigurationManager.AppSettings["ContentServiceUrl"] = "http://localhost:2222/api/Content/";
            var client = new ContentClient();

            // Act
            var content = client.Get(ContentTypes.Footer);

            // Assert
            Assert.That(content, Is.Not.Null);
        }
        static async Task Main(string[] args)
        {
            var client = new ContentClient(HttpClient);
            var token  = await HttpClient.GetToken("sample_console_client", "developmentsecret", $"{client.BaseUrl}/connect/token");

            HttpClient.DefaultRequestHeaders.Clear();
            HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);

            var fooTextItemDto = (await client.Api_GetAsync("4qnhdhv3z54xk4fg4tdfke76c9")) as FooTextItemDto;

            Console.WriteLine("Reading from Api: " + fooTextItemDto.FooText.FooField.Text);

            fooTextItemDto.FooText.FooField.Text = "Foo field value - edited by api - " + Guid.NewGuid().ToString("n");

            fooTextItemDto = (await client.Api_PostAsync(false, fooTextItemDto)) as FooTextItemDto;

            Console.WriteLine("Written and read back from Api: " + fooTextItemDto.FooText.FooField.Text);

            Console.WriteLine(JsonConvert.SerializeObject(fooTextItemDto, Formatting.Indented));

            var queriesClient = new QueriesClient(HttpClient);

            var recentBlogPostsQuery = await queriesClient.Api_Query_PostAsync("RecentBlogPosts", String.Empty);

            foreach (var item in recentBlogPostsQuery.OfType <BlogPostItemDto>())
            {
                Console.WriteLine(item.DisplayText);
            }

            var aliasQuery = await queriesClient.Api_Query_GetAsync("AliasQuery", "{ alias:'categories' }");

            foreach (var item in aliasQuery)
            {
                Console.WriteLine("Sql query for aliases: " + item.DisplayText);
                Console.WriteLine(JsonConvert.SerializeObject(item, Formatting.Indented));
            }

            var luceneClient = new LuceneClient(HttpClient);

            // This style of lucene query will always return content items.
            var luceneContentQuery = await luceneClient.Api_Content_PostAsync("Search", LuceneQuery, String.Empty);

            foreach (var item in luceneContentQuery.Items.OfType <BlogPostItemDto>())
            {
                Console.WriteLine("Lucene query for blogposts: " + item.DisplayText);
            }

            // This style of query can also return any kind of document that is indexed with lucene.
            var luceneDocumentQuery = await luceneClient.Api_Documents_GetAsync("Search", LuceneQuery, null);

            foreach (var item in luceneDocumentQuery)
            {
                Console.WriteLine("Lucene document query: " + item.AdditionalProperties["Content.ContentItem.DisplayText"]);
            }

            var fooClient = new FooClient(HttpClient);
            var fooQuery  = await fooClient.Foo_GetAllAsync();

            foreach (var item in fooQuery)
            {
                Console.WriteLine("Foo : " + item.Text);
            }
        }
        public async Task <string> GetNewItemID(List <IContentItem> parents, string name)
        {
            if ((parents == null) || !parents.Any() || string.IsNullOrEmpty(name))
            {
                return(null);
            }

            if ((Root == null) || (Root.Children == null))
            {
                return(null);
            }

            var channel = Root.Children.FirstOrDefault(c => c.Name == parents[0].Name);

            if (channel == null)
            {
                return(null);
            }

            string currentID = channel.ID;

            while (parents.Count > 0)
            {
                var currentParent = parents[0];
                parents.RemoveAt(0);
                string title = name;
                if (parents.Count > 0)
                {
                    title = parents[0].Name;
                }

                IEnumerable <ContentItemEx> items = null;
                try
                {
                    if ((currentID == channel.ID) && (channel is ChannelEx) && ((channel as ChannelEx).LoginInfo != null) && (channel as ChannelEx).LoginInfo.HasCredentials)
                    {
                        items = await ContentClient.LoginAndGetChildren(currentID, (channel as ChannelEx).LoginInfo);
                    }
                    else
                    {
                        if (currentParent.IsFromSearch)
                        {
                            items = await ContentClient.Search(channel.ID, currentID);
                        }
                        else if (currentParent.IsDeepLink)
                        {
                            items = await ContentClient.DeepLink(channel.ID, currentID);
                        }
                        else
                        {
                            items = await ContentClient.GetChildren(currentID);
                        }
                    }
                }
                catch
                {
                }

                if ((items == null) || !items.Any())
                {
                    return(null);
                }

                if (parents.Count == 0)
                {
                    var item = items.FirstOrDefault(i => i.Name == name);
                    if (item != null)
                    {
                        return(item.ID);
                    }
                }
                else
                {
                    var item = items.FirstOrDefault(i => i.Name == title);
                    if (item != null)
                    {
                        currentID = item.ID;
                    }
                    else if (parents[0].IsFromSearch || parents[0].IsDeepLink)
                    {
                        currentID = parents[0].ID;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }