LightMoq 0.1.0
dotnet add package LightMoq --version 0.1.0
NuGet\Install-Package LightMoq -Version 0.1.0
<PackageReference Include="LightMoq" Version="0.1.0" />
paket add LightMoq --version 0.1.0
#r "nuget: LightMoq, 0.1.0"
// 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 | Versions 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. |
-
net6.0
- LightMock.Generator (>= 1.1.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LightMoq:
Package | Downloads |
---|---|
RBG_GodotTools_AutoTest
RBG_GodotTools_AutoTest description. |
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 | 12,238 | 10/29/2022 |
LightMoq release.