diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/EnsureCorrectTestMode.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/EnsureCorrectTestMode.cs new file mode 100644 index 0000000000000..8d1640fce2cdc --- /dev/null +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/EnsureCorrectTestMode.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.IO; +using System.Reflection; +using Azure.Core.TestFramework; +using FluentAssertions; +using Microsoft.Extensions.Configuration; +using NUnit.Framework; + +namespace Azure.DigitalTwins.Core.Tests +{ + [Category("Unit")] + [Parallelizable(ParallelScope.All)] + public class EnsureCorrectTestMode + { + [Test] + // The PR tests use the value in the common.config.json to determine the mode to run the tests. + // This test ensures that the value in common.config.json is not changed. + public void CommonConfig_SetTo_PlaybackMode() + { + // arrange + string codeBase = Assembly.GetExecutingAssembly().CodeBase; + var uri = new UriBuilder(codeBase); + string path = Uri.UnescapeDataString(uri.Path); + string workingDirectory = Path.GetDirectoryName(path); + string testSettingsCommonPath = Path.Combine( + workingDirectory, + "config", + "common.config.json"); + + var testsSettingsConfigBuilder = new ConfigurationBuilder(); + testsSettingsConfigBuilder.AddJsonFile(testSettingsCommonPath); + + IConfiguration config = testsSettingsConfigBuilder.Build(); + + // act + var testSettings = config.Get(); + + // assert + testSettings.TestMode.Should().Be(RecordedTestMode.Playback, "The PR pipeline should always run the e2e tests in the playback mode so the value of TestMode should not be changed in the common.config.json file."); + } + } +}