小编mon*_*Bug的帖子

已超出asp.net Web服务最大json输入长度

我在.net网站上与Nancyfx合作.我有一个必须上传图像的路由,这个图像是从json byte64编码的客户端发送的,以及其他属性.当我尝试将传入的json与我的模型绑定时,我得到了下一个异常:"已超出最大JSON输入长度."

像这样的东西:

Post["/Upload", true] = async(_, ctx) =>
{
     UploadModel model = null;

     model = this.Bind<UploadModel >();

   .
   .
   .
}
Run Code Online (Sandbox Code Playgroud)

我已经读过在我的web.config中更改"maxJsonLength"的值会处理这个问题,但是当我为它设置一个更高的值时,没有任何效果:

<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="50000000"/>
  </webServices>
</scripting>
Run Code Online (Sandbox Code Playgroud)

与maxRequestLength一起:

<httpRuntime targetFramework="4.5" maxRequestLength="1000000"/>
Run Code Online (Sandbox Code Playgroud)

对于一些较小的图片(5KB,50KB),绑定没有问题,但是当我发送大小为144KB及以上的图片时,它会给我一个关注的错误.

有什么想法吗?如果我错过了一些相关信息,请问我

asp.net json nancy

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

如何模拟 IMongoDatabase

我正在使用 Moq 来模拟 ASP.NET Core 项目中的对象。

我想模拟以下 IsConnection() 方法:

public Client(IMongoClient client)
{
    _client = client;
}

public async Task<bool> IsConectionOk()
{            
    var pingCommand = new BsonDocument("ping", 1);
    var mongoDb = _client.GetDatabase("Name");
    var commandResult = await mongoDb.RunCommandAsync<BsonDocument>(pingCommand);
    return commandResult != null;        
}
Run Code Online (Sandbox Code Playgroud)

如您所见,只有一次注入,IMongoClient所以我需要模拟这一注入。IMongoDatabase现在,我还需要模拟,因为_client.GetDatabase返回给我一个IMongoDatabase运行的RunCommandAsync

这是我的单元测试:

[Fact]
public async Task IsConnectionOk_xxx_RunPing1Command()
{
    var dbMock = new Mock<IMongoDatabase>();
    var resultCommand = new BsonDocument("ok", 1);
    dbMock.Setup(stub => stub.RunCommandAsync<BsonDocument>(It.IsAny<BsonDocument>(), It.IsAny<ReadPreference>(), It.IsAny<CancellationToken>())).ReturnsAsync(resultCommand);

    var mongoClientMock = new Mock<IMongoClient>(); …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing moq mongodb

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

标签 统计

asp.net ×1

c# ×1

json ×1

mongodb ×1

moq ×1

nancy ×1

unit-testing ×1