Tum4ik.StinimGen 2.0.24039.8

dotnet add package Tum4ik.StinimGen --version 2.0.24039.8
NuGet\Install-Package Tum4ik.StinimGen -Version 2.0.24039.8
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="2.0.24039.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tum4ik.StinimGen --version 2.0.24039.8
#r "nuget: Tum4ik.StinimGen, 2.0.24039.8"
#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=2.0.24039.8

// Install Tum4ik.StinimGen as a Cake Tool
#tool nuget:?package=Tum4ik.StinimGen&version=2.0.24039.8

<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), WrapperClassName = "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());
  }
}

API

Property Default Description
sourceType (constructor required) - The type to generate interface members and an implementation wrapper for
WrapperClassName (required) - The implementation wrapper class name to generate
IsPublic false Controls the generated implementation wrapper accessibility: true emits public access modifier, false - internal
IsSealed true Controls the ability to inherit generated implementation wrapper: true emits sealed modifier, false - nothing
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.0.24039.8 213 2/8/2024
2.0.24038.5-rc 56 2/7/2024
2.0.24033.3-rc 57 2/2/2024
2.0.24029.1-rc 61 1/29/2024
1.0.24027.19 76 1/27/2024
1.0.24024.17 80 1/24/2024
1.0.24024.15-beta 67 1/24/2024
1.0.24024.13-beta 65 1/24/2024
1.0.24024.11-beta 65 1/24/2024
1.0.24024.9-beta 64 1/24/2024
1.0.24024.7-beta 66 1/24/2024
1.0.24024.5-beta 59 1/24/2024
1.0.24024.3-beta 64 1/24/2024

- New API to control implementation wrapper generation.
- Keep members original XML documentation.
- Forward Obsolete attribute.
- Forward method parameters attributes from System.Diagnostics.CodeAnalysis.