Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f11619
commit 3ede17e
Showing
36 changed files
with
830 additions
and
304 deletions.
There are no files selected for viewing
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
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
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,42 @@ | ||
// Copyright (c) 2023 .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. | ||
|
||
using Xunit; | ||
|
||
namespace ReactiveUI.Testing.Tests | ||
{ | ||
/// <summary> | ||
/// TestSequencerTests. | ||
/// </summary> | ||
public class TestSequencerTests | ||
{ | ||
/// <summary> | ||
/// Shoulds the execute tests in order. | ||
/// </summary> | ||
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> | ||
[Fact] | ||
public async Task Should_Execute_Tests_In_Order() | ||
{ | ||
using var testSequencer = new TestSequencer(); | ||
var subject = new Subject<Unit>(); | ||
subject.Subscribe(async _ => await testSequencer.AdvancePhaseAsync()); | ||
|
||
Assert.Equal(0, testSequencer.CurrentPhase); | ||
Assert.Equal(0, testSequencer.CompletedPhases); | ||
subject.OnNext(Unit.Default); | ||
Assert.Equal(1, testSequencer.CurrentPhase); | ||
Assert.Equal(0, testSequencer.CompletedPhases); | ||
await testSequencer.AdvancePhaseAsync("Phase 1"); | ||
Assert.Equal(1, testSequencer.CurrentPhase); | ||
Assert.Equal(1, testSequencer.CompletedPhases); | ||
subject.OnNext(Unit.Default); | ||
Assert.Equal(2, testSequencer.CurrentPhase); | ||
Assert.Equal(1, testSequencer.CompletedPhases); | ||
await testSequencer.AdvancePhaseAsync("Phase 2"); | ||
Assert.Equal(2, testSequencer.CurrentPhase); | ||
Assert.Equal(2, testSequencer.CompletedPhases); | ||
} | ||
} | ||
} |
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,84 @@ | ||
// Copyright (c) 2023 .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 ReactiveUI.Testing | ||
{ | ||
/// <summary> | ||
/// Test Sequencer. | ||
/// </summary> | ||
/// <seealso cref="System.IDisposable" /> | ||
public class TestSequencer : IDisposable | ||
{ | ||
private readonly Barrier _phaseSync; | ||
private bool _disposedValue; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TestSequencer"/> class. | ||
/// </summary> | ||
public TestSequencer() => _phaseSync = new(2); | ||
|
||
/// <summary> | ||
/// Gets the number of completed phases. | ||
/// </summary> | ||
/// <value> | ||
/// The completed phases. | ||
/// </value> | ||
public long CompletedPhases => _phaseSync.CurrentPhaseNumber; | ||
|
||
/// <summary> | ||
/// Gets the current phase. | ||
/// </summary> | ||
/// <value> | ||
/// The current phase. | ||
/// </value> | ||
public long CurrentPhase { get; private set; } | ||
|
||
/// <summary> | ||
/// Advances this phase instance. | ||
/// </summary> | ||
/// <param name="comment">The comment for Test visual identification Purposes only.</param> | ||
/// <returns> | ||
/// A <see cref="Task" /> representing the asynchronous operation. | ||
/// </returns> | ||
#pragma warning disable RCS1163 // Unused parameter. | ||
public Task AdvancePhaseAsync(string comment = "") | ||
#pragma warning restore RCS1163 // Unused parameter. | ||
{ | ||
if (_phaseSync.ParticipantCount == _phaseSync.ParticipantsRemaining) | ||
{ | ||
CurrentPhase = CompletedPhases + 1; | ||
} | ||
|
||
return Task.Run(() => _phaseSync?.SignalAndWait(CancellationToken.None)); | ||
} | ||
|
||
/// <summary> | ||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
/// <summary> | ||
/// Releases unmanaged and - optionally - managed resources. | ||
/// </summary> | ||
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> | ||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!_disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
_phaseSync.Dispose(); | ||
} | ||
|
||
_disposedValue = true; | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.