Moq returnsasync ienumerable
Moq returnsasync ienumerable. Setup(_ => _. Jan 2, 2021 · Another part of Moq that is obsolete for the most part is the async setup helper verbs setup. It is up to you to provide mocked values. 6) you can use Task. Thankfully its quite simple these days, and is very useful to know as async calls become more and more commonplace. There is a spelling mistake in IEnumerable in what you show as the controller code, which suggests it's not the code you really use. Jul 21, 2016 · To address this issue, refactor your test to pass the mock object, along with the setup method, to the constructor. GimmeSomeData(); foreach (int i in resultList) Apr 11, 2024 · xUnit. [Fact] public async Task CreateUser_True() {. If you want the Visual Studio debugger to step into Moq's source code, disable Just My Code, enable SourceLink, and configure NuGet's symbol server. – May 7, 2019 · An alternative way is possible in C# 8. You may needs something like. I'm not sure where the problem in your code is but here is a passing test. One is used to create the controller. Basically the following: Expression<Func<MyModel, bool>> func = (param) => param. Since the edit for this answer seems legit, that’s the direction I’ll go first. mockIRepository. The following example uses Moq, but you should be able to do something similar in your implementation. mediator. Any[TSource](IEnumerable`1 source) at Domain. ReturnsAsync(data); will only return data when the values of null and the default value are passed as the two parameters. Thanks to the tip from Callum Linigton I came to the following solution: moq. SomeTable). methods returning a Task<T> or ValueTask<T> ): Starting with Moq 4. Returns(new DealSummary {FileName = "Test"}); You could verify by setting a breakpoint in the Get () method of your To mock an IEnumerable<T> using Moq, you can create a mock object for the interface and set up the GetEnumerator method to return an enumerator that will iterate over the collection of T objects that you want to mock. What are they? These extension methods allow you to set up the result of an async method call without having to manually wrap the desired result in a task: Below is an example of how we can write unit test cases, We will follow the AAA pattern where we will perform Arrange, Act, and Assertion. Create() returns a tuple value: Task<(Model. var managerMock = new Mock<IHttpManager>(); var policyMock = new Mock<IAsyncPolicy<HttpResponseMessage>>(); var sut = new Caller(managerMock. Empty<SchoolyearDTO>())); Now I Dec 11, 2011 · Try the generic version of Returns: . IsAny vs. IsAny<string>())) . Now hoist the sails - it's time to put these skills to the test! Nov 28, 2022 · @OlegI Not necessarily, in Moq, you need to provide all arguments to a setup, even optional ones. Here's a simplified version of the code that's adding the IsAuthorizedAsync method to my Mock Object. StoreAsync(It. ReturnsAsync ("Hello Apr 21, 2023 · Hello Garrick, It turns out that JustMock handles anonymous types in a wrong way. Apr 6, 2017 · That means you need to have the mock return a task to allow the async process to continue the flow. getHtml ()). IsAny<TransferNotificationCommand>(), It. 10. Remove the generic argument. private SampleController GetSampleController() { var command = new Mock<ICommand>(); return new SampleController(command. ReturnsAsync(expected); This makes the test pass, which leads me to the most important thing: 4. We are unable to mock if TResult is an anonymous type, even if I explicitly set it as an object (as suggestion on some Stackoverflow thread). Is there a better / more correct way to write the code below? In this example, we have some sort of repository, and our implementation takes in an object of type Thing that has an Id (we want to pretend that our db set the Id) property: Dec 17, 2020 · There is a way to fake the response of the IConfidentialClientApplication AcquireTokenForClient method by faking the HttpClient SendAsync method. ReturnsAsync(filter => GetTestAirlines. Send(new GetCustomersQuery { Active Aug 8, 2022 · 0. NET. Returns(async () => { throw Exception(); }) instead of . service\BackgroundProcessors\ZipCodeAndLocationProcessor. FindAsync(predicate)). ThrowsAsync<Exception>(). IsAny<AuthenticationDTO>() instead of null. Yes, they are essentially the same, but delegate types have distinct type identity, even if they are functionally the same. var mockModel = new Mock<IQueryable<MyModel>>(); Nov 8, 2016 · Much less code solution. Net (4. Something like this (haven't tested this code in my IDE so be aware of any typo's) var httpClientMock = new Mock<HttpClient>(); Jul 30, 2013 · First of all moq required that you can moq interface methods or virtual methods . The controller derives from ControllerBase and implements the ICrudOperations<Student> interface. Invoke(); Aug 14, 2023 · Initialization: new Mock<T>() => Substitute. Root. Setup the returned task's . ReturnsAsync(Moq. Next, we’ll create an in-memory API controller called StudentsController that implements the CRUD operations for the Student model. [Theory] [AutoData] public async Task WhenSomething_ThenSomething(IEnumerable<string> stringCollection) { //Arange //Mock of the method used in Handle() that returns stringCollection. When I use ReturnsAsync(null) in a C# unit test method in Visual Studio (with Moq), I get the error: "The call is ambiguous between the following methods or properties" and then a list of the ReturnsAsync methods which have different parameters. Returns(() => Task. AddReleaseAsync(Arg. That's what I am objecting against. Below is the example of my problem with Moq Verify() method. AsyncExecute with any int argument. g. Object); } Mocking an interface that inherits from IEnumerable to return canned data is quite straightforward. var mockBookClient= new Mock<IBookService>(); mockBookClient. IsAny<CancellationToken>())) . cs. IsAny<Entity>())) . GetAsync(It. Feb 11, 2019 · 1. IEnumerable`1[SomeOtherClass]' Source=System. IReturns, TResult, System. Verify(x => x. Bar2(0)). See the code example below for clarification: public ClassWithDependecy(ISettingsProvider settingsProvider) {. . No, your statement: "Well your problem is that your method should be returning Task<IList> and You are returning Task<List> you can't do that" is false. AddUser(fakeUserInvite, fakeUserToken)) . return await func. var mock = new Mock<IService>(); // or, if you don't need to customize and verify the mock. It is in fact returning a Task of IList, as stated in the question. I had a unit testing requirement as two systems get authentication tokens based on flag status. Setup(). CreateClient();. FromResult so the mock setup should look like this: this. If you create a mock of HttpClient you can then return this when calling _httpClientFactory. This is how you can unit test your methods that use HttpClient with Moq and xUnit. The syntax is more or less the same as Sep 10, 2013 · As of Oct 10, 2019 Moq. Setup(client => client. The setup should be done like this: connection. Object }; If you want a "pure" IEnumerable<T> that can't be cast back to an array etc, then you could create it using a helper method: var mockEnumerable = CreateEnumerable(mockParent. public interface ITestAsync { Task<IEnumerable<string>> get(); } Aug 6, 2017 · As for the private method, you want to setup the behavior of any dependencies that are used within that method, which in this case is the users repository. Here is my test method, where I'm expecting ReturnsAsync should receive type that will be returned by method defined in Setup. ToDynamicProxyGenAssembly2)] attribute, because assembly Moq is strong-named. IsAny<IAsyncRepository<Task>>())). The setup, for some reason, is not returning the product list. ReturnsExtensions. Feb 18, 2021 · QueryAsync takes a model class, not an IEnumerable of model class. It seems to be a limitation of the API. Returns(GetDbSet(ListOfItems)); However the method I'm trying to write a unit test for uses the ToListAsync method at one point to convert from IQueryable to a List. SetupGet<Task<IEnumerable<SchoolyearDTO>>>(c => c. GetStringAsync(It. Expressions. Task<IEnumerable<T>> GetListAsync<T>(string storedProcedure, object Sep 23, 2014 · When using ReturnsAsync, we could only get it to return a new object. – schwechel May 10, 2017 · Parameter name: source at System. For example: MockedDatabaseContext. Your static method is not mockable. Where method takes a Func<T, bool> not a Predicate<T>. Jul 22, 2017 · Nuget で . Of<ISomeInterface>(si => si. Its frameworks provide a framework for writing and running automated unit tests. Anyways, the accepted answer is the correct one. The last argument in the setup should probably be It. DoSomethingAsync(). GetAll()) . Jun 10, 2020 · With that understanding in place, let's look at your setup: mockRepository. Since you are passing a function as the first parameter it is not null, therefore not matching the setup. ThrowsAsync. Returns((IEnumerable<MatchSetup>)null); Instead. I have a unit test using MOQ that's behaving unexpectedly. Setup (obj => obj. Returns(Task. Strict); Jul 17, 2014 · > System. Use the in-memory db context which should take care of bootstrapping all the sets for you. Mar 23, 2020 · 1. Apr 18, 2023 · For ReturnAsync, I can return a new List: moq Setup ReturnsAsync( new List<Foo>() ); , but can I return an object directly? Feb 18, 2015 · In this case it seems that you can simply return an already completed task using Task. Aug 22, 2019 · I am using MOQ for mocking my interfaced repositories. ReturnsAsync(fakeHttpResponseMessage); requires the actual call to be made with the exact same objects as the ones referenced by fakeUserInvite and fakeUserToken in order for Moq to return fakeHttpResponseMessage. Get(It. GetStudentsAsync(1, null, CancellationToken. So first thing to do is do interface or virtual method. Net Core. Result). AnyInt matcher for the call to match calls to ITaskAsync. Returns((Entity e) => Task. Setup(foo => foo. GetAsync(document . (Arrays implement the IEnumerable<T> interface. Returns Aug 25, 2023 · Tech Tutorial. //Arrange. CompletedTask like this: Apr 25, 2022 · 'IEnumerable' does not contain a definition for 'ElementType' and no accessible extension method 'ElementType' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?) So, please can any one help me out for Moq setup for await with ToListAsync variable. FromResult(new StoreResult {Entity = e})); The key difference is to specify the type for the input parameter of the lambda expression in order to avoid ambiguous calls. QueryAsync<ClerkItem>(It. SetupDapperAsync(c => c. xUnit is a free, open-source, community-focused unit testing tool for . Returns(true); I didn't check the moq code, but I'm pretty sure that when it evaluates the expression in the setup method, it takes into account that the parameter is actually It. Something like Mar 1, 2022 · I am fairly new to unit testing in C# and learning to use Moq. Returns(Task. Object); //Act. ReturnsAsync(async (string key, Func<Task<IEnumerable<int>>> func, DateTimeOffset policy) =>. You can still call the method with only the required arguments. The following code generates CS1929: public static void ExtensionMethod(this D d) class D : B. my extended team next week, and this is one of my examples Sep 27, 2022 · Unit tests of controller logic. Jan 2, 2019 · What am I doing wrong? Two completely different mocks are being used. Net Core version) please reply. content_paste. ReturnsAsync("Some sort of string"); If you specify 'uri' parameter in setup then you have to match it in your test to get desired return value "Some sort of string" from the method. Assuming the following classes: public class DataClass { public int Id { get; set; } } public interface IEnumerableClass : IEnumerable<DataClass> { } The following approach can be taken. Setup(ms => ms. ) var mockEnumerable = new[] { mockParent. answered Jun 22, 2018 at 14:56. Net 4. cs:line 60 --- End of stack In addition, since both DbSetMock and DbContextMock inherit from Mock<DbSet> and Mock<DbContext>, you can use all features of the Moq framework. static void Main() B b = new B(); b. var mock = Mock. In this guide, we will delve into the depths Here are the examples of the csharp api class Moq. TimeSpan, System. Get(mock); Dec 28, 2021 · I am using Moq to mock my service layer in unit test for a post api call, and the _service. When unit testing controller logic, only the contents of a single action are tested, not the behavior of its dependencies or of the framework itself. Object); This compiles. Advertisement. var usersRepository = new Mock<IRepository<User, int>>(); var userResolverService = new Mock<IUserResolverService>(); Aug 14, 2020 · I'm trying to setup a mock return that returns the parameter passed into it. In Example 2 we use an Arg. IsAny<int>() has return type of int and returns 0, so your second setup is equivalent to: mock. ToModelListJVDET(); Apr 2, 2019 · Making sure that the policy has been used. 1, and recently found a different behavior of using public static IReturnsResult<TMock> ReturnsAsync<TMock, TResult>(this IReturns<TMock, Task<TResult>> mock, Func<TResult> valueFunction) where Dec 8, 2016 · I'm new to testing with Moq, so I'm confused a bit regarding ReturnsAsync. Debugging my unit test when I do the setup it still comes out null before it even hits the controller. - by creating a new extension method for proper type 'B': May 28, 2012 · It is probably correct that only an Expression with the exactly same structure (and literal values) will match. In reality, the methods return a new list of products, but I was hoping the setup would be fine like that. <DealerZipCodeAndLocation>d__5. None)) . public static IReturnsResult<TMock> ReturnsAsync<TMock, TResult>(this IReturns<TMock, Task<TResult>> mock, TResult value) where TMock : class; Option B Oct 7, 2021 · Interface: Task<ServiceResponse<string>> GetJSON<T>(FileRequest request, FileItemsSerializer<T> serializer = null, CsvConfiguration May 1, 2020 · How to test HttpClient with Moq in C#. Setup(i => i. public static IAuthenticationInterface GetAuthentication() var mock = new Mock Jun 26, 2023 · With a sturdy understanding of Moq's setup, the use of async Task in NUnit test methods, and the assurance of verifying asynchronous calls, you're equipped to navigate these sometimes stormy waters. Enumerable. ToList(); } Aug 1, 2016 · 14. IsAny<**whatever your get lambda is defined as**>()). Mock. Id == 1. Decided to blog about because this usually helps me fix the knowledge. This statement. Because you're passing the function null (and there are two overloads of Returns ), the compiler does not know which overload you mean unless you cast the argument Jul 8, 2015 · 1. If anyone knows of a solution for . A common case is to mock an async method call to return a custom value in conjunction with a matcher. Expression only works for . var drives = await graphClient. ReturnsAsync(new Notification()) //<-- return Task to allow await to continue. Set up unit tests of controller actions to focus on the Jan 2, 2024 · There are several ways to set up "async" methods (e. IsAny<Release>())). I’ll keep the post for the sake of history. You no longer need to mock out the DbSet on your context but if you want to return data from a service for example, you can simply return the actual set data of the in-memory context. You can specify different results for different inputs: The IEnumerable<T>. Get. Jun 5, 2017 · So basically if the key exists it will return what's in it and if not it'll create a key and fill it with data returned from the passed in Func<>. Sure, you could also always use . Returns(true); Dec 8, 2021 · I have Delegate define in C# SendAnprProviderExemptionNotifications which pass as parameter in the method ProcessCreateRequestAsync that trigger the callBack method May 2, 2011 · For completeness, if you want to use Moq v4 functional specifications and get rid of the . FindBy(x => It. I'm expecting the IsAuthorizedAsync method to always return true, but it's returning false. Nov 7, 2017 · result: mockHttp. Returns<IEnumerable<MatchSetup>>(null); or: . If you change the arrangement in the following way: Mock. Your best alternative would be to create a Adapter/wrapper for HttpClient and mock that in this case. Your test is failing correctly because you try to verify that GetAll () was called even though you haven't actually called it. Jan 17, 2018 · 7. GetAsync(); foreach (var d in drives) yield return d. Description For using Moq, I share with you how to implement this solution using Moq to test Azure Function Isolated . Once interface was made public everything worked/passed . You can mock ReadNextAsync to return a mock of FeedResponse that only has GetEnumerator() defined. The thing is that I have this method that I want to test: public async virtual Task<IEnumerable<T>> GetAsync(Expression<Func<T, bool>> predicate) { return (await Collection. やりかた メソッドの返り値を設定するときに Returns の代わりに ReturnsAsync を使う。. It'll pass if you call the method in your test or in the code your are testing. Aug 18, 2016 · The stub you create with: service2. You know what list goes into CreateAsync, re-use the same list in ReturnAsync. In this case you can simple create a mock for IAsyncPolicy and call the Verify. ReturnsAsync(x) methods, and even . VeracrossMock. Expression. Return a Value for an Async Method Using a Matcher. In this particular case, it creates a mock having a method AddReleaseAsync with a return type Tuple. Jan 16, 2018 · Update: Moq now has the ReturnsAsync() method, rendering the following unnecessary. devlooped / moq Public. IsAny<Expression<Func<Airline, bool>>>())) . I've got a method that converts a List to a DbSet which I use when mocking the data my database context should return. Receipt Receipt, bool IsIdempotent)> therefor I created a tuple result and pass as ReturnsAsync like below: If running asynchronous code, Moq has the ability to delay the response with the second parameter via a TimeSpan. ValidateLambdaArgs(Type delegateType, Expression& body Aug 3, 2017 · Before we jump in let’s go over an important concept in the Moq framework. Unit tests involve testing a part of an app in isolation from its infrastructure and dependencies. Jun 22, 2018 · 22. ReturnsAsync and setup. Returns(//stuff); The FindBy method takes a predicate of type Func<Task,bool>, and here you have provided a specific predicate: x => It. Object, policyMock. Notifications Nov 13, 2009 · You could just create an array. If your method is not static then do the following and you dont need verifiable Apr 21, 2020 · I came across a pretty old StackOverflow question that seemed inline with what I was looking for. However, when I run the To whom it may concern: I am using moq 4. _mockRepository. IsAny<string>(), null, null, null, null)) . IReturns. Linq. var mockInstance = Mock. Feb 17, 2020 · list jvdem does not contain the defination for ToModelListJVDET and the best extension overload method modelhelper. Net 8 public static HttpRequestData CreateMockHttpRequestData(string body, string? schema = null) { var functionContext Oct 26, 2015 · It. It uses IAsyncEnumerable. This may or may not mean the mistake is not related to the test code. Aug 7, 2023 · Debug symbols (Moq. mockService. I suggest that you use the overload of Returns() that lets you use the parameters the mock is called with: Nov 9, 2016 · Make it public, or internal and mark your assembly with [assembly: InternalsVisibleTo(InternalsVisible. Object: var list = new List<int> { 1, 2, 3 }; ISomeInterface implementation =. ZipCodeAndLocationProcessor. FromResult(response)); the Here are the examples of the csharp api class Moq. Moq offers a flexible and expressive mocking framework, while Xunit provides a simple and extensible testing framework. I'm trying to mock a handler with Moq. The GetEnumerator of the List you create will then be passed through to the underlying implementation of the foreach. But they exist because tests are more readable with them, and there's no reason for Task methods IVehicleRecordsRepository mock is set up with a specific (new) guid, which I suppose is not stored and reused in anywhere. EDITED. Setup(c => c. 0 に対応した …. FromMilliseconds(500)); // Delay return for 500 milliseconds. Setup(m => m. a normal number. Func) taken from open source projects. //arrange. Of<IService>(); // when using the above, you can still get the mock instance using Mock. Setup(u => u. Setup(x => x. GetAppSetting("settings"); Aug 18, 2011 · I'm guessing your setup isn't matching the call you make because they're two different anonymous lambdas. Random Apr 26, 2022 · You should use ReturnsAsync method of Moq as shown below. Service. コード [TestFixture] public class TestClass { [Test] public async Task TestMethod () { var hogeMoq = new Mock<Ihoge> (); hogeMoq. Which makes me think that the call doesn't work, because the setup doesn't match it. Id)). class B. MoveNext() in C:\Repos\Vader\AdSvc\domain\domain. This works in nearly all setup and verification expressions: mock. GetFooAsync()) . MockSortProvider. FromResult(false)); Beginning with the next version of . ReturnsAsync(System. [Fact] public async Task Test1() {. Children. If you want to apply the filter then change your setup. Where(filter)); Now if you assert on Dec 19, 2018 · Intro This is just a really quick post on how to write async test methods in C# with XUnit and NSubstitute. Arrange(() => apiMock. SortAsync(categoryId, products, uniqueAnswerIds)); This test fails, but it fails because products is null. ReturnsAsync(new Mock<Response<KeyVaultSecret>>(). Am I right? But seemed ReturnsAsync should have the other signature - it's looking for Func delegate. Jan 14, 2016 · Looking at the Moq implementation of ReturnsAsync : public static IReturnsResult<TMock> ReturnsAsync<TMock, TResult>(this IReturns<TMock, Task<TResult>> mock, TResult value) where TMock : class { TaskCompletionSource<TResult> completionSource = new TaskCompletionSource<TResult>(); completionSource. SetResult(value); return mock. You need to specify that in the type parameters for SetupGet. Drive. How to mock a method returning IEnumerable<T> in unit test method? 1. Result property. I understand that this is due to the ReturnsAsync function being overloaded. GimmeSomeData() == list); List<int> resultList = implementation. NET Standard 1. // expecting "Test" value for tests. This handler takes a parameter of type bool to filter out active customers and non active customers. Collections. (@stakx, #789) Expression<Func<TKey, IEnumerable<TEntity>, TResult>> resultSelector) // SomethingHere. We don't want our unit tests to actually perform HTTP requests during testing so we will have to mock those requests. ArgumentException was unhandled by user code HResult=-2147024809 Message=Expression of type 'System. so please check my code and guide me how can i solve this problem. I was struggling earlier today, due to always forgetting how to properly mock an async method using Moq. Here's an example of how to mock an IEnumerable<T> using Moq: I'm trying to write a unit test for a method which looks like this: public int Save(IEnumerable<int> addedIds, IEnumerable<int> removedIds) { var existingIds = repository. Setup(r => r. For<T>() Moq. Feb 15, 2012 · I have an method like this: public virtual Tuple<int,int> GetQuantities(Entry entry, CartHelper cartHelper) { //something to do return new Tuple<int, int>(minQuantity, maxQuant Apr 2, 2019 · This is mostly for ergonomics and readability. May 13, 2021 · 1. Sep 23, 2021 · This is referring to this Callback() overload in the Moq API, which the compiler thinks you’re trying to use: ICallbackResult Callback ( InvocationAction action ) ; Code language: C# ( cs ) For example, let’s say you’re mocking IRepository and want to set up a callback on the Save(bool) method: I need method CreateAsync to return what it receives (the same List<enteties>) I'm trying to mock a repository's method like that: . ReturnsAsync((List<enteties> x, object y) => x); But it returns empty IEnumareble. The following code solves the CS1929 as described in 1. I have tried constructing the result using Returns or ReturnsAsync. Returns(async () => x) instead of all of the other . NET Sep 18, 2018 · services. pdb) have moved into a separate NuGet symbol package (as per the current official guideline). BackgroundProcessors. This funciton is critical when mocking out complex objects such as the DbSet<T>. The method signature that I'm trying to mock: public async Task<Foo> SendFoo(Foo foo) How I'm trying to mock it: Jan 10, 2018 · I'm creating some unit tests for my DAL that uses mongoDB c# driver. ExtensionMethod(); // CS1929. Usage: Feb 5, 2019 · With new Mock<HttpClient>() I believe you are using MOQ for mocking and if so you can't mock GetAsync() likewise since MOQ is Dynamic Proxy based mocking system which allows mocking only abstract or virtual methods. mockFooService. My mocking attempt of this so far is as follows: . Moq allows us to mock overridable members such as abstract, virtual, or interface methods. Using a separate function to return a list or a IEnumerable<T>. Get(); Nov 1, 2023 · I don't know exactly what you are trying to do, and I also don't know that API, but another option is to also use Moq to create a return value: mockSecretClient . Jun 18, 2015 · 4. Language. Generic. GetSchoolyearsAsync is an async method, so it returns a Task<IEnumerable<SchoolyearDTO>> and not just a IEnumerable<SchoolyearDTO>. This is my code: List<JVDM> jVDMs = new LocationHandler(). It is a project of the . Moq and Xunit are two powerful frameworks that, when combined, provide a robust and efficient solution for unit testing in . Moq and xUnit: Complete Guide | 2023. _mockService. Controller However I only needed the one IEnumerable within my ReturnsAsync delegate method, so I'm goodI was mistaken in that I thought I had to specify a parameter for everyone parameter in the method being mocked up in the "Setup" callnow that I've found you do not need to do that, I'm good to go. Next to Moq, there also is an NSubstitute implementation. . Keep these tools close, and they'll surely help you voyage into your testing future. Object); Apr 6, 2021 · If you will pay attention to the ReturnsAsync signature you will see that it has an overload that accept only on argument: TResult value. GetSchoolyears()). When the mocked method is called without the optional parameter, null is passed for the nullable guid value instead of the one that was set up. 7 (or any non . ToString(); It will alter your signature a bit, which may (or may not) be an option for you. ReturnsAsync(resp); and the method will infer the desired generic arguments based on the member being mocked. Add Interface to Mock Object. Core StackTrace: at System. Usage with the Moq version looks like this: Jun 5, 2022 · In your Setup call you have made the following statement: whatever I receive as a filter expression I should always return with the entire list. Object, mockChild. In the ReturnsAsync method, instead of using a simple int value, we use May 15, 2023 · API Controller. 16, you can simply mock. var expectedTest = settingsProvider. ReturnsAsync(new Foo(), TimeSpan. By voting up you can indicate which examples are most useful and appropriate. Object' cannot be used for return type 'System. ToModelListJVDET (List) requires a receiver of type list. Map<IEnumerable<CustomerDto>>(await _mediatr. ReturnsAsync(document); Mocking an interface that inherits from IEnumerable to return canned data is quite straightforward. GetSecretAsync(certificateName, null, CancellationToken. Below is an example of mocking the Async method of Interface. GetjVDM(). Send(It. The handler is used in my service: public async Task<IEnumerable<CustomerDto>> GetCustomers(bool active) return _mapper. Request(). GetAsync(null, default)). var m = new Mock<IReadAccess<Foo>>(MockBehavior. advertisement. Weirdly enough, I'm giving a Lunch & Learn session for. Currently ReturnsAsync() is an extension method on IReturns<TMock, Task<TResult>> and SetupSequence() is on Mock<TMock>. To properly mock the DbSet<T> we will need to use the As function which adds an interface implementation to our mock. The generic argument being used does not match the arguments of the member being mocked. FromResult(Enumerable. IsAny<IAsyncRepository<Task>>(). qs wo ky vu qa mf zl xj oo th