小编ana*_*tol的帖子

MOQ文件在哪里?

我在哪里可以找到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'.

.net c# testing moq mocking

54
推荐指数
3
解决办法
4万
查看次数

SQLite外键不匹配错误

为什么在执行下面的脚本时出现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)

sqlite

14
推荐指数
3
解决办法
2万
查看次数

尝试编辑消息时出现Telegram Bot API错误:"Bad Request:message not found"

我已经尝试编辑大约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)

telegram telegram-bot

12
推荐指数
2
解决办法
6530
查看次数

与默认方法和抽象类的接口,以及动机是什么?

上下文

我最近遇到过这个C#提议的默认界面方法 我已经阅读了规范,更重要的是阅读了动机.可能我错过了一些东西,但动机有点让我感到恶心.

接口和完全抽象类之间唯一的实际区别,未来的类可以实现(所以是[IS A])多个接口,但是只能从一个抽象类继承(所以是[IS A])(并且所有后果)

什么是不明确的,我就是用默认的方法抽象类和接口之间的确切区别现在,除了我们可以把多个(实现)继承到图片的默认方法,这是不可能的抽象类.(我不想打开问题/讨论是好还是坏,这不是这里的话题)

然而,动机谈论完全不同,三点:

  • "...... API作者在未破坏源代码的情况下在未来版本中向接口添加方法......".好的,"API"作者可以在未来的版本中添加方法,如果他实现它们而不破坏任何东西.
  • "......使C#能够与针对Android(Java)和iOS(Swift)的API互操作,......".我认为语言设计决策,尤其是关于抽象和OOP模式(如多重继承)的决策水平要高于与Swift的互操作性.我也认为,这只是互操作问题的0.0%,也可以通过其他方式解决.
  • "......事实证明,添加默认界面实现提供了"特征"语言特征的元素......".这是一个非常浅薄的陈述,特别是它指的是维基百科的"特征".根据定义,traits允许添加没有多重继承的方法(与super具有[IS A]关系).然而界面肯定是关于[IS A] ......不是说这个事实,特征至少是可以说是好的做法

我的问题是真正的差异(或动机)是什么,或者我缺少什么?

c# java

9
推荐指数
1
解决办法
846
查看次数

在Rider IDE中创建类依赖关系图

该功能是否存在?如何使用?在这个问题上,车手官方文档对我毫无用处。

.net c# rider

7
推荐指数
1
解决办法
1715
查看次数

dotnet恢复在本地工作,但在构建Docker容器时失败

如果我使用创建一个新的控制台应用程序dotnet classlib -lang f# -o hello-dockercd进入目录,然后运行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容器内部还原?

docker windows-10 .net-core

6
推荐指数
1
解决办法
2076
查看次数

使用通配符时,对电子邮件地址列中断的全文搜索

我正在尝试在包含电子邮件地址的表上执行全文搜索.

假设我的表包含电子邮件地址:abbuilder@realestate.com

现在,由于断字符,此电子邮件地址中的句点用作分隔符.默认的SQL Server停止列表可以防止对单个字符建立索引(出于显而易见的原因).

通常不是问题,搜索地址工作得很好.不过,我希望能够搜索部分的地址.

我想通过下面的查询搜索"abbuilder @ real".不幸的是,这不起作用,因为地址没有被编入索引"abbuilder @ real ......".

SELECT*FROM [Addressbook] a WHERE CONTAINS([a].*,'"abbuilder @ real*"')

关于如何解决这个问题的任何建议?关于SQL Fiddle的测试示例.

sql-server full-text-search wildcard sql-server-2012

5
推荐指数
1
解决办法
837
查看次数

C# - 将 JSON 反序列化为 ValueTuple

我正在尝试反序列化为[{"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 我对用于此目的的任何模型/类都不感兴趣。我需要确切的值元组。

c# serialization json json.net valuetuple

4
推荐指数
2
解决办法
6766
查看次数

我如何获得电报机器人的 file_path

我有一个电报机器人 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

telegram telegram-bot telegram-webhook

3
推荐指数
1
解决办法
6441
查看次数

用户机密文件在 asp.net core 6 中被忽略

我有两个针对 .net 6 的项目,并且没有任何使用用户机密的明确声明(我记得,在以前的版本中需要使用AddUserSecrets())。虽然,一个项目从 获取正确的配置secrets.json,但另一个项目 - 尝试从 获取它appsettings.json

所以,我想知道,这是什么问题?.net 6 中的行为如何改变?

appsettings asp.net-core .net-6.0

3
推荐指数
1
解决办法
5808
查看次数

Angular 9 HttpErrorResponse“JSON.Parse错误”,而响应正常

为什么这会引发错误?

 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。

在此输入图像描述

在此输入图像描述

我错过了什么?

json typescript angular angular-httpclient

2
推荐指数
1
解决办法
4460
查看次数

在 .net core 中获取注入服务的调用者信息

如果我将这些属性应用于某些服务,然后将其注入到 DI 中,我正在尝试弄清楚将使用哪个CallerMemberNameCallerFilePath值。例如:

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

1
推荐指数
1
解决办法
114
查看次数

具有多种预期类型的​​ XUnit Assert.IsType()

我需要检查三种可能的异常类型中的一种。如果抛出这些异常之一,则测试视为通过。我正在将[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# unit-testing xunit.net .net-core

0
推荐指数
1
解决办法
5202
查看次数