LightMoq 0.1.0

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

// Install LightMoq as a Cake Tool
#tool nuget:?package=LightMoq&version=0.1.0

LightMoq

Extensions for LightMock.Generator to make it more like Moq.

Why?

I had written a lot of tests for C# Godot projects using Moq, but Moq relies on dynamic code generation at runtime to create the proxies that power mocks. That currently doesn't play nicely with collectible assemblies inside Godot, and I think the future of mocking in C# will probably center around source generators, anyways.

I didn't want to update hundreds of tests, and I like Moq's syntax. So I created a few extensions for LightMock to make it behave more like Moq.

Usage

Just make a mock (exactly how you would with LightMoq.Generator) and call Setup on it to stub methods. You can also use VerifyAll, which will verify all stubbed methods are called at least once, in any order.

namespace LightMoqTests;

using System;
using LightMock.Generator;
using LightMoq;
using Shouldly;
using Xunit;

internal interface IMyObject {
  void DoSomething();
  string SaySomething();
}

public class LightMoqTest {
  [Fact]
  public void TestObjectIsUsable() {
    var myObject = new Mock<IMyObject>();

    var speech = "Hello World!";

    myObject.Setup(obj => obj.DoSomething());
    myObject.Setup(obj => obj.SaySomething()).Returns(speech);

    myObject.Object.DoSomething();
    myObject.Object.SaySomething().ShouldBe(speech);

    // Make sure all stubbed methods were called at least once, in any order.
    myObject.VerifyAll();
  }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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 (1)

Showing the top 1 popular GitHub repositories that depend on LightMoq:

Repository Stars
chickensoft-games/GodotEnv
Manage Godot versions and addons from the command line on Windows, macOS, and Linux.
Version Downloads Last updated
0.1.0 7,889 10/29/2022

LightMoq release.