Tum4ik.StinimGen 1.0.24024.7-beta

This is a prerelease version of Tum4ik.StinimGen.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Tum4ik.StinimGen --version 1.0.24024.7-beta                
NuGet\Install-Package Tum4ik.StinimGen -Version 1.0.24024.7-beta                
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="Tum4ik.StinimGen" Version="1.0.24024.7-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tum4ik.StinimGen --version 1.0.24024.7-beta                
#r "nuget: Tum4ik.StinimGen, 1.0.24024.7-beta"                
#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 Tum4ik.StinimGen as a Cake Addin
#addin nuget:?package=Tum4ik.StinimGen&version=1.0.24024.7-beta&prerelease

// Install Tum4ik.StinimGen as a Cake Tool
#tool nuget:?package=Tum4ik.StinimGen&version=1.0.24024.7-beta&prerelease                

<h1 align="center"> <img src="logo.png" alt="StinimGen" style="width:128px;" /> <br/> StinimGen </h1> <h1 align="center">

NuGet: Tum4ik.StinimGen NuGet: Downloads </h1>

Interface and implementation generator for static members.

This library is useful in case you want to have possibilities to mock static classes or static members in your tests.

Requirements

  • .NET 6 and higher

Philosophy

  1. Stinim should be associated with the words: static, interface, implementation, Gen - generator.
  2. Static (also const) fields are converted to the properties.
  3. Static events, properties and methods are converted to the events, properties and methods respectively.
  4. All instance (non-static) members are ignored.

How to use

1. Install NuGet package

Use any approach you prefer to install the NuGet package Tum4ik.StinimGen.

2. Declare an interface

Declare your interface for a type you want to make mockable, use IIForAttribute to specify the type to wrap and the name of the wrapper class to be generated.

using Tum4ik.StinimGen.Attributes;

[IIFor(typeof(DateTime), "DateTimeWrapper")]
internal partial interface IDateTime
{
}
3. Register

Register the declared interface and the generated wrapper class in the DI container.

container.Register<IDateTime, DateTimeWrapper>();
4. Inject and use

Inject and use your wrapper in any place you need.

internal class MyService
{
  private readonly IDateTime _dateTime;

  public MyService(IDateTime dateTime)
  {
    _dateTime = dateTime;
  }


  public DateTime GetCurrentDateTime()
  {
    return _dateTime.Now;
  }
}
5. Mock and test

Now you are able to mock the functionality as usual.

using Moq;
using Xunit;

public class MyServiceTests
{
  private readonly Mock<IDateTime> _dateTimeMock = new()
  private readonly MyService _testeeService;

  public MyServiceTests()
  {
    _testeeService = new(_dateTimeMock.Object);
  }


  [Fact]
  internal void GetCurrentDateTimeTest()
  {
    var now = DateTime.Now;
    _dateTimeMock.Setup(dt => dt.Now).Returns(now);
    Assert.Equal(now, _testeeService.GetCurrentDateTime());
  }
}
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. 
.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.
  • .NETStandard 2.0

    • No dependencies.

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
2.2.24230.3 139 8/17/2024
2.1.24171.1 164 6/19/2024
2.0.24150.12 147 5/29/2024
2.0.24150.10 142 5/29/2024
2.0.24039.8 285 2/8/2024
2.0.24038.5-rc 102 2/7/2024
2.0.24033.3-rc 102 2/2/2024
2.0.24029.1-rc 83 1/29/2024
1.0.24027.19 111 1/27/2024
1.0.24024.17 113 1/24/2024
1.0.24024.15-beta 95 1/24/2024
1.0.24024.13-beta 88 1/24/2024
1.0.24024.11-beta 89 1/24/2024
1.0.24024.9-beta 89 1/24/2024
1.0.24024.7-beta 87 1/24/2024
1.0.24024.5-beta 94 1/24/2024
1.0.24024.3-beta 87 1/24/2024

- Interface and implementation generation for static members.
- Generic methods support.