You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have the to mock Method with expression or predicate as parameter
I need to mock the this.catalogueRepository.GetAsync(predicate).ConfigureAwait(false); in the below method
public async Task AddProductDetails(int a)
{
Expression<Func<Catalogue, bool>> predicate = a => a.ParentId == viewModel.VendorId &&
a.GlobalKey == EYConstants.GlobalKeys.Product &&
!a.IsDeleted &&
a.GlobalValue.ToLower() == viewModel.ProductName.ToLower().Trim();
var data = await this.catalogueRepository.GetAsync(predicate).ConfigureAwait(false);
return data;
}
I tried to mock the this.catalogueRepository.GetAsync method in the below approach. But it returns null all the time.
Xunit test.
[Fact]
public async Task AddProductDetails_ReturnResult_WhenInputIsValid()
{
#region Arrange
var viewModel = GetAddProductRequest();
var vendorDetail = GetVendorDetail();
var response = GetAddProductResponse();
Expression<Func<Catalogue, bool>> predicate = a => a.ParentId == viewModel.VendorId &&
a.GlobalKey == EYConstants.GlobalKeys.Product &&
!a.IsDeleted &&
a.GlobalValue.ToLower() == viewModel.ProductName.ToLower().Trim();
#endregion
#region Act
//Mocking the method with expression as parameter.
this.MockCatalogueRepository.Setup(x => x.GetAsync(predicate).ReturnsAsync(vendorDetail);
var result = await manager.AddProductDetails(viewModel);
#endregion
#region Assert
Assert.NotNull(result);
Assert.IsType<string>(result);
Assert.Equal(response, result);
#endregion
}
The text was updated successfully, but these errors were encountered:
This issue tracker focuses on Moq development. This issue doesn't look like a bug report, nor like a feature request, but like a simple usage question. Places like Stack Overflow are perhaps better suited for such questions as they will reach a larger audience.
Hi,
I have the to mock Method with expression or predicate as parameter
I need to mock the this.catalogueRepository.GetAsync(predicate).ConfigureAwait(false); in the below method
public async Task AddProductDetails(int a)
{
Expression<Func<Catalogue, bool>> predicate = a => a.ParentId == viewModel.VendorId &&
a.GlobalKey == EYConstants.GlobalKeys.Product &&
!a.IsDeleted &&
a.GlobalValue.ToLower() == viewModel.ProductName.ToLower().Trim();
}
I tried to mock the this.catalogueRepository.GetAsync method in the below approach. But it returns null all the time.
Xunit test.
[Fact]
public async Task AddProductDetails_ReturnResult_WhenInputIsValid()
{
#region Arrange
var viewModel = GetAddProductRequest();
var vendorDetail = GetVendorDetail();
var response = GetAddProductResponse();
Expression<Func<Catalogue, bool>> predicate = a => a.ParentId == viewModel.VendorId &&
a.GlobalKey == EYConstants.GlobalKeys.Product &&
!a.IsDeleted &&
a.GlobalValue.ToLower() == viewModel.ProductName.ToLower().Trim();
#endregion
}
The text was updated successfully, but these errors were encountered: