Beispiel #1
0
        /// <summary>
        /// Constructs a new instance of <see cref="AzPredictorTests"/>
        /// </summary>
        public AzPredictorTests(ModelFixture modelFixture)
        {
            this._fixture = modelFixture;
            var startHistory = $"{AzPredictorConstants.CommandPlaceholder}{AzPredictorConstants.CommandConcatenator}{AzPredictorConstants.CommandPlaceholder}";

            this._service         = new MockAzPredictorService(startHistory, this._fixture.PredictionCollection[startHistory], this._fixture.CommandCollection);
            this._telemetryClient = new MockAzPredictorTelemetryClient();
            this._azPredictor     = new AzPredictor(this._service, this._telemetryClient, new Settings()
            {
                SuggestionCount = 1,
            },
                                                    null);
        }
        /// <summary>
        /// Constructs a new instance of <see cref="AzPredictorTests"/>
        /// </summary>
        public AzPredictorTests(ModelFixture modelFixture)
        {
            _fixture = modelFixture;
            var startHistory = $"{AzPredictorConstants.CommandPlaceholder}{AzPredictorConstants.CommandConcatenator}{AzPredictorConstants.CommandPlaceholder}";

            _service         = new MockAzPredictorService(startHistory, _fixture.PredictionCollection[startHistory], _fixture.CommandCollection, null);
            _telemetryClient = new MockAzPredictorTelemetryClient();
            _azPredictor     = new AzPredictor(_service, _telemetryClient, new Settings()
            {
                SuggestionCount            = 1,
                MaxAllowedCommandDuplicate = 1,
            },
                                               null);
        }
Beispiel #3
0
        private (AzPredictor, MockAzPredictorTelemetryClient) CreateTestObjects(bool throwException, int expectedTelemetryEvent)
        {
            var telemetryClient = new MockAzPredictorTelemetryClient();

            telemetryClient.ResetWaitingTasks();
            telemetryClient.ExceptedTelemetryRecordCount = expectedTelemetryEvent;
            var startHistory = $"{AzPredictorConstants.CommandPlaceholder}{AzPredictorConstants.CommandConcatenator}{AzPredictorConstants.CommandPlaceholder}";

            var service = new MockAzPredictorService(startHistory, _fixture.PredictionCollection[startHistory], _fixture.CommandCollection);

            service.ThrowException = throwException;
            var azPredictor = new AzPredictor(service, telemetryClient, new Settings()
            {
                SuggestionCount            = 1,
                MaxAllowedCommandDuplicate = 1,
            },
                                              null);

            return(azPredictor, telemetryClient);
        }
Beispiel #4
0
 /// <summary>
 /// Verifies that the number of telemetry events to be sent is equal to <paramref name="expectedCount"/>.
 /// </summary>
 /// <remarks>
 /// It requires to set up the <paramref name="telemetryClient"/> with the <see cref="MockAzPredictorTelemetryClient.ExceptedTelemetryRecordCount"/> one more than <paramref name="expectedCount"/>.
 /// That means the expectedTelemetryEvent in <see cref="CreateTestObjects"/> should be one plus
 /// <paramref name="expectedCount"/>.
 /// Internally, it'll check that the task in <see cref="MockAzPredictorTelemetryClient.SendTelemetryTaskCompletionSource"/> times out because it's waiting for one more telemetry event and that telemetry event never comes.
 /// </remarks>
 private void VerifyTelemetryRecordCount(int expectedCount, MockAzPredictorTelemetryClient telemetryClient)
 {
     Assert.False(telemetryClient.SendTelemetryTaskCompletionSource.Task.Wait(TimeSpan.FromMilliseconds(200)));
     Assert.Equal(expectedCount, telemetryClient.RecordedTelemetry.Count);
 }