我在哪里可以找到MOQ的综合文档?我只是从嘲笑开始,我很难理解它.我已经阅读了http://code.google.com/p/moq/wiki/QuickStart上的所有链接,但似乎无法找到教程或温和的介绍.
我还简要介绍了Rhino Mocks,但发现它非常令人困惑.
是的 - 我读过Stephen Walthers的文章 - 非常有帮助.我也通过了链接.我似乎无法在http://www.bestechvideos.com/2008/06/08/dimecasts-net-introduction-to-mocking-with-moq 观看视频[断链]
具体来说,我试图确定是否从模拟类中引发了一个事件.我无法获得QuickStarts页面上的事件编译示例.在google组中,Daniel解释说CreateEventHandler只能处理类型的事件EventHandler<TEventArgs>,但即使这样我也无法获得编译代码.
更具体地说,我有一个实现的类INotifyChanged.
public class Entity : INotifyChanged
{
public event PropertyChangingEventHandler PropertyChanging;
public int Id
{
get {return _id;}
set {
_id = value;
OnPropertyChanged("Id");
}
}
protected void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
etc .....
}
Run Code Online (Sandbox Code Playgroud)
如何模拟该类以测试PropertyChanged事件是否被触发?我不能重写事件,public event EventHandler<PropertyChangedEventArgs>因为我得到这个错误:
错误1'CoreServices.Notifier'未实现接口成员System.ComponentModel.INotifyPropertyChanged.PropertyChanged'.'CoreServices.Notifier.PropertyChanged'无法实现'System.ComponentModel.INotifyPropertyChanged.PropertyChanged',因为它没有匹配的返回类型'System.ComponentModel.PropertyChangedEventHandler'.
为什么在执行下面的脚本时出现SQLite" 外键不匹配 "错误?
DELETE
FROM rlsconfig
WHERE importer_config_id=2 and
program_mode_config_id=1
Run Code Online (Sandbox Code Playgroud)
这是主表定义:
CREATE TABLE [RLSConfig] (
"rlsconfig_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
"importer_config_id" integer NOT NULL,
"program_mode_config_id" integer NOT NULL,
"l2_channel_config_id" integer NOT NULL,
"rls_fixed_width" integer NOT NULL
,
FOREIGN KEY ([importer_config_id])
REFERENCES [ImporterConfig]([importer_config_id]),
FOREIGN KEY ([program_mode_config_id])
REFERENCES [ImporterConfig]([importer_config_id]),
FOREIGN KEY ([importer_config_id])
REFERENCES [ImporterConfig]([program_mode_config_id]),
FOREIGN KEY ([program_mode_config_id])
REFERENCES [ImporterConfig]([program_mode_config_id])
)
Run Code Online (Sandbox Code Playgroud)
和引用表:
CREATE TABLE [ImporterConfig] (
"importer_config_id" integer NOT NULL,
"program_mode_config_id" integer NOT NULL,
"selected" integer NOT NULL DEFAULT 0,
"combined_config_id" …Run Code Online (Sandbox Code Playgroud) 我已经尝试编辑大约2小时前发出的机器人的消息并得到了这个错误,并认为这条消息如此陈旧,无法进行编辑.然后我尝试编辑另一条消息,稍后发送并且成功了.但在此之后,我尝试编辑最近发送的消息之一,再次得到此错误.现在似乎请求的结果是随机的.
这是什么意思?
这是我的POST查询的一个例子:
https://api.telegram.org/bot{token}/editMessageText?chat_id=12345&message_id=370&text=New text
Run Code Online (Sandbox Code Playgroud)
结果如下:
{
"ok": false,
"error_code": 400,
"description": "Bad Request: message not found"
}
Run Code Online (Sandbox Code Playgroud) 上下文
我最近遇到过这个C#提议的默认界面方法 我已经阅读了规范,更重要的是阅读了动机.可能我错过了一些东西,但动机有点让我感到恶心.
接口和完全抽象类之间唯一的实际区别是,未来的类可以实现(所以是[IS A])多个接口,但是只能从一个抽象类继承(所以是[IS A])(并且所有后果)
什么是不明确的,我就是用默认的方法抽象类和接口之间的确切区别现在,除了我们可以把多个(实现)继承到图片的默认方法,这是不可能的抽象类.(我不想打开问题/讨论是好还是坏,这不是这里的话题)
然而,动机谈论完全不同,三点:
题
我的问题是真正的差异(或动机)是什么,或者我缺少什么?
如果我使用创建一个新的控制台应用程序dotnet classlib -lang f# -o hello-docker,cd进入目录,然后运行dotnet restore,如预期一切正常。
但是,如果我添加Dockerfile以下内容
FROM microsoft/dotnet:2-sdk
WORKDIR /hello
COPY hello-docker.fsproj .
COPY *.fs ./
RUN dotnet restore
RUN dotnet build
ENTRYPOINT [ "dotnet", "run" ]
Run Code Online (Sandbox Code Playgroud)
并运行docker build .,它无法达到nuget.org以下消息:
/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5):错误:无法加载源https://api.nuget.org/v3/index.json的服务索引。[/hello/hello-docker.fsproj]
/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5):错误:发送请求时发生错误。[/hello/hello-docker.fsproj]
/usr/share/dotnet/sdk/2.0.0/NuGet.targets(102,5):错误:无法解析主机名[/hello/hello-docker.fsproj]
命令“ / bin / sh -c dotnet restore”返回非零代码:1
为什么我可以在本地还原,但不能在Docker容器内部还原?
我正在尝试在包含电子邮件地址的表上执行全文搜索.
假设我的表包含电子邮件地址:abbuilder@realestate.com
现在,由于断字符,此电子邮件地址中的句点用作分隔符.默认的SQL Server停止列表可以防止对单个字符建立索引(出于显而易见的原因).
通常不是问题,搜索地址工作得很好.不过,我希望能够搜索部分的地址.
我想通过下面的查询搜索"abbuilder @ real".不幸的是,这不起作用,因为地址没有被编入索引"abbuilder @ real ......".
SELECT*FROM [Addressbook] a WHERE CONTAINS([a].*,'"abbuilder @ real*"')
关于如何解决这个问题的任何建议?关于SQL Fiddle的测试示例.
我正在尝试反序列化为[{"foo": "1", "bar": false}, {"foo": "2", "bar": false}]类型List<(string, bool)>:
JsonConvert.DeserializeObject<List<(string foo, bool bar)>>(json)
Run Code Online (Sandbox Code Playgroud)
但始终会获得默认值列表 - (null, false)。
如何实现正确的反序列化?
PS 我对用于此目的的任何模型/类都不感兴趣。我需要确切的值元组。
我有一个电报机器人 webhook 消息,如
{
"update_id":236420475,
"message":{
"message_id":26577,
"from":{
"id":xxxxxxxx,
"first_name":"DB",
"last_name":"Ks",
"username":"xxxxxxxx"
},
"chat":{
"id":193044649,
"first_name":"DB",
"last_name":"Ks",
"username":"xxxxxxxx",
"type":"private"
},
"date":1493266832,
"voice":{
"duration":2,
"mime_type":"audio/ogg",
"file_id":"AwADBQADBAADQKMIVC978KStO6ZhAg",
"file_size":7532
}
}
}
Run Code Online (Sandbox Code Playgroud)
从电报机器人 API 文档中,指定了用于下载文件的file_path。我怎样才能获得FILE_PATH或得到任何API FILE_PATH使用的file_id?
我有两个针对 .net 6 的项目,并且没有任何使用用户机密的明确声明(我记得,在以前的版本中需要使用AddUserSecrets())。虽然,一个项目从 获取正确的配置secrets.json,但另一个项目 - 尝试从 获取它appsettings.json。
所以,我想知道,这是什么问题?.net 6 中的行为如何改变?
为什么这会引发错误?
deleteUser(userId: string) {
this.dataService.deleteUser(userId).subscribe((response: string) => {
console.log(response);
});
}
Run Code Online (Sandbox Code Playgroud)
“SyntaxError:JSON 中的意外标记 f 在 JSON.parse () 在 XMLHttpRequest.onLoad (https://localhost:5001/vendor.js:34968:51) 在 ZoneDelegate.invokeTask (https://localhost:5001) 的位置 1 /polyfills.js:412:35) 在 Object.onInvokeTask (https://localhost:5001/vendor.js:72879:33) 在 ZoneDelegate.invokeTask (https://localhost:5001/polyfills.js:411:40) )在Zone.runTask(https://localhost:5001/polyfills.js:180:51)在ZoneTask.invokeTask [作为调用](https://localhost:5001/polyfills.js:493:38)在invokeTask( https://localhost:5001/polyfills.js:1634:18) 在 XMLHttpRequest.globalZoneAwareCallback (https://localhost:5001/polyfills.js:1671:25)"
响应是纯字符串值,状态为 200。
我错过了什么?
如果我将这些属性应用于某些服务,然后将其注入到 DI 中,我正在尝试弄清楚将使用哪个CallerMemberName或CallerFilePath值。例如:
public class MyService: IMyService
{
public MyService([CallerMemberName] string name = null)
{
var name = name; // name is always null here
}
}
...
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IMyService, MyService>();
}
}
Run Code Online (Sandbox Code Playgroud)
所以,我想,这是name变量的预期值还是我做错了什么?CallerMemberName在这种情况下我该如何工作?有可能吗?
c# dependency-injection callermembername asp.net-core asp.net5
我需要检查三种可能的异常类型中的一种。如果抛出这些异常之一,则测试视为通过。我正在将[Theory]和用于[MemberData]多种场景。
[Theory]
[MemberData(nameof(GetInvalidMimeMessages))]
public async Task ProcessAsync_TestFail(MimeMessage message)
{
var stub = Mock.Of<IOptions<ScrapyardFilesOptions>>(s => s.Value.ConnectionString == "UseDevelopmentStorage=true" && s.Value.Container == "exchange");
var loggerMock = new Mock<ILogger<ScrapyardFilesHandler>>(MockBehavior.Loose);
var scrapyard = new ScrapyardFilesHandler(loggerMock.Object, stub);
var ex = await Assert.ThrowsAnyAsync<Exception>(() => scrapyard.ProcessAsync(message));
// imagine solution somehow like that
Assert.IsType(
{
typeof(NullReferenceException) ||
typeof(KeyNotFoundException) ||
typeof(InvalidOperationException) ||
},
ex);
}
private static IEnumerable<object[]> GetInvalidMimeMessages()
{
yield return new object[] { null };
yield return new object[] { new MimeMessage() }; …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×2
.net-core ×2
asp.net-core ×2
json ×2
telegram ×2
telegram-bot ×2
.net-6.0 ×1
angular ×1
appsettings ×1
asp.net5 ×1
docker ×1
java ×1
json.net ×1
mocking ×1
moq ×1
rider ×1
sql-server ×1
sqlite ×1
testing ×1
typescript ×1
unit-testing ×1
valuetuple ×1
wildcard ×1
windows-10 ×1
xunit.net ×1