Skip to content

ovaishanif94/Moq.Expression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Moq.Expression

This package helps you to solve expression function in unit test moq framework.

GitHub license Nuget downloads Nuget version GitHub issues Maintenance

Download

The latest stable release is available on NuGet: https://www.nuget.org/packages/MoqExpression/

Example

Install-Package MoqExpression -Version 2.0.0

IUserService

public class User
{
    public string UserId { get; set; }
    public string Name { get; set; }
}

public interface IUserService
{
    User FindByUserId(Expression<Func<User, bool>> expression);
}

UnitTest

using MoqExpression;

User user = new User();
Mock<IUserService> mockUserService = new Mock<IUserService>();
mockUserService.Setup(x => x.FindByUserId(MoqHelper.IsExpression<User>(s => s.UserId.Equals("123")))).Returns(user);

Note: Make sure don't use like this, it will not work.

// don't use like this it will not work 
Expression<Func<User, bool>> expression = MoqHelper.IsExpression<User>(s => s.UserId.Equals("123"));
mockUserService.Setup(x => x.FindByUserId(expression)).Returns(user);

// use equal function instead of ==
mockUserService.Setup(x => x.FindByUserId(MoqHelper.IsExpression<User>(s => s.UserId == "123"))).Returns(user);

Buy me a coffee ☕

ETH: 0xC32Cce6e9A2C88fBe77430B94306C2Db443c06d4

BTC: 1MWVz2MFuHrnTfzxZ8GUSiZXgKuTuRHNLW

BCH: bitcoincash:qr8xav6nzhaj2l9xutvhps36sgxcn8nknge0jz567s

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published