mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
## Motivation I have a PR where there are many new xUnit tests. It would also be useful to create new xUnit tests for public APIs. The number of xUnit tests will increase and their ordering is required. ## PR Summary - Move C# xUnit tests in new folder. This allows to put new xUnit tests in directory structure in accordance with directory structure where cs files are. - Use an xUnit TestCaseOrderer attribute to sequentially process tests for `powershell.config.json`. - Update README.md - A race condition was fixed which allowed to run all XUnit tests in single batch job.
76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
using Xunit;
|
|
using System;
|
|
using System.Management.Automation;
|
|
using System.Management.Automation.Internal;
|
|
using System.Reflection;
|
|
|
|
namespace PSTests.Parallel
|
|
{
|
|
public static class UtilsTests
|
|
{
|
|
[SkippableFact]
|
|
public static void TestIsWinPEHost()
|
|
{
|
|
Skip.IfNot(Platform.IsWindows);
|
|
Assert.False(Utils.IsWinPEHost());
|
|
}
|
|
|
|
[Fact]
|
|
public static void TestHistoryStack()
|
|
{
|
|
var historyStack = new HistoryStack<string>(20);
|
|
Assert.Equal(0, historyStack.UndoCount);
|
|
Assert.Equal(0, historyStack.RedoCount);
|
|
|
|
historyStack.Push("first item");
|
|
historyStack.Push("second item");
|
|
Assert.Equal(2, historyStack.UndoCount);
|
|
Assert.Equal(0, historyStack.RedoCount);
|
|
|
|
Assert.Equal("second item", historyStack.Undo("second item"));
|
|
Assert.Equal("first item", historyStack.Undo("first item"));
|
|
Assert.Equal(0, historyStack.UndoCount);
|
|
Assert.Equal(2, historyStack.RedoCount);
|
|
|
|
Assert.Equal("first item", historyStack.Redo("first item"));
|
|
Assert.Equal(1, historyStack.UndoCount);
|
|
Assert.Equal(1, historyStack.RedoCount);
|
|
|
|
// Pushing a new item should invalidate the RedoCount
|
|
historyStack.Push("third item");
|
|
Assert.Equal(2, historyStack.UndoCount);
|
|
Assert.Equal(0, historyStack.RedoCount);
|
|
|
|
// Check for the correct exception when the Redo/Undo stack is empty.
|
|
Assert.Throws<InvalidOperationException>(() => historyStack.Redo("bar"));
|
|
historyStack.Undo("third item");
|
|
historyStack.Undo("first item");
|
|
Assert.Equal(0, historyStack.UndoCount);
|
|
Assert.Throws<InvalidOperationException>(() => historyStack.Undo("foo"));
|
|
}
|
|
|
|
[Fact]
|
|
public static void TestBoundedStack()
|
|
{
|
|
uint capacity = 20;
|
|
var boundedStack = new BoundedStack<string>(capacity);
|
|
Assert.Throws<InvalidOperationException>(() => boundedStack.Pop());
|
|
|
|
for (int i = 0; i < capacity; i++)
|
|
{
|
|
boundedStack.Push($"{i}");
|
|
}
|
|
|
|
for (int i = 0; i < capacity; i++)
|
|
{
|
|
var poppedItem = boundedStack.Pop();
|
|
Assert.Equal($"{20 - 1 - i}", poppedItem);
|
|
}
|
|
|
|
Assert.Throws<InvalidOperationException>(() => boundedStack.Pop());
|
|
}
|
|
}
|
|
}
|