Skip to content

Commit

Permalink
#938 Add default Run and Test mode. (#939)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>
  • Loading branch information
adamradocz and ChrisPulman authored Jul 24, 2022
1 parent fa2aed8 commit 211f99d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
}
}
43 changes: 43 additions & 0 deletions src/Splat.Tests/ModeDetection/ModeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Splat.ModeDetection;
using Xunit;

namespace Splat.Tests.ModeDetection
{
/// <summary>
/// Unit tests for the <see cref="Mode"/> class.
/// </summary>
public class ModeTests
{
/// <summary>
/// Tests the <see cref="Mode.Run"/> mode.
/// </summary>
[Fact]
public void RunModeTest()
{
// Arrange
ModeDetector.OverrideModeDetector(Mode.Run);

// Act
var inUnitTestRunner = ModeDetector.InUnitTestRunner();

// Assert
Assert.False(inUnitTestRunner);
}

/// <summary>
/// Tests the <see cref="Mode.Test"/> mode.
/// </summary>
[Fact]
public void TestModeTest()
{
// Arrange
ModeDetector.OverrideModeDetector(Mode.Test);

// Act
var inUnitTestRunner = ModeDetector.InUnitTestRunner();

// Assert
Assert.True(inUnitTestRunner);
}
}
}
30 changes: 30 additions & 0 deletions src/Splat/ModeDetection/Mode.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// The default implementation of the <see cref="Run"/> and <see cref="Test"/> mode.
/// </summary>
public sealed class Mode : IModeDetector
{
/// <summary>
/// The default implementation of the run mode.
/// </summary>
public static readonly Mode Run = new(false);

/// <summary>
/// The default implementation of the test mode.
/// </summary>
public static readonly Mode Test = new(true);

private readonly bool _inUnitTestRunner;

private Mode(bool inUnitTestRunner) => _inUnitTestRunner = inUnitTestRunner;

/// <inheritdoc/>
public bool? InUnitTestRunner() => _inUnitTestRunner;
}
}

0 comments on commit 211f99d

Please sign in to comment.