假设我想从中获取数据Visual Studio TFS并且响应(作为 json)采用这种格式:
{
"Microsoft.VSTS.Scheduling.StoryPoints": 3.0,
// ......
}
Run Code Online (Sandbox Code Playgroud)
属性名称中有一个点。从其他问题中阅读我发现我可以使用这样的界面在打字稿中读取该 json
export interface IStory { // I don't think this kind of interface do me any help
"Microsoft.VSTS.Scheduling.StoryPoints": number
}
Run Code Online (Sandbox Code Playgroud)
然后我可以使用以下语法使用该属性:
var story = GetStoryFromTFS();
console.log(story["Microsoft.VSTS.Scheduling.StoryPoints"]);
Run Code Online (Sandbox Code Playgroud)
但我不想这样调用属性,因为智能感知将无法帮助我找到我想要使用的属性(因为我使用字符串调用属性)。
在 C# 中,有一个JsonProperty属性使我能够创建这样的模型:
public class Story
{
[JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.StoryPoints")]
public double StoryPoints { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后我可以这样使用该属性:
var story = GetStoryFromTFS();
Console.WriteLine(story.StoryPoints);
Run Code Online (Sandbox Code Playgroud)
这样,智能感知将能够帮助我找到我想要使用的属性。
JsonProperty打字稿中有类似属性的东西吗?或者有没有其他更好的方法可以在打字稿中实现这一点?
当我们https://github.com/{user}/{repo}/graphs/traffic在GitHub中使用此URL时,将显示我们的repo访客的图表.还有一个表格显示推荐网站.
私有仓库的GitLab Page是否存在此功能?或者是否有任何解决方法可以看到访问者数量而无需添加任何第三方访问者计数器Web插件?
所以我有两个类,每个类都包含数据库集成测试。在每个类的构造函数中,我放置了一个重置数据库的方法:
public class FirstClassSpec {
public FirstClassSpec() {
var dataSetup = new DataSetup();
dataSetup.CleanTables();
}
[Fact]
public async Task FirstTest() {
using(var conn = new SqlConnection("connStringHere")){
var result = await conn.ExecuteAsync("someSqlCommand");
Assert.True(result > 0);
}
}
}
public class SecondClassSpec {
public SecondClassSpec() {
var dataSetup = new DataSetup();
dataSetup.CleanTables();
}
[Fact]
public async Task SecondTest() {
using(var conn = new SqlConnection("connStringHere")){
var result = await conn.ExecuteAsync("someSqlCommand");
Assert.True(result > 0);
}
}
}
public class DataSetup {
public void CleanTables() …Run Code Online (Sandbox Code Playgroud) c# integration-testing database-connection xunit visual-studio-2015