Stubber 0.0.1

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

// Install Stubber as a Cake Tool
#tool nuget:?package=Stubber&version=0.0.1

Stubber

Helper library for writing WebAPI tests while mocking DB calls etc. Captures required data in run time and saves it as json file to desired location. Generates code for setting up mocked services with Moq with the data captured in run time.

Motivation

Writing tests for complex methods takes a lot of time especially the project has no prior tests. Stubber automatically generates some code to jump start testing.

Installation

Stubber is activated only in DEBUG mode. Using Stubber should not affect performance in production environment.

appsettings.json

{
  "Stubber": {
    "CodeFilePathPrefix": "C:\\ProjectPath\\Tests\\Documents", 
    "StubFilePathPrefix": "C:\\ProjectPath\\Tests\\DataSources"
  }
}

Startup.cs

using StubberProject.Extensions;

public class Startup
{
    public IConfiguration Configuration { get; }
    
    public Startup(IConfiguration configuration) 
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services) 
    {
        ...
        service.UseStubber(Configuration);
        ...
    }
    
    public void Configure(IApplicationBuilder app) 
    {
        ...
        app.UseStubber();
        ...
    }
}

Usage

Detailed example can be found in examples folder. (WIP)

Classes needs to be recorded should be marked with an attribute.

using StubberProject.Attributes;

[Stubber]
public class UserService : IUserService 
{
    ...
}

Target method under test should be marked with an attribute. Recording session will start when this method is triggered and end after it is done. Every method's and propertyGetter's data is saved to the json file (do not forget to put JsonIgnore to sensitive fields). Every method and propertyGetter used in recorded session will be generated as Moq setup code under CodeFilePathPrefix folder.

using StubberProject.Attributes;

public class BlogService : IBlogService
{
    public BlogService (IUserService userService)
    {
        ...
    }

    [StubberTarget]
    public int GetUsersBlogCount(Guid userId)
    {
        var user = _userService.GetUser(userId);
        ...
    }
}

License

MIT License

Copyright (c) 2020 Metin ÖZTÜRK

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.1 438 11/1/2020