ToolBX.NetAbstractions 2.2.0

dotnet add package ToolBX.NetAbstractions --version 2.2.0
NuGet\Install-Package ToolBX.NetAbstractions -Version 2.2.0
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="ToolBX.NetAbstractions" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolBX.NetAbstractions --version 2.2.0
#r "nuget: ToolBX.NetAbstractions, 2.2.0"
#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.
// Install ToolBX.NetAbstractions as a Cake Addin
#addin nuget:?package=ToolBX.NetAbstractions&version=2.2.0

// Install ToolBX.NetAbstractions as a Cake Tool
#tool nuget:?package=ToolBX.NetAbstractions&version=2.2.0

NetAbstractions

NetAbstractions

Abstractions for .NET base types such as File and Directory to provide easier means to mock low-level operations.

For some strange and obscure reason, Microsoft thought it was a good idea to have unmockable static classes for most low-level operations such as deleting files and folders. Suppose you want to test a method that checks whether a file exists and delete it if it does? You could create temporary files to be used with your tests. It could work but it would also needlessly complexify your tests’ logic. You might also be tempted to just not test that method. It’s fine if you don’t care about code quality. It’s okay, I’m not judging (I am.)

Using this library, you can do the following:

public class ShadyService : IShadyService
{
	private readonly IFile _file;

	public ShadyService(IFile file)
	{
		_file = file;
	}

	public void DoTheThing(string path)
	{
		if (_file.Exists(path))
			_file.Delete(path);
	}
}

And down the line,

[TestClass]
public class ShadyServiceTest
{
	[TestMethod]
	public void SomeTest()
	{
		var file = new Mock<IFile>();
		var shadyService = new ShadyService(file.Object);

		var path = "c:/temp/something.wat";
		shadyService.DoTheThing(path);

		file.Setup(x => x.Exists(path)).Returns(true);

		file.Verify(x => x.Delete(path), Times.Once);
	}
}

Getting started

Using (https://github.com/Moreault/AutoInject "AutoInject")

public void ConfigureServices(IServiceCollection services)
{
	//This only needs to be called once for your entire application
    services.AddAutoInjectServices();
}

Manually

public void ConfigureServices(IServiceCollection services)
{
    services.AddNetAbstractions();
}

You can also add every service one by one if you're into that but the end result will be the same.

IInstanceWrapper and the Unwrapped property

This can be a bit confusing at first. Why would you expose an unwrapped property on a wrapped type?

Well because sometimes that's what you need to do if you make your own wrappers or when using 3rd party code.

In short, you should never use the Unwrapped property outside of wrapper code.

This mechanism may be changed in the future but it is so far the least painful way to deal with wrapping issues.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on ToolBX.NetAbstractions:

Package Downloads
ToolBX.FileGuy

High-level API for handling files.

ToolBX.MisterTerminal

A high level library to easily and cleanly build smarter console applications.

ToolBX.FileGuy.Json

Adds a FileSerializer service which takes advantage of FileGuy's features to serialize objects to file using Microsoft's System.Text json library.

ToolBX.ProjectMaster

Provides a base class to format and access application data paths in an easy and straightforward way.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 584 1/13/2024
2.2.0-beta2 140 1/7/2024
2.2.0-beta1 82 12/21/2023
2.0.3 298 6/19/2023
2.0.2 149 6/11/2023
2.0.2-beta1 116 5/9/2023
2.0.1 409 4/26/2023
2.0.0 457 11/10/2022
2.0.0-beta1 191 9/27/2022
1.0.8 871 9/27/2022
1.0.7 409 7/31/2022
1.0.6 418 7/20/2022
1.0.5 416 7/6/2022
1.0.4 406 7/5/2022
1.0.3 432 6/23/2022
1.0.2.5-beta 635 5/17/2022
1.0.2.4-beta 460 5/15/2022
1.0.2.3-beta 137 5/15/2022
1.0.2.2-beta 140 5/15/2022
1.0.2.1-beta 145 5/6/2022
1.0.2 439 5/2/2022
1.0.1 426 4/29/2022
1.0.0 285 1/10/2022