Исходный код вики Сценарии
Редактировал(а) Alexandr Fokin 2023/05/18 23:08
Скрыть последних авторов
author | version | line-number | content |
---|---|---|---|
![]() |
1.2 | 1 | |(% style="width:147px" %)Простой пример|(% style="width:1346px" %){{code language="c#"}}var moq = new Mock<IReadInterface>(); |
2 | moq | ||
3 | .Setup(e => e.MethodAsync(It.IsAny<string>())) | ||
4 | .Returns( | ||
5 | ValueTask.FromResult( | ||
6 | new Result() | ||
7 | ) | ||
8 | );{{/code}} | ||
9 | |(% style="width:147px" %)Mocking generic methods|(% style="width:1346px" %)Mocking generic methods in Moq without specifying T | ||
10 | [[https:~~/~~/stackoverflow.com/questions/20072429/mocking-generic-methods-in-moq-without-specifying-t>>https://stackoverflow.com/questions/20072429/mocking-generic-methods-in-moq-without-specifying-t]] | ||
![]() |
1.4 | 11 | |(% style="width:147px" %)Mocking [[Expression tree ~~| Деревья выражений>>doc:Разработка.NET.C#.Рантайм и типы.Expression tree | Деревья выражений.WebHome]]|(% style="width:1346px" %)((( |
12 | 1) Для типизированного выражения возможен следующий вариант. | ||
13 | |||
14 | {{code language="c#"}} | ||
15 | It.Is<Expression<Func<TEntity, TProp?>>>( | ||
![]() |
1.3 | 16 | e => Microsoft.EntityFrameworkCore.Query.ExpressionEqualityComparer.Instance.Equals(e, propertySelector) |
![]() |
1.4 | 17 | ) |
18 | {{/code}} | ||
![]() |
1.5 | 19 | |
20 | Using Moq, How do you Mock a method that uses local variables | ||
21 | [[https:~~/~~/stackoverflow.com/questions/40165349/using-moq-how-do-you-mock-a-method-that-uses-local-variables>>https://stackoverflow.com/questions/40165349/using-moq-how-do-you-mock-a-method-that-uses-local-variables]] | ||
![]() |
1.4 | 22 | ))) |