我有以下代码可以正常工作:
TestSuiteModel TestSuites;
TestCasesModel TestCases;
TestCaseModel TestCase;
public async Task GetTestSuites()
{
string url = "https://dev.azure.com/****/****/_apis/test/Plans/12/suites?api-version=5.0";
TestSuites = await TestSuiteService.GetTestSuites(url);
if(TestSuites != null)
{
foreach (var ts in TestSuites.value)
{
TestCases = await TestCasesService.GetTestCases(ts.testCasesUrl);
if (TestCases?.value != null)
{
foreach (var tcs in TestCases.value)
{
TestCase = await TestCaseService.GetTestCase(tcs.testCase.url);
}
}
}
}
}
protected override async Task OnInitializedAsync()
{
await this.GetTestSuites();
await base.OnInitializedAsync();
}
现在,我想创建某种数组、字典或列表来存储每个循环中的数据并以这种方式显示:
foreach(var ts in TestSuites)
show TestCases
foreach(var tcs in TestCases)
show TestCases
foreach(var tc in TestCase)
show TestCase
问题是我已经尝试过,但无法以这种方式存储和显示数据。
以下是三个型号:
namespace ABC.Models.TestSuiteModel
{
public class DefaultConfiguration
{
public string id { get; set; }
public string name { get; set; }
}
public class Parent
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class Plan
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class Project
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class TestSuiteModel
{
public List<Value> value { get; set; }
public int count { get; set; }
}
public class Value
{
public int id { get; set; }
public string name { get; set; }
public string url { get; set; }
public Project project { get; set; }
public Plan plan { get; set; }
public int revision { get; set; }
public int testCaseCount { get; set; }
public string suiteType { get; set; }
public string testCasesUrl { get; set; }
public bool inheritDefaultConfigurations { get; set; }
public List<DefaultConfiguration> defaultConfigurations { get; set; }
public string state { get; set; }
public DateTime lastUpdatedDate { get; set; }
public Parent parent { get; set; }
public int? requirementId { get; set; }
public DateTime? lastPopulatedDate { get; set; }
public string queryString { get; set; }
}
}
using Newtonsoft.Json;
namespace ABC.Models.TestCasesModel
{
public class Avatar
{
public string href { get; set; }
}
public class Configuration
{
public string id { get; set; }
public string name { get; set; }
}
public class Links
{
public Avatar avatar { get; set; }
}
public class PointAssignment
{
public Configuration configuration { get; set; }
public Tester tester { get; set; }
}
public class TestCasesModel
{
public List<Value> value { get; set; }
public int count { get; set; }
}
public class TestCase
{
public string id { get; set; }
public string url { get; set; }
public string webUrl { get; set; }
}
public class Tester
{
public string displayName { get; set; }
public string url { get; set; }
public Links _links { get; set; }
public string id { get; set; }
public string uniqueName { get; set; }
public string imageUrl { get; set; }
public string descriptor { get; set; }
}
public class Value
{
public TestCase testCase { get; set; }
public List<PointAssignment> pointAssignments { get; set; }
}
}
using Newtonsoft.Json;
namespace ABC.Models.TestCaseModel
{
public class Avatar
{
public string href { get; set; }
}
public class Fields
{
[JsonProperty("System.AreaPath")]
public string SystemAreaPath { get; set; }
[JsonProperty("System.TeamProject")]
public string SystemTeamProject { get; set; }
[JsonProperty("System.IterationPath")]
public string SystemIterationPath { get; set; }
[JsonProperty("System.WorkItemType")]
public string SystemWorkItemType { get; set; }
[JsonProperty("System.State")]
public string SystemState { get; set; }
[JsonProperty("System.Reason")]
public string SystemReason { get; set; }
[JsonProperty("System.AssignedTo")]
public SystemAssignedTo SystemAssignedTo { get; set; }
[JsonProperty("System.CreatedDate")]
public DateTime SystemCreatedDate { get; set; }
[JsonProperty("System.CreatedBy")]
public SystemCreatedBy SystemCreatedBy { get; set; }
[JsonProperty("System.ChangedDate")]
public DateTime SystemChangedDate { get; set; }
[JsonProperty("System.ChangedBy")]
public SystemChangedBy SystemChangedBy { get; set; }
[JsonProperty("System.CommentCount")]
public int SystemCommentCount { get; set; }
[JsonProperty("System.Title")]
public string SystemTitle { get; set; }
[JsonProperty("Microsoft.VSTS.Common.StateChangeDate")]
public DateTime MicrosoftVSTSCommonStateChangeDate { get; set; }
[JsonProperty("Microsoft.VSTS.Common.ActivatedDate")]
public DateTime MicrosoftVSTSCommonActivatedDate { get; set; }
[JsonProperty("Microsoft.VSTS.Common.ActivatedBy")]
public MicrosoftVSTSCommonActivatedBy MicrosoftVSTSCommonActivatedBy { get; set; }
[JsonProperty("Microsoft.VSTS.Common.Priority")]
public int MicrosoftVSTSCommonPriority { get; set; }
[JsonProperty("Microsoft.VSTS.TCM.AutomationStatus")]
public string MicrosoftVSTSTCMAutomationStatus { get; set; }
public string href { get; set; }
}
public class Html
{
public string href { get; set; }
}
public class Links
{
public Avatar avatar { get; set; }
public Self self { get; set; }
public WorkItemUpdates workItemUpdates { get; set; }
public WorkItemRevisions workItemRevisions { get; set; }
public WorkItemComments workItemComments { get; set; }
public Html html { get; set; }
public WorkItemType workItemType { get; set; }
public Fields fields { get; set; }
}
public class MicrosoftVSTSCommonActivatedBy
{
public string displayName { get; set; }
public string url { get; set; }
public Links _links { get; set; }
public string id { get; set; }
public string uniqueName { get; set; }
public string imageUrl { get; set; }
public string descriptor { get; set; }
}
public class TestCaseModel
{
public int id { get; set; }
public int rev { get; set; }
public Fields fields { get; set; }
public Links _links { get; set; }
public string url { get; set; }
}
public class Self
{
public string href { get; set; }
}
public class SystemAssignedTo
{
public string displayName { get; set; }
public string url { get; set; }
public Links _links { get; set; }
public string id { get; set; }
public string uniqueName { get; set; }
public string imageUrl { get; set; }
public string descriptor { get; set; }
}
public class SystemChangedBy
{
public string displayName { get; set; }
public string url { get; set; }
public Links _links { get; set; }
public string id { get; set; }
public string uniqueName { get; set; }
public string imageUrl { get; set; }
public string descriptor { get; set; }
}
public class SystemCreatedBy
{
public string displayName { get; set; }
public string url { get; set; }
public Links _links { get; set; }
public string id { get; set; }
public string uniqueName { get; set; }
public string imageUrl { get; set; }
public string descriptor { get; set; }
}
public class WorkItemComments
{
public string href { get; set; }
}
public class WorkItemRevisions
{
public string href { get; set; }
}
public class WorkItemType
{
public string href { get; set; }
}
public class WorkItemUpdates
{
public string href { get; set; }
}
}