Inheritance: WordPredictorServiceBase
Example #1
0
        public void WordPredictorServiceTest()
        {
            TextualContextService t = new TextualContextService();

            WordPredictorServiceBase.PluginDirectoryPath = TestHelper.SybilleResourceFullPath;
            WordPredictorServiceBase w = new SybilleWordPredictorService()
            {
                Feature = TestHelper.MockFeature( 10 ).Object,
                TextualContextService = t
            };

            w.Setup( null );
            w.Start();

            Task.WaitAll( w.AsyncEngineContinuation );

            t.SetRawText( "Je" );
            //Task.WaitAll( w.AsyncEngineContinuation );
            Assert.That( w.Words.Count > 0 );
            Console.WriteLine( String.Join( " ", w.Words.Select( o => o.Word ).ToArray() ) );
            t.SetRawText( "Je " );
            t.SetRawText( "Je Bon" );
            Assert.That( w.Words.Count > 0 );
            Console.WriteLine( String.Join( " ", w.Words.Select( o => o.Word ).ToArray() ) );

            w.Stop();
        }
        public void When_A_Word_Is_Predicted_It_Must_Appears_In_Prediction_Zone()
        {
            // Texual service plugin usage
            var textualService = new TextualContextService()
            {
                //SendKeyService = ServiceHelper.MockServiceWrapper<ISendKeyCommandHandlerService>(),
                //SendStringService = ServiceHelper.MockServiceWrapper<ISendStringService>()
            };
            // Predictor service plugin usage

            SybilleWordPredictorService.PluginDirectoryPath = TestHelper.SybilleResourceFullPath;
            var predictorService = new SybilleWordPredictorService()
            {
                Feature = TestHelper.MockFeature( 10 ).Object,
                TextualContextService = textualService,
            };

            // Mocking of IKeyboardContext
            var mKbContext = TestHelper.MockKeyboardContext( TestHelper.CompatibilityKeyboardName, TestHelper.PredictionZoneName );

            // The Plugin Under Test.
            var pluginSut = new InKeyboardWordPredictor()
            {
                Feature = TestHelper.MockFeature( 10 ).Object,
                WordPredictorService = predictorService.MockServiceWrapper<IWordPredictorService>(),
                Context = mKbContext.Object
            };

            // Start all depending plugins
            textualService.Start();
            predictorService.Setup( null );
            predictorService.Start();
            pluginSut.Start();
            Task.WaitAll( predictorService.AsyncEngineContinuation );
            // Start test. When a token is inserted into the textual service, it will triggers the predictor service to make a prediction.
            textualService.SetRawText( "J" );
            Assert.That( predictorService.Words.Count > 0 );

            // We need to assert that the SUT correctly creates Keys into the Prediction Zone, according to its specs.

            // Test
            var keys = pluginSut.Context.Keyboards[TestHelper.CompatibilityKeyboardName].Zones[ TestHelper.PredictionZoneName].Keys;
            Assert.That( keys.Select( e => e.CurrentLayout.Current.Visible == true ).Count() == predictorService.Words.Count );

            mKbContext.VerifyAll();
        }