FunctionalDev.MoqHelpers
1.1.0
See the version list below for details.
dotnet add package FunctionalDev.MoqHelpers --version 1.1.0
NuGet\Install-Package FunctionalDev.MoqHelpers -Version 1.1.0
<PackageReference Include="FunctionalDev.MoqHelpers" Version="1.1.0" />
<PackageVersion Include="FunctionalDev.MoqHelpers" Version="1.1.0" />
<PackageReference Include="FunctionalDev.MoqHelpers" />
paket add FunctionalDev.MoqHelpers --version 1.1.0
#r "nuget: FunctionalDev.MoqHelpers, 1.1.0"
#:package FunctionalDev.MoqHelpers@1.1.0
#addin nuget:?package=FunctionalDev.MoqHelpers&version=1.1.0
#tool nuget:?package=FunctionalDev.MoqHelpers&version=1.1.0
FunctionalDev.MoqHelpers
Object Activation
LazyActivator and MockActivator can be used to create instances of an object. LazyActivator should be used for concrete types, and MockActivator should be used for abstract/interface types.
Both provide the ability to create an object without supplying all constructor arguments, absent arguments will be resolved. Protected/private constructors can also be targeted by these classes.
Object Proxy
ObjectProxy can be used to interact (set/get) private members of a given instance, and can be used to invoke protected/private methods.
Dot separated member access is supported to access members of members recursively. E.g. ObjectProxy.For(person)["Name"."FirstName"]
Static classes can be setup with ObjectProxy.ForStatic
to interact with static classes.
Examples
Given the following class:
public class Person
{
private string Name { set; get; }
private Person(ILogger<Person> logger, string name)
{
Name = name;
}
}
Creating an instance of Person
can be achieved as shown below.
var person = LazyActivator.CreateLazy<Person>("Fred");
// or
var person = LazyActivator.CreateLazy<Person>();
And members can be managed as shown below.
// Get.
var name = ObjectProxy.For(person)["Name"];
// Set.
ObjectProxy.Create(person)["Name"] = "Bob";
Setup Extension Methods
Several extension methods have been provided which enable functional Moq creation (returning Mock{T}
to enable chaining) and to setup private/protected members.
Given an example interface:
public interface IPerson
{
string SetName(string name);
int GetAge();
}
The following can be used to set up an IPerson
interface.
var person = new Mock<IPerson>()
.Setup(x => x.SetName, (string name) => "")
.Setup(x => x.GetAge, () => 25);
Please note that this does not provide any filters on the arguments for methods (such as It.Is<T>(Func<T, bool>)
filtering).
Developer Notes
It is not the intention for this library to provide the ability to test private/protected members, rather to assist the creation of objects prior to being tested correctly.
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- Moq (>= 4.16.1)
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 |
---|---|---|
3.3.0 | 220 | 6/17/2025 |
3.2.0 | 819 | 9/17/2024 |
3.1.6 | 124 | 7/24/2024 |
3.1.5 | 188 | 7/8/2024 |
3.1.4 | 242 | 2/20/2024 |
3.1.3 | 189 | 1/22/2024 |
3.1.2 | 129 | 1/22/2024 |
3.1.1 | 142 | 1/21/2024 |
3.1.0 | 129 | 1/21/2024 |
3.0.25 | 269 | 12/6/2023 |
3.0.24 | 159 | 12/4/2023 |
3.0.23 | 225 | 11/15/2023 |
3.0.22 | 242 | 10/10/2023 |
3.0.21 | 199 | 10/6/2023 |
3.0.20 | 251 | 8/7/2023 |
3.0.19 | 182 | 7/31/2023 |
3.0.18 | 174 | 7/31/2023 |
3.0.17 | 220 | 6/27/2023 |
3.0.16 | 255 | 6/2/2023 |
3.0.15 | 191 | 6/2/2023 |
3.0.14 | 219 | 5/15/2023 |
3.0.13 | 310 | 4/18/2023 |
3.0.12 | 224 | 4/18/2023 |
3.0.11 | 227 | 4/17/2023 |
3.0.10 | 242 | 4/14/2023 |
3.0.9 | 234 | 4/14/2023 |
3.0.8 | 233 | 4/14/2023 |
3.0.7 | 226 | 4/14/2023 |
3.0.6 | 367 | 2/17/2023 |
3.0.5 | 277 | 2/16/2023 |
3.0.4 | 308 | 2/9/2023 |
3.0.3 | 313 | 2/7/2023 |
3.0.2 | 2,156 | 1/24/2023 |
3.0.1 | 404 | 1/11/2023 |
3.0.0 | 350 | 1/11/2023 |
2.1.4 | 541 | 11/1/2022 |
2.1.3 | 618 | 7/19/2022 |
2.1.2 | 571 | 5/3/2022 |
2.1.1 | 536 | 5/3/2022 |
2.1.0 | 503 | 4/27/2022 |
2.0.15 | 493 | 4/26/2022 |
2.0.14 | 558 | 3/10/2022 |
2.0.13 | 836 | 1/27/2022 |
2.0.12 | 719 | 1/24/2022 |
2.0.11 | 711 | 1/21/2022 |
2.0.10 | 492 | 9/10/2021 |
2.0.9 | 412 | 9/10/2021 |
2.0.8 | 375 | 9/3/2021 |
2.0.7 | 367 | 9/3/2021 |
2.0.6 | 396 | 9/2/2021 |
2.0.5 | 372 | 8/27/2021 |
2.0.4 | 361 | 8/27/2021 |
2.0.3 | 371 | 8/13/2021 |
2.0.2 | 419 | 7/29/2021 |
2.0.1 | 395 | 7/28/2021 |
2.0.0 | 400 | 7/28/2021 |
1.1.0 | 446 | 7/28/2021 |
1.0.0 | 439 | 7/27/2021 |