Ejemplo n.º 1
0
 internal IProtocolTransformer CreateCorrespondingProtocolTransformer(IProtocol protocol, SearchEngine searchEngine = null)
 {
     return(protocol switch
     {
         UriProtocol uriProtocol => new SearchEngineTransformer(uriProtocol, searchEngine),
         _ => null,
     });
        public void CreateCorrespondingProtocolTransformer_CreatesSearchEngineTransformer()
        {
            var validProtocol = new UriProtocol(null);
            var factory       = new ProtocolTransformerFactory();

            var transformer = factory.CreateCorrespondingProtocolTransformer(validProtocol);

            Assert.IsType <SearchEngineTransformer>(transformer);
        }
        public void Transform_HttpBecomesHttps()
        {
            var uri                     = new Uri($"http://www.bing.com/search?q={Query}");
            var uriProtocol             = new UriProtocol(uri);
            var searchEngineTransformer = new SearchEngineTransformer(uriProtocol, null);

            var transformedProtocol = searchEngineTransformer.Transform();

            Assert.Equal($"https://www.bing.com/search?q={Query}", (transformedProtocol as UriProtocol)?.Uri.AbsoluteUri);
        }
        public void Transform_ReturnsTransformedProtocol(string searchEngineAddress)
        {
            var uri                     = new Uri($"https://www.bing.com/search?q={Query}");
            var uriProtocol             = new UriProtocol(uri);
            var searchEngine            = new SearchEngine("Search engine", searchEngineAddress);
            var searchEngineTransformer = new SearchEngineTransformer(uriProtocol, searchEngine);

            var transformedProtocol = searchEngineTransformer.Transform();

            Assert.Equal(searchEngineAddress + Query, (transformedProtocol as UriProtocol)?.Uri.AbsoluteUri);
        }
Ejemplo n.º 5
0
        private async void Menu_Click(object sender, EventArgs e)
        {
            if (ExecutionMode.IsRunningAsUwp())
            {
                if (_appService == null)
                {
                    // start the app service
                    _appService = new AppService();
                    var result = await _appService.StartAppServiceConnection("com.microsoft.knowzy.appservice.test");
                }

                // start the XAML UI that will communicate with the App Service
                Uri uri = new Uri("com.microsoft.knowzy.protocol.test://" + "message?appserviceid=" + "com.microsoft.knowzy.appservice.test");
                await UriProtocol.SendUri(uri);
            }
        }
Ejemplo n.º 6
0
 internal SearchEngineTransformer(UriProtocol protocol, SearchEngine searchEngine)
 {
     _protocol     = protocol;
     _searchEngine = searchEngine ?? new SearchEngine("Bing", "https://www.bing.com/search?q=");
 }