Пример #1
0
 /// <summary>
 /// A number of our tests have built in delays while we wait an expected
 /// amount of time for a service operation to complete and this method
 /// allows us to wait (unless we're playing back recordings, which can
 /// complete immediately).
 /// </summary>
 /// <param name="milliseconds">The number of milliseconds to wait.</param>
 /// <param name="playbackDelayMilliseconds">
 /// An optional number of milliseconds to wait if we're playing back a
 /// recorded test.  This is useful for allowing client side events to
 /// get processed.
 /// </param>
 /// <returns>A task that will (optionally) delay.</returns>
 public static async Task Delay(RecordedTestMode mode, int milliseconds = 1000, int?playbackDelayMilliseconds = null)
 {
     if (mode != RecordedTestMode.Playback)
     {
         await Task.Delay(milliseconds);
     }
     else if (playbackDelayMilliseconds != null)
     {
         await Task.Delay(playbackDelayMilliseconds.Value);
     }
 }
 public RecordedVariableMisuse(bool recorded, RecordedTestMode mode) : base(true, mode)
 {
     if (recorded)
     {
         Value = TestEnvironment.RecordedValue;
     }
     else
     {
         Value = TestEnvironment.NotRecordedValue;
     }
 }
        internal DelayCreateKeyInterceptor(RecordedTestMode mode)
        {
            _mode = mode;

            if (int.TryParse(Environment.GetEnvironmentVariable(DelayEnvironmentVariableName), out int maxDelay))
            {
                if (maxDelay >= 0)
                {
                    _maxDelay = maxDelay;
                }
            }
        }
Пример #4
0
        protected IdentityRecordedTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
        {
            // the following headers are added by MSAL and need to be excluded from matching for recordings
            Matcher.ExcludeHeaders.Add("Content-Length");
            Matcher.ExcludeHeaders.Add("client-request-id");
            Matcher.ExcludeHeaders.Add("x-client-OS");
            Matcher.ExcludeHeaders.Add("x-client-SKU");
            Matcher.ExcludeHeaders.Add("x-client-CPU");
            Matcher.ExcludeHeaders.Add("x-client-Ver");

            Sanitizer = new IdentityRecordedTestSanitizer();
        }
 /// <summary>
 /// Modifies the <paramref name="test"/> by adding categories to it and changing the run state as needed.
 /// </summary>
 /// <param name="test">The <see cref="Test"/> to modify.</param>
 public void ApplyToTest(Test test)
 {
     if (test.RunState != RunState.NotRunnable)
     {
         RecordedTestMode mode = TestEnvironment.GlobalTestMode;
         if (mode != RecordedTestMode.Playback)
         {
             test.RunState = RunState.Ignored;
             test.Properties.Set("_SKIPREASON", $"Playback tests will not run when AZURE_TEST_MODE is {mode}.  This test was skipped for the following reason: {_reason}");
         }
     }
 }
Пример #6
0
        public static RecordedTestMode GetModeFromEnvironment()
        {
            string modeString = TestContext.Parameters["TestMode"] ?? Environment.GetEnvironmentVariable(ModeEnvironmentVariableName);

            RecordedTestMode mode = RecordedTestMode.Playback;

            if (!string.IsNullOrEmpty(modeString))
            {
                mode = (RecordedTestMode)Enum.Parse(typeof(RecordedTestMode), modeString, true);
            }

            return(mode);
        }
        /// <summary>
        /// Modifies the <paramref name="test"/> by adding categories to it and changing the run state as needed.
        /// </summary>
        /// <param name="test">The <see cref="Test"/> to modify.</param>
        public void ApplyToTest(Test test)
        {
            test.Properties.Add("Category", "Live");

            if (test.RunState != RunState.NotRunnable)
            {
                RecordedTestMode mode = RecordedTestUtilities.GetModeFromEnvironment();
                if (mode != RecordedTestMode.Live)
                {
                    test.RunState = RunState.Ignored;
                    test.Properties.Set("_SKIPREASON", $"Live tests will not run when AZURE_TEST_MODE is {mode}");
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Modifies the <paramref name="test"/> by adding categories to it and changing the run state as needed.
        /// </summary>
        /// <param name="test">The <see cref="Test"/> to modify.</param>
        public void ApplyToTest(Test test)
        {
            test.Properties.Add("Category", "Live");

            if (test.RunState != RunState.NotRunnable)
            {
                RecordedTestMode mode = TestEnvironment.GlobalTestMode;
                if (mode != RecordedTestMode.Live && !_alwaysRunLocally)
                {
                    test.RunState = RunState.Ignored;
                    test.Properties.Set("_SKIPREASON", $"Live tests will not run when AZURE_TEST_MODE is {mode}");
                }
            }
        }
Пример #9
0
 public static async Task <T> RetryAsync <T>(
     RecordedTestMode mode,
     Func <Task <T> > operation,
     Func <RequestFailedException, bool> shouldRetry,
     int retryDelay    = TestConstants.RetryDelay,
     int retryAttempts = Constants.MaxReliabilityRetries)
 {
     for (int attempt = 0; ;)
     {
         try
         {
             return(await operation());
         }
         catch (RequestFailedException ex)
             when(attempt++ < retryAttempts && shouldRetry(ex))
             {
                 await Delay(mode, retryDelay);
             }
     }
 }
        public TestRecording(RecordedTestMode mode, string sessionFile, RecordedTestSanitizer sanitizer, RecordMatcher matcher)
        {
            Mode         = mode;
            _sessionFile = sessionFile;
            _sanitizer   = sanitizer;
            _matcher     = matcher;

            switch (Mode)
            {
            case RecordedTestMode.Record:
                _session = new RecordSession();
                if (File.Exists(_sessionFile))
                {
                    try
                    {
                        _previousSession = Load();
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                }
                break;

            case RecordedTestMode.Playback:
                try
                {
                    _session = Load();
                }
                catch (Exception ex) when(ex is FileNotFoundException || ex is DirectoryNotFoundException)
                {
                    throw new TestRecordingMismatchException(ex.Message, ex);
                }
                break;

            case RecordedTestMode.RemoteRecord:
            case RecordedTestMode.RemotePlayback:
                break;
            }
        }
Пример #11
0
 public ServiceLinkerTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
     SanitizedHeaders.Add(UserTokenPolicy.UserTokenHeader);
 }
Пример #12
0
 protected ConfidentialLedgerManagementTestBase(bool isAsync, RecordedTestMode mode)
     : base(isAsync, mode)
 {
 }
Пример #13
0
 protected ManagementRecordedTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
 }
Пример #14
0
 public RecordedTestAttributeCommand(TestCommand innerCommand, RecordedTestMode mode) : base(innerCommand)
 {
     _mode = mode;
 }
Пример #15
0
 private static void SetRecordMode(RecordedTestBase fixture, RecordedTestMode mode)
 {
     fixture.Mode = mode;
 }
 protected ServiceBusTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
     Sanitizer = new ServiceBusRecordedTestSanitizer();
 }
 public ComputeTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
 }
 public E2eTestBase(bool isAsync, RecordedTestMode testMode)
     : base(isAsync, testMode)
 {
 }
Пример #19
0
 public StorageTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
 }
        public void ReadingNonRecordedValueInCtorWorks(RecordedTestMode mode)
        {
            var test = new RecordedVariableMisuse(false, mode);

            Assert.AreEqual("2", test.Value);
        }
 protected ResourcesTestBase(bool isAsync, RecordedTestMode mode)
     : base(isAsync, mode, useLegacyTransport: true)
 {
 }
 protected ManagementRecordedTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
     SessionEnvironment      = new TEnvironment();
     SessionEnvironment.Mode = Mode;
     Initialize();
 }
Пример #23
0
 public ConnectedVMwareTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
 }
Пример #24
0
 public VirtualDesktopCollectionTests(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
 }
 public void ReadingRecordedValueInCtorThrowsInRecordedOrPlayback(RecordedTestMode mode)
 {
     Assert.Throws <InvalidOperationException>(() => new RecordedVariableMisuse(true, mode));
 }
Пример #26
0
 protected AppPlatformManagementTestBase(bool isAsync, RecordedTestMode mode)
     : base(isAsync, mode)
 {
 }
        public void ReadingRecordedValueInCtorWorksForSamples(RecordedTestMode mode)
        {
            var test = new SampleTestClass();

            Assert.AreEqual("1", test.Value);
        }
Пример #28
0
 protected RecordedTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync)
 {
     Sanitizer = new RecordedTestSanitizer();
     Matcher   = new RecordMatcher(Sanitizer);
     Mode      = mode;
 }
 public TableServiceLiveTestsBase(bool isAsync, TableEndpointType endpointType, RecordedTestMode recordedTestMode) : base(isAsync, recordedTestMode)
 {
     _endpointType = endpointType;
     Sanitizer     = new TablesRecordedTestSanitizer();
 }
 public ManagedIdentityCredentialLiveTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
 {
 }