From dd65f6903362309a5df833714e53b3f68bf3cc93 Mon Sep 17 00:00:00 2001 From: Adam Radocz Date: Sun, 24 Jul 2022 14:33:40 +0200 Subject: [PATCH 1/2] #938 Add default Run and Test mode. --- src/Splat.Tests/ModeDetection/ModeTests.cs | 43 ++++++++++++++++++++++ src/Splat/ModeDetection/Mode.cs | 30 +++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/Splat.Tests/ModeDetection/ModeTests.cs create mode 100644 src/Splat/ModeDetection/Mode.cs diff --git a/src/Splat.Tests/ModeDetection/ModeTests.cs b/src/Splat.Tests/ModeDetection/ModeTests.cs new file mode 100644 index 000000000..34b611176 --- /dev/null +++ b/src/Splat.Tests/ModeDetection/ModeTests.cs @@ -0,0 +1,43 @@ +using Splat.ModeDetection; +using Xunit; + +namespace Splat.Tests.ModeDetection +{ + /// + /// Unit tests for the class. + /// + public class ModeTests + { + /// + /// Tests the mode. + /// + [Fact] + public void RunModeTest() + { + // Arrange + ModeDetector.OverrideModeDetector(Mode.Run); + + // Act + var inUnitTestRunner = ModeDetector.InUnitTestRunner(); + + // Assert + Assert.False(inUnitTestRunner); + } + + /// + /// Tests the mode. + /// + [Fact] + public void TestModeTest() + { + // Arrange + ModeDetector.OverrideModeDetector(Mode.Test); + + // Act + var inUnitTestRunner = ModeDetector.InUnitTestRunner(); + + // Assert + Assert.True(inUnitTestRunner); + } + } +} diff --git a/src/Splat/ModeDetection/Mode.cs b/src/Splat/ModeDetection/Mode.cs new file mode 100644 index 000000000..47c462357 --- /dev/null +++ b/src/Splat/ModeDetection/Mode.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +namespace Splat.ModeDetection +{ + /// + /// The default implementation of the and mode. + /// + public sealed class Mode : IModeDetector + { + /// + /// The default implementation of the run mode. + /// + public static readonly Mode Run = new(false); + + /// + /// The default implementation of the test mode. + /// + public static readonly Mode Test = new(true); + + private readonly bool _inUnitTestRunner; + + private Mode(bool inUnitTestRunner) => _inUnitTestRunner = inUnitTestRunner; + + /// + public bool? InUnitTestRunner() => _inUnitTestRunner; + } +} From 6e2fc1a00e7fc0c7ba10be1b45cda3aa20bb9747 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Sun, 24 Jul 2022 14:15:45 +0100 Subject: [PATCH 2/2] Update ApiApprovalTests.SplatProject.DotNet6_0.verified.txt --- .../ApiApprovalTests.SplatProject.DotNet6_0.verified.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt index 72858adf4..45d64972d 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt +++ b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.DotNet6_0.verified.txt @@ -772,4 +772,13 @@ namespace Splat.ApplicationPerformanceMonitoring { void OnViewNavigation(string name); } +} +namespace Splat.ModeDetection +{ + public sealed class Mode : Splat.IModeDetector + { + public static readonly Splat.ModeDetection.Mode Run; + public static readonly Splat.ModeDetection.Mode Test; + public bool? InUnitTestRunner() { } + } } \ No newline at end of file