ToolBX.NetAbstractions
3.0.0
dotnet add package ToolBX.NetAbstractions --version 3.0.0
NuGet\Install-Package ToolBX.NetAbstractions -Version 3.0.0
<PackageReference Include="ToolBX.NetAbstractions" Version="3.0.0" />
paket add ToolBX.NetAbstractions --version 3.0.0
#r "nuget: ToolBX.NetAbstractions, 3.0.0"
// Install ToolBX.NetAbstractions as a Cake Addin #addin nuget:?package=ToolBX.NetAbstractions&version=3.0.0 // Install ToolBX.NetAbstractions as a Cake Tool #tool nuget:?package=ToolBX.NetAbstractions&version=3.0.0
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- ToolBX.AutoInject (>= 3.0.0)
- ToolBX.Mathemancy (>= 3.0.0)
- ToolBX.WrapperMeister (>= 3.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on ToolBX.NetAbstractions:
Package | Downloads |
---|---|
ToolBX.MisterTerminal
A high level library to easily and cleanly build smarter console applications. |
|
ToolBX.FileGuy
High-level API for handling files. |
|
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 |
---|---|---|
3.0.0 | 1,145 | 9/26/2024 |
3.0.0-beta1 | 141 | 9/23/2024 |
2.2.0 | 1,066 | 1/13/2024 |
2.2.0-beta2 | 256 | 1/7/2024 |
2.2.0-beta1 | 126 | 12/21/2023 |
2.0.3 | 364 | 6/19/2023 |
2.0.2 | 181 | 6/11/2023 |
2.0.2-beta1 | 141 | 5/9/2023 |
2.0.1 | 474 | 4/26/2023 |
2.0.0 | 517 | 11/10/2022 |
2.0.0-beta1 | 251 | 9/27/2022 |
1.0.8 | 940 | 9/27/2022 |
1.0.7 | 449 | 7/31/2022 |
1.0.6 | 453 | 7/20/2022 |
1.0.5 | 451 | 7/6/2022 |
1.0.4 | 441 | 7/5/2022 |
1.0.3 | 466 | 6/23/2022 |
1.0.2.5-beta | 682 | 5/17/2022 |
1.0.2.4-beta | 512 | 5/15/2022 |
1.0.2.3-beta | 165 | 5/15/2022 |
1.0.2.2-beta | 171 | 5/15/2022 |
1.0.2.1-beta | 159 | 5/6/2022 |
1.0.2 | 474 | 5/2/2022 |
1.0.1 | 462 | 4/29/2022 |
1.0.0 | 319 | 1/10/2022 |