小编J L*_*wis的帖子

Typescript 解析私有范围包的类型

我有一个托管在 Azure Artifacts npm feed 中的包,范围为@company,例如添加我们使用的包yarn add @company/package。该包是一个打字稿项目,编译时还包含类型文件。

使用它时,暴露的类型没有被解析,并且编译失败。

构建示例:

  • 建造
    • 索引.js
    • 索引.d.ts

示例 package.json

{
  "name": "@company/package",
  "version": "0.0.5",
  "module": "./build/index.js",
  "types": "./build/index.d.ts",
  "scripts": {
    "build": "rimraf ./build && tsc -p tsconfig.json --noEmit false",
    "prepublish": "npm run build"
  },
  "devDependencies": {
    "typescript": "^3.9.7"
  },
  "files": [
    "build/"
  ]
}
Run Code Online (Sandbox Code Playgroud)

与package.json同一级别,有一个.npmrc文件,一个tsconfig.json文件。

.npmrc

@company:registry=https://company.pkgs.visualstudio.com/_packaging/company-npm/npm/registry/
                        
always-auth=true
Run Code Online (Sandbox Code Playgroud)

tsconfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "target": "ES2015",
    "lib": [
      "es2018",
      "dom"
    ],
    "sourceMap": true,
    "allowJs": false,
    "jsx": "preserve",
    "preserveConstEnums": …
Run Code Online (Sandbox Code Playgroud)

npm typescript tsconfig typescript-typings

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

VS Code 使用本地 OmniSharp 安装 C# 扩展

由于我当前工作设置的限制,我正在尝试本地安装 VS Code C# 扩展。我可以使用市场或 a 很好地安装它.vsix,但在尝试安装所需的 OmniSharp 工具集时遇到问题。

因此,我安装了 OmniSharp 的本地版本,并omnisharp.path在 VS Code 中将设置设置为指向此本地安装。我的问题是,扩展程序仍会尝试下载 OmniSharp 版本,而不是使用此功能。

有没有办法解决这个问题,而无需设置 VS Code 来与我们的网络很好地配合(可能是代理问题)?


扩展管理器输出供参考:

Updating C# dependencies...
Platform: win32, x86_64

Downloading package 'OmniSharp for Windows (.NET 4.6 / x64)'    Retrying from 'https://omnisharpdownload.blob.core.windows.net/ext/omnisharp-win-x64-1.23.2.zip' Downloading package '.NET Core Debugger (Windows / x64)'   Retrying from 'https://vsdebugger.blob.core.windows.net/coreclr-debug-1-12-5/coreclr-debug-win7-x64.zip' 
Installing package 'OmniSharp for Windows (.NET 4.6 / x64)'
Failed at stage: installPackages
Error: end of central directory record signature not found

Finished
Run Code Online (Sandbox Code Playgroud)

omnisharp visual-studio-code

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

具有只读属性和内部构造函数的返回类型的模拟第三方接口

我正在尝试模拟我正在使用的第三方接口(EventStore ClientAPI/IEventStoreConnection),特别是这个方法:

Task<StreamEventsSlice> ReadStreamEventsForwardAsync(string stream, long start, int count, bool resolveLinkTos, UserCredentials userCredentials = null);
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是返回类型StreamEventsSlicereadonly字段和internal构造函数,即

public class StreamEventsSlice
{
    public readonly string Stream;
    //other similar fields

    internal StreamEventsSlice(string stream) //missing other fields
    {
        Stream = stream;
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的测试代码中,我正在使用 模拟事件存储连接Moq,设置ReadStreamEventsForwardAsyncMethod,并尝试像这样设置返回类型:

var connection = new Mock<IEventStoreConnection>();
connection.Setup(s => s.ReadStreamEventsForwardAsync(It.IsAny<string>(), It.IsAny<long>(), It.IsAny<int>(), It.IsAny<bool>(), It.IsAny<UserCredentials>())
    .ReturnsAsync(new StreamsEventSlice { props here });
Run Code Online (Sandbox Code Playgroud)

但是我不能设置属性,或者调用构造函数而不是那个(我实际上只需要设置两个属性)

我尝试制作一个扩展原始类的存根,然后返回它。虽然我可以隐藏只读属性,但我在类上收到错误消息,提示“StreamEventsSlice 没有采用 0 个参数的构造函数”。给它一个构造函数是行不通的,因为我不能调用基本构造函数,因为它是内部构造函数。

当我无法实例化返回类型时,如何模拟接口上的方法?

c# unit-testing moq mocking .net-core

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