MathCore.TestsExtensions 1.0.0.2

dotnet add package MathCore.TestsExtensions --version 1.0.0.2
                    
NuGet\Install-Package MathCore.TestsExtensions -Version 1.0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MathCore.TestsExtensions" Version="1.0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MathCore.TestsExtensions" Version="1.0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MathCore.TestsExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MathCore.TestsExtensions --version 1.0.0.2
                    
#r "nuget: MathCore.TestsExtensions, 1.0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MathCore.TestsExtensions@1.0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MathCore.TestsExtensions&version=1.0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MathCore.TestsExtensions&version=1.0.0.2
                    
Install as a Cake Tool

MathCore.TestsExtensions

Расширения для MSTest, добавляющие удобный fluent-интерфейс к стандартным ассертам через точки расширения:

  • Assert.That
  • CollectionAssert.That
  • StringAssert.That

Пакет помогает писать выразительные и компактные проверки со связным API: проверка значений, коллекций, перечислений, строк и исключений с наглядными сообщениями об ошибках.

Установка

  • Платформа: .NET Standard 2.0
  • Зависимость: MSTest.TestFramework >= 4.0.2

NuGet-пакет: MathCore.TestsExtensions

Быстрый старт

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class SampleTests
{
    [TestMethod]
    public void Value_and_Collections()
    {
        Assert.That.Value(42).IsEqual(42);

        var items = new[] { 1, 3, 5, 7 };
        Assert.That.Collection(items)
            .IsNotEmpty()
            .Contains(5)
            .IsEqualTo(1, 3, 5, 7);
    }
}

Точки расширения и fluent-интерфейс

Пакет добавляет расширение That к стандартным ассертам:

  • Assert.That — проверки значений (Value), функций/действий (Method), перечислений (Enumerable) и коллекций (Collection)
  • CollectionAssert.That — проверки коллекций (Collection)
  • StringAssert.That — проверки строк через Value(string)

Базовый паттерн использования: начать с нужной «точки», получить «чекер» и вызывать цепочкой методы-проверки. Для удобства большинство чекеров имеют свойство And => Assert.That, позволяя продолжать цепочку с новой проверки.

Примеры: Assert.That

Проверка значения и сравнение с точностью:

Assert.That.Value(1.1).LessOrEqualsThan(1.0, 0.1);
Assert.That.Value(10).GreaterThan(5);

Проверка исключений:

Assert.That.Method(() => throw new InvalidOperationException())
    .Throw<InvalidOperationException>();

Assert.That.Method(() => 1 / 0)
    .Throw<DivideByZeroException>();

Перечисления (IEnumerable<T>):

IEnumerable<string> actual   = new[] { "file3.txt", "file4.txt", "file5.txt", "file6.txt" };
IEnumerable<string> expected = new[] { "file3.txt", "file4.txt", "file5.txt", "file6.txt" };

Assert.That.Enumerable(actual).IsEqualTo(expected);
Assert.That.Enumerable(actual).Contains(s => s.EndsWith(".txt"));

Примеры: CollectionAssert.That

Проверки для ICollection<T> и массивов:

var items = new[] { 1, 3, 5, 7 };

CollectionAssert.That.Collection(items)
    .IsItemsCount(4)
    .Contains(5)
    .IsEqualTo(1, 3, 5, 7);

var expected = new[] { 1, 3, 5, 7 };
CollectionAssert.That.Collection(items).IsEqualTo(expected);

Покрытие сценариев с точностью для double:

double[] actual   = { 1.0, 2.0, 3.000000001 };
double[] expected = { 1.0, 2.0, 3.0 };

Assert.That.Collection(actual).IsEqualTo(expected, 1e-8);

Примеры: StringAssert.That

Строковые проверки через ValueChecker<string>:

StringAssert.That.Value("Hello, World!")
    .StartWith("Hello")
    .Contains("World")
    .EndWith("!")
    .Matches(@"^Hello,\sWorld!$");

Дополнительно: работа с элементами перечислений/коллекций

Позиционные проверки и сводные метрики:

var xs = Enumerable.Range(0, 10).ToArray();

Assert.That.Collection(xs)
    .ItemsCount.IsEqual(10)
    .AllItems((v, i) => v.IsEqual(i));

Assert.That.Enumerable(xs)
    .Max(x => x).IsEqual(9)
    .Min(x => x).IsEqual(0)
    .Average(x => x).IsEqual(4.5);

Сообщения об ошибках

Чекеры формируют понятные сообщения: при неравенстве указываются индексы элементов и сводки по расхождениям (включая относительную ошибку для числовых типов), а также прикладываются Expected и Actual в Exception.Data.

Лицензия

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.2 318 11/16/2025
0.1.44 2,357 4/14/2024
0.1.43.5 1,832 12/1/2022
0.1.43.4 454 12/1/2022
0.1.43.3 455 12/1/2022
0.1.43.2 431 12/1/2022
0.1.43.1 513 11/20/2022
0.1.43 457 11/19/2022
0.1.42.3 453 11/19/2022
0.1.42.2 482 11/19/2022
0.1.42.1 456 11/19/2022
0.1.42 457 11/19/2022
0.1.41 523 11/17/2022
0.1.40 869 9/25/2022
0.1.39.4 1,036 5/24/2022
0.1.39.3 580 5/24/2022
0.1.39.2 600 5/24/2022
0.1.39.1 604 5/24/2022
0.1.39 601 5/24/2022
0.1.38.5 633 5/19/2022
0.1.38.4 646 5/17/2022
0.1.38.3 719 5/11/2022
0.1.38.2 773 4/19/2022
0.1.38.1 574 4/19/2022
0.1.38 605 4/19/2022
0.1.37.2 628 4/12/2022
0.1.37.1 629 4/12/2022
0.1.37 581 4/12/2022
0.1.36 618 4/10/2022
0.1.35.2 660 3/20/2022
0.1.35.1 582 3/20/2022
0.1.35 595 3/20/2022
0.1.34 641 3/19/2022
0.1.33 1,026 1/14/2022
0.1.32 823 12/10/2021
0.1.31 972 9/27/2021
0.1.30.4 1,143 6/8/2021
0.1.30.2 584 5/22/2021
0.1.30.1 1,026 10/30/2020
0.1.30 875 6/9/2020
0.1.29.2 672 5/24/2020
0.1.29.1 667 5/24/2020
0.1.29 706 5/24/2020
0.1.28 821 3/25/2020
0.1.27 705 3/16/2020
0.1.26 711 3/16/2020

Актуализация пакета и зависимостей, поддержка netstandard2.0