xunit.assertation.extensions 0.1.2-alpha

This is a prerelease version of xunit.assertation.extensions.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package xunit.assertation.extensions --version 0.1.2-alpha
                    
NuGet\Install-Package xunit.assertation.extensions -Version 0.1.2-alpha
                    
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="xunit.assertation.extensions" Version="0.1.2-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="xunit.assertation.extensions" Version="0.1.2-alpha" />
                    
Directory.Packages.props
<PackageReference Include="xunit.assertation.extensions" />
                    
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 xunit.assertation.extensions --version 0.1.2-alpha
                    
#r "nuget: xunit.assertation.extensions, 0.1.2-alpha"
                    
#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 xunit.assertation.extensions@0.1.2-alpha
                    
#: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=xunit.assertation.extensions&version=0.1.2-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=xunit.assertation.extensions&version=0.1.2-alpha&prerelease
                    
Install as a Cake Tool

xunit.assertation.extensions


That library extend xunit.assertation libraies class Assert with new methods like Assert.That(...) That library is made to simplify assertation in xunit. New methos does not replace standard Assert class mehtod, so you can use both, but I recommed to use one of it.

How to use it


The simple assertation usage:

object obj = ...

Assert.That(obj)
	.IsNotNull()
	.IsEqualTo(obj);

Extension methods


Assert class extension methods in library:

  • Assert.That(...) - contains methods to assert single value.
  • Assert.ThatCollection(...) - contains methods to assert collection values.
  • Assert.ThatCode(...) - contains methods to assert code behavior or result.
  • Assert.ThatAsyncCode(...) - contains methods to assert async code behavior or result.
  • Assert.All(...) - gets assertation expressions in params, than invoke each expressions and shows all assertation exceptions.

Assert.That()


Assert.That(obj) returns instance of assertation class that contains simple checks for obj. For example:

// Act
var result = ...

// Assert
Assert.That(result).IsNotNull();
Assert.That(result.Amount).IsEqualTo(amount);

Assert.ThatCollection()


Assert.ThatCollection(collection) returns instance of assertation class that contains checks for collection. For example:

// Act
var resultCollection = ...

// Assert
Assert.ThatCollection(resultCollection)
	.HasCount(expectedCount)
	.Any(x => x.ID == firsrtID && x.Amount == firstAmount)
	.Any(x => x.ID == secondID && x.Amount == secondAmount)
	.OrderedByDescending(x => x.Date);

Also Assert.ThatCollection(collection) contains methods for each collection element assertations:

  • ForEach(x => ...) - gets lambda for each elements of collection
  • AssertForEach(x => ...) - gets lambda for each Assert.That(...) for each element of collection

Assert.ThatCode()


Assert.ThatCode(() => DoSomething()) returns instance of assertation class that contains checks for DoSomething(). For example:

// Arrange
void DoSomething()
{
	...
}

// Act & Assert
Assert.ThatCode(() => DoSomething())
	.Throws<ArgumentOutOfRangeException>();

Assert.ThatCode(() => DoSomething()) contains next methods:

  • Throws()or Throws<TException>()
  • DoesNotThrowException()
  • Returns() - for functions

Assert.ThatAsyncCode()


Assert.ThatAsyncCode(() => DoSomethingAsync()) returns instance of assertation class that contains checks for DoSomethingAsync(). For example:

// Arrange
Task DoSomethingAsync()
{
	...
}

// Act & Assert
Assert.ThatAsyncCode(() => DoSomethingAsync())
	.Throws<ArgumentOutOfRangeException>();

Assert.ThatAsyncCode(() => DoSomethingAsync()) contains next methods:

  • Throws()or Throws<TException>()
  • DoesNotThrowException()
  • Returns() - for functions

Assert.All()


Assert.All(() => FirstCheck(), () => SecondCheck()) does all params checks before to throw exception. For example:

// Arrange
var result = ...

// Assert
Assert.All(
	() => Assert.That(result.Message).IsEqualTo(expectedMessage),
	() => Assert.That(result.Date).IsEqualTo(expecteDate),
	() => Assert.That(result.Level).IsType<InfoLevel>(),
	() => Assert.That(result.Service).IsSame(expectedService));

How to install to test project


Unfortunately you cannot use it with standard xunit test project. You need change some package first. When you create simple xunit test project you have next two libraries form xunit:

To use our library you need to remove xunit library and install next libraries instead:

On the other hand you can remove xunit library and just install xunit.extended library instead.

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on xunit.assertation.extensions:

Package Downloads
xunit.extended

Contains xunit libraries with extended assertation library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.4-alpha 431 10/11/2023
0.1.2-alpha 550 7/3/2023
0.1.0-alpha 537 6/25/2023

- Readme was added
 - Sync async code checks were fised with CofigureAwait(false)