Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#938 Add default Run and Test mode. #939

Merged
merged 2 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}