-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): Adding tests to ensure that the test mode values are not …
…changed (#12481)
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
sdk/digitaltwins/Azure.DigitalTwins.Core/tests/EnsureCorrectTestMode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestSettings>(); | ||
|
||
// 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."); | ||
} | ||
} | ||
} |